Skip to content

Commit cac29b3

Browse files
committed
fix(linter): fix default values for eslint/max-lines-per-function
1 parent 9956464 commit cac29b3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,27 @@ fn max_lines_per_function_diagnostic(
2828
.with_label(span)
2929
}
3030

31-
#[derive(Debug, Default, Clone)]
31+
#[derive(Debug, Clone)]
3232
pub struct MaxLinesPerFunctionConfig {
3333
max: usize,
3434
skip_comments: bool,
3535
skip_blank_lines: bool,
3636
iifes: bool,
3737
}
3838

39+
const DEFAULT_MAX_LINES_PER_FUNCTION: usize = 50;
40+
41+
impl Default for MaxLinesPerFunctionConfig {
42+
fn default() -> Self {
43+
Self {
44+
max: DEFAULT_MAX_LINES_PER_FUNCTION,
45+
skip_comments: false,
46+
skip_blank_lines: false,
47+
iifes: false,
48+
}
49+
}
50+
}
51+
3952
#[derive(Debug, Default, Clone)]
4053
pub struct MaxLinesPerFunction(Box<MaxLinesPerFunctionConfig>);
4154

@@ -157,7 +170,9 @@ impl Rule for MaxLinesPerFunction {
157170
.and_then(|config| config.get("max"))
158171
.and_then(Value::as_number)
159172
.and_then(serde_json::Number::as_u64)
160-
.map_or(50, |v| usize::try_from(v).unwrap_or(50));
173+
.map_or(DEFAULT_MAX_LINES_PER_FUNCTION, |v| {
174+
usize::try_from(v).unwrap_or(DEFAULT_MAX_LINES_PER_FUNCTION)
175+
});
161176
let skip_comments = config
162177
.and_then(|config| config.get("skipComments"))
163178
.and_then(Value::as_bool)
@@ -222,6 +237,12 @@ fn is_iife<'a>(node: &AstNode<'a>, semantic: &Semantic<'a>) -> bool {
222237
fn test() {
223238
use crate::tester::Tester;
224239

240+
let defaults = MaxLinesPerFunction::default();
241+
assert_eq!(defaults.max, 50);
242+
assert!(!defaults.skip_comments);
243+
assert!(!defaults.skip_blank_lines);
244+
assert!(!defaults.iifes);
245+
225246
let pass = vec![
226247
(
227248
"var x = 5;

0 commit comments

Comments
 (0)