@@ -8,10 +8,31 @@ use crate::analysis::LocalDMLError;
88use crate :: analysis:: parsing:: tree:: { ZeroRange , Content , TreeElement } ;
99use serde:: { Deserialize , Serialize } ;
1010use super :: Rule ;
11+ use crate :: lint:: LintCfg ;
1112
1213pub const MAX_LENGTH_DEFAULT : u32 = 80 ;
1314pub const INDENTATION_LEVEL_DEFAULT : u32 = 4 ;
1415
16+ fn default_indentation_spaces ( ) -> u32 {
17+ INDENTATION_LEVEL_DEFAULT
18+ }
19+
20+ pub fn setup_indentation_size ( cfg : & mut LintCfg ) {
21+ let mut indentation_spaces = INDENTATION_LEVEL_DEFAULT ;
22+
23+ if let Some ( in1) = & cfg. in1 {
24+ indentation_spaces = in1. indentation_spaces ;
25+ }
26+ if let Some ( in3) = & mut cfg. in3 {
27+ in3. indentation_spaces = indentation_spaces;
28+ }
29+ if let Some ( in6) = & mut cfg. in6 {
30+ in6. indentation_spaces = indentation_spaces;
31+ }
32+ if let Some ( in9) = & mut cfg. in9 {
33+ in9. indentation_spaces = indentation_spaces;
34+ }
35+ }
1536#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
1637pub struct LongLineOptions {
1738 pub max_length : u32 ,
@@ -29,7 +50,7 @@ impl LongLinesRule {
2950 enabled : true ,
3051 max_length : long_lines. max_length ,
3152 } ,
32- None => LongLinesRule {
53+ None => LongLinesRule {
3354 enabled : false ,
3455 max_length : MAX_LENGTH_DEFAULT ,
3556 } ,
@@ -59,6 +80,11 @@ impl Rule for LongLinesRule {
5980 }
6081}
6182
83+ #[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
84+ pub struct IN1Options {
85+ pub indentation_spaces : u32 ,
86+ }
87+
6288#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
6389pub struct IN2Options { }
6490
@@ -98,8 +124,10 @@ pub struct IN3Rule {
98124
99125#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
100126pub struct IN3Options {
127+ #[ serde( default = "default_indentation_spaces" ) ]
101128 pub indentation_spaces : u32 ,
102129}
130+
103131pub struct IN3Args < ' a > {
104132 members_ranges : Vec < ZeroRange > ,
105133 lbrace : ZeroRange ,
@@ -196,25 +224,26 @@ impl Rule for IN3Rule {
196224
197225// IN6: Continuation Line
198226#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
199- pub struct ContinuationLineOptions {
227+ pub struct IN6Options {
228+ #[ serde( default = "default_indentation_spaces" ) ]
200229 pub indentation_spaces : u32 ,
201230}
202231
203- pub struct ContinuationLineRule {
232+ pub struct IN6Rule {
204233 pub enabled : bool ,
205234 pub indentation_spaces : u32 ,
206235}
207236
208- impl ContinuationLineRule {
209- pub fn from_options ( options : & Option < ContinuationLineOptions > ) -> ContinuationLineRule {
237+ impl IN6Rule {
238+ pub fn from_options ( options : & Option < IN6Options > ) -> IN6Rule {
210239 match options {
211- Some ( continuation_line ) => ContinuationLineRule {
240+ Some ( in6 ) => IN6Rule {
212241 enabled : true ,
213- indentation_spaces : continuation_line . indentation_spaces ,
242+ indentation_spaces : in6 . indentation_spaces ,
214243 } ,
215- None => ContinuationLineRule {
244+ None => IN6Rule {
216245 enabled : false ,
217- indentation_spaces : INDENTATION_LEVEL_DEFAULT ,
246+ indentation_spaces : 0 ,
218247 } ,
219248 }
220249 }
@@ -235,7 +264,7 @@ impl ContinuationLineRule {
235264 & logical_operators[ ..] ,
236265 & bitwise_operators[ ..] ,
237266 ] ;
238-
267+
239268 for ( i, line) in lines. iter ( ) . enumerate ( ) {
240269 if let Some ( last_char) = line. trim ( ) . chars ( ) . last ( ) {
241270 if operators. iter ( ) . any ( |ops| ops. contains ( & last_char. to_string ( ) . as_str ( ) ) ) {
@@ -244,7 +273,7 @@ impl ContinuationLineRule {
244273 let expected_indent = line. chars ( ) . take_while ( |c| c. is_whitespace ( ) ) . count ( ) + self . indentation_spaces as usize ;
245274 let actual_indent = next_line. chars ( ) . take_while ( |c| c. is_whitespace ( ) ) . count ( ) ;
246275 if actual_indent != expected_indent {
247- let msg = ContinuationLineRule :: description ( ) . to_owned ( ) ;
276+ let msg = IN6Rule :: description ( ) . to_owned ( ) ;
248277 let dmlerror = LocalDMLError {
249278 range : Range :: new (
250279 Row :: new_zero_indexed ( ( i + 1 ) as u32 ) ,
@@ -263,13 +292,13 @@ impl ContinuationLineRule {
263292 }
264293}
265294
266- impl Rule for ContinuationLineRule {
295+ impl Rule for IN6Rule {
267296 fn name ( ) -> & ' static str {
268- "CONTINUATION_LINE "
297+ "IN6_CONTINUATION_LINE "
269298 }
270299
271300 fn description ( ) -> & ' static str {
272- "Continuation line not indented correctly"
301+ "Continuation line not indented correctly. "
273302 }
274303}
275304
@@ -280,8 +309,10 @@ pub struct IN9Rule {
280309
281310#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
282311pub struct IN9Options {
312+ #[ serde( default = "default_indentation_spaces" ) ]
283313 pub indentation_spaces : u32 ,
284314}
315+
285316pub struct IN9Args < ' a > {
286317 case_range : ZeroRange ,
287318 expected_depth : & ' a mut u32 ,
0 commit comments