@@ -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 ) ]
3232pub 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 ) ]
4053pub 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 {
222237fn 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