Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions crates/oxc_linter/src/config/settings/jsdoc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;

use crate::utils::default_true;
use rustc_hash::FxHashMap;
use schemars::JsonSchema;
use serde::Deserialize;
Expand Down Expand Up @@ -178,12 +179,6 @@ impl JSDocPluginSettings {
}
}

// Deserialize helper types

fn default_true() -> bool {
true
}

#[derive(Clone, Debug, Deserialize, JsonSchema)]
#[serde(untagged)]
enum TagNamePreference {
Expand Down
5 changes: 1 addition & 4 deletions crates/oxc_linter/src/rules/jsdoc/require_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 2 additions & 5 deletions crates/oxc_linter/src/rules/jsdoc/require_returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down Expand Up @@ -84,9 +84,6 @@ impl Default for RequireReturnsConfig {
}
}
}
fn default_true() -> bool {
true
}
fn default_exempted_by() -> Vec<String> {
vec!["inheritdoc".to_string()]
}
Expand Down
25 changes: 25 additions & 0 deletions crates/oxc_linter/src/utils/config.rs
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 3 additions & 2 deletions crates/oxc_linter/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod config;
mod jest;
mod jsdoc;
mod nextjs;
Expand All @@ -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.
Expand Down