mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(linter): move default_true to utils (#4947)
This commit is contained in:
parent
873d502993
commit
4cb8c3771f
5 changed files with 32 additions and 17 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use crate::utils::default_true;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
@ -178,12 +179,6 @@ impl JSDocPluginSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deserialize helper types
|
|
||||||
|
|
||||||
fn default_true() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, Deserialize, JsonSchema)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum TagNamePreference {
|
enum TagNamePreference {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
context::LintContext,
|
context::LintContext,
|
||||||
rule::Rule,
|
rule::Rule,
|
||||||
utils::{
|
utils::{
|
||||||
collect_params, get_function_nearest_jsdoc_node, should_ignore_as_avoid,
|
collect_params, default_true, get_function_nearest_jsdoc_node, should_ignore_as_avoid,
|
||||||
should_ignore_as_internal, should_ignore_as_private, ParamKind,
|
should_ignore_as_internal, should_ignore_as_private, ParamKind,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -81,9 +81,6 @@ impl Default for RequireParamConfig {
|
||||||
fn default_exempted_by() -> Vec<String> {
|
fn default_exempted_by() -> Vec<String> {
|
||||||
vec!["inheritdoc".to_string()]
|
vec!["inheritdoc".to_string()]
|
||||||
}
|
}
|
||||||
fn default_true() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
fn default_check_types_pattern() -> String {
|
fn default_check_types_pattern() -> String {
|
||||||
"^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$".to_string() // spellchecker:disable-line
|
"^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$".to_string() // spellchecker:disable-line
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ use crate::{
|
||||||
context::LintContext,
|
context::LintContext,
|
||||||
rule::Rule,
|
rule::Rule,
|
||||||
utils::{
|
utils::{
|
||||||
get_function_nearest_jsdoc_node, should_ignore_as_avoid, should_ignore_as_internal,
|
default_true, get_function_nearest_jsdoc_node, should_ignore_as_avoid,
|
||||||
should_ignore_as_private,
|
should_ignore_as_internal, should_ignore_as_private,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -84,9 +84,6 @@ impl Default for RequireReturnsConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn default_true() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
fn default_exempted_by() -> Vec<String> {
|
fn default_exempted_by() -> Vec<String> {
|
||||||
vec!["inheritdoc".to_string()]
|
vec!["inheritdoc".to_string()]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
25
crates/oxc_linter/src/utils/config.rs
Normal file
25
crates/oxc_linter/src/utils/config.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/// Always returns `true`.
|
||||||
|
///
|
||||||
|
/// Useful for default values in rule configs that use serde.
|
||||||
|
/// See [serde documentation](https://serde.rs/field-attrs.html#default--path)
|
||||||
|
/// for more information
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
/// ```ignore
|
||||||
|
/// use serde::Deserialize;
|
||||||
|
/// use oxc_linter::utils::default_true;
|
||||||
|
///
|
||||||
|
/// #[derive(Debug, Clone, Deserialize)]
|
||||||
|
/// pub struct RuleConfig {
|
||||||
|
/// // default to true
|
||||||
|
/// #[serde(default = "default_true")]
|
||||||
|
/// pub foo: bool,
|
||||||
|
/// // default to false
|
||||||
|
/// #[serde(default)]
|
||||||
|
/// pub bar: bool,
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
#[inline]
|
||||||
|
pub const fn default_true() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
mod config;
|
||||||
mod jest;
|
mod jest;
|
||||||
mod jsdoc;
|
mod jsdoc;
|
||||||
mod nextjs;
|
mod nextjs;
|
||||||
|
|
@ -9,8 +10,8 @@ mod unicorn;
|
||||||
mod vitest;
|
mod vitest;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
jest::*, jsdoc::*, nextjs::*, promise::*, react::*, react_perf::*, tree_shaking::*, unicorn::*,
|
config::*, jest::*, jsdoc::*, nextjs::*, promise::*, react::*, react_perf::*, tree_shaking::*,
|
||||||
vitest::*,
|
unicorn::*, vitest::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Check if the Jest rule is adapted to Vitest.
|
/// Check if the Jest rule is adapted to Vitest.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue