refactor(linter): move default_true to utils (#4947)

This commit is contained in:
Don Isaac 2024-08-17 14:09:58 -04:00 committed by GitHub
parent 873d502993
commit 4cb8c3771f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 32 additions and 17 deletions

View file

@ -1,5 +1,6 @@
use std::borrow::Cow;
use crate::utils::default_true;
use rustc_hash::FxHashMap;
use schemars::JsonSchema;
use serde::Deserialize;
@ -178,12 +179,6 @@ impl JSDocPluginSettings {
}
}
// Deserialize helper types
fn default_true() -> bool {
true
}
#[derive(Clone, Debug, Deserialize, JsonSchema)]
#[serde(untagged)]
enum TagNamePreference {

View file

@ -13,7 +13,7 @@ use crate::{
context::LintContext,
rule::Rule,
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,
},
};
@ -81,9 +81,6 @@ impl Default for RequireParamConfig {
fn default_exempted_by() -> Vec<String> {
vec!["inheritdoc".to_string()]
}
fn default_true() -> bool {
true
}
fn default_check_types_pattern() -> String {
"^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$".to_string() // spellchecker:disable-line
}

View file

@ -14,8 +14,8 @@ use crate::{
context::LintContext,
rule::Rule,
utils::{
get_function_nearest_jsdoc_node, should_ignore_as_avoid, should_ignore_as_internal,
should_ignore_as_private,
default_true, get_function_nearest_jsdoc_node, should_ignore_as_avoid,
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> {
vec!["inheritdoc".to_string()]
}

View 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
}

View file

@ -1,3 +1,4 @@
mod config;
mod jest;
mod jsdoc;
mod nextjs;
@ -9,8 +10,8 @@ mod unicorn;
mod vitest;
pub use self::{
jest::*, jsdoc::*, nextjs::*, promise::*, react::*, react_perf::*, tree_shaking::*, unicorn::*,
vitest::*,
config::*, jest::*, jsdoc::*, nextjs::*, promise::*, react::*, react_perf::*, tree_shaking::*,
unicorn::*, vitest::*,
};
/// Check if the Jest rule is adapted to Vitest.