Skip to content

Commit 2e3db4e

Browse files
committed
fix(linter): fix default values for eslint/max-depth (#11908)
related #11906
1 parent 1e7076f commit 2e3db4e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

crates/oxc_linter/src/rules/eslint/max_depth.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ fn max_depth_diagnostic(num: usize, max: usize, span: Span) -> OxcDiagnostic {
1515
.with_label(span)
1616
}
1717

18-
#[derive(Debug, Default, Clone, JsonSchema)]
18+
const DEFAULT_MAX_DEPTH: usize = 4;
19+
20+
#[derive(Debug, Clone, JsonSchema)]
1921
pub struct MaxDepth {
2022
max: usize,
2123
}
2224

25+
impl Default for MaxDepth {
26+
fn default() -> Self {
27+
Self { max: DEFAULT_MAX_DEPTH }
28+
}
29+
}
30+
2331
declare_oxc_lint!(
2432
/// ### What it does
2533
///
@@ -132,7 +140,7 @@ impl Rule for MaxDepth {
132140
.and_then(|config| config.get("max"))
133141
.and_then(Value::as_number)
134142
.and_then(serde_json::Number::as_u64)
135-
.map_or(4, |v| usize::try_from(v).unwrap_or(4))
143+
.map_or(DEFAULT_MAX_DEPTH, |v| usize::try_from(v).unwrap_or(DEFAULT_MAX_DEPTH))
136144
};
137145
Self { max }
138146
}
@@ -157,6 +165,9 @@ fn should_stop(node: &AstNode<'_>) -> bool {
157165
fn test() {
158166
use crate::tester::Tester;
159167

168+
let defaults = MaxDepth::default();
169+
assert_eq!(defaults.max, 4);
170+
160171
let pass = vec![
161172
(
162173
"function foo() { if (true) { if (false) { if (true) { } } } }",

0 commit comments

Comments
 (0)