@@ -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,15 +80,22 @@ 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+
6288pub struct IN3Rule {
6389 pub enabled : bool ,
6490 indentation_spaces : u32
6591}
6692
6793#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
6894pub struct IN3Options {
95+ #[ serde( default = "default_indentation_spaces" ) ]
6996 pub indentation_spaces : u32 ,
7097}
98+
7199pub struct IN3Args < ' a > {
72100 members_ranges : Vec < ZeroRange > ,
73101 lbrace : ZeroRange ,
@@ -164,25 +192,26 @@ impl Rule for IN3Rule {
164192
165193// IN6: Continuation Line
166194#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
167- pub struct ContinuationLineOptions {
195+ pub struct IN6Options {
196+ #[ serde( default = "default_indentation_spaces" ) ]
168197 pub indentation_spaces : u32 ,
169198}
170199
171- pub struct ContinuationLineRule {
200+ pub struct IN6Rule {
172201 pub enabled : bool ,
173202 pub indentation_spaces : u32 ,
174203}
175204
176- impl ContinuationLineRule {
177- pub fn from_options ( options : & Option < ContinuationLineOptions > ) -> ContinuationLineRule {
205+ impl IN6Rule {
206+ pub fn from_options ( options : & Option < IN6Options > ) -> IN6Rule {
178207 match options {
179- Some ( continuation_line ) => ContinuationLineRule {
208+ Some ( in6 ) => IN6Rule {
180209 enabled : true ,
181- indentation_spaces : continuation_line . indentation_spaces ,
210+ indentation_spaces : in6 . indentation_spaces ,
182211 } ,
183- None => ContinuationLineRule {
212+ None => IN6Rule {
184213 enabled : false ,
185- indentation_spaces : INDENTATION_LEVEL_DEFAULT ,
214+ indentation_spaces : 0 ,
186215 } ,
187216 }
188217 }
@@ -203,7 +232,7 @@ impl ContinuationLineRule {
203232 & logical_operators[ ..] ,
204233 & bitwise_operators[ ..] ,
205234 ] ;
206-
235+
207236 for ( i, line) in lines. iter ( ) . enumerate ( ) {
208237 if let Some ( last_char) = line. trim ( ) . chars ( ) . last ( ) {
209238 if operators. iter ( ) . any ( |ops| ops. contains ( & last_char. to_string ( ) . as_str ( ) ) ) {
@@ -212,7 +241,7 @@ impl ContinuationLineRule {
212241 let expected_indent = line. chars ( ) . take_while ( |c| c. is_whitespace ( ) ) . count ( ) + self . indentation_spaces as usize ;
213242 let actual_indent = next_line. chars ( ) . take_while ( |c| c. is_whitespace ( ) ) . count ( ) ;
214243 if actual_indent != expected_indent {
215- let msg = ContinuationLineRule :: description ( ) . to_owned ( ) ;
244+ let msg = IN6Rule :: description ( ) . to_owned ( ) ;
216245 let dmlerror = LocalDMLError {
217246 range : Range :: new (
218247 Row :: new_zero_indexed ( ( i + 1 ) as u32 ) ,
@@ -231,13 +260,13 @@ impl ContinuationLineRule {
231260 }
232261}
233262
234- impl Rule for ContinuationLineRule {
263+ impl Rule for IN6Rule {
235264 fn name ( ) -> & ' static str {
236- "CONTINUATION_LINE "
265+ "IN6_CONTINUATION_LINE "
237266 }
238267
239268 fn description ( ) -> & ' static str {
240- "Continuation line not indented correctly"
269+ "Continuation line not indented correctly. "
241270 }
242271}
243272
@@ -248,8 +277,10 @@ pub struct IN9Rule {
248277
249278#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
250279pub struct IN9Options {
280+ #[ serde( default = "default_indentation_spaces" ) ]
251281 pub indentation_spaces : u32 ,
252282}
283+
253284pub struct IN9Args < ' a > {
254285 case_range : ZeroRange ,
255286 expected_depth : & ' a mut u32 ,
0 commit comments