@@ -27,11 +27,13 @@ pub struct SpReservedOptions {}
2727pub struct SpReservedRule {
2828 pub enabled : bool ,
2929}
30+
3031pub struct SpReservedArgs {
3132 before_range : Option < ZeroRange > ,
3233 token_range : ZeroRange ,
3334 after_range : Option < ZeroRange > ,
3435}
36+
3537impl SpReservedArgs {
3638 pub fn from_after_content ( node : & AfterContent ) -> Vec < SpReservedArgs > {
3739 let mut args_list = vec ! [ ] ;
@@ -130,12 +132,14 @@ pub struct SpBraceOptions {}
130132pub struct SpBracesRule {
131133 pub enabled : bool ,
132134}
135+
133136pub struct SpBracesArgs {
134137 body_start : ZeroRange ,
135138 body_end : ZeroRange ,
136139 lbrace : ZeroRange ,
137140 rbrace : ZeroRange ,
138141}
142+
139143impl SpBracesArgs {
140144 pub fn from_compound ( node : & CompoundContent ) -> Option < SpBracesArgs > {
141145 if node. statements . is_empty ( ) {
@@ -234,14 +238,17 @@ impl Rule for SpBracesRule {
234238
235239#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
236240pub struct SpBinopOptions { }
241+
237242pub struct SpBinopRule {
238243 pub enabled : bool ,
239244}
245+
240246pub struct SpBinopArgs {
241247 left : ZeroRange ,
242248 operator : ZeroRange ,
243249 right : ZeroRange ,
244250}
251+
245252impl SpBinopArgs {
246253 pub fn from_binary_expression_content ( node : & BinaryExpressionContent ) -> Option < SpBinopArgs > {
247254 Some ( SpBinopArgs {
@@ -251,6 +258,7 @@ impl SpBinopArgs {
251258 } )
252259 }
253260}
261+
254262impl SpBinopRule {
255263 pub fn check ( & self , acc : & mut Vec < DMLStyleError > ,
256264 ranges : Option < SpBinopArgs > ) {
@@ -268,6 +276,7 @@ impl SpBinopRule {
268276 }
269277 }
270278}
279+
271280impl Rule for SpBinopRule {
272281 fn name ( ) -> & ' static str {
273282 "sp_binop"
@@ -280,19 +289,21 @@ impl Rule for SpBinopRule {
280289 }
281290}
282291
283-
284292#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
285293pub struct SpTernaryOptions { }
294+
286295pub struct SpTernaryRule {
287296 pub enabled : bool ,
288297}
298+
289299pub struct SpTernaryArgs {
290300 left : ZeroRange ,
291301 left_op : ZeroRange ,
292302 middle : ZeroRange ,
293303 right_op : ZeroRange ,
294304 right : ZeroRange ,
295305}
306+
296307impl SpTernaryArgs {
297308 pub fn from_tertiary_expression_content ( node : & TertiaryExpressionContent ) -> Option < SpTernaryArgs > {
298309 Some ( SpTernaryArgs {
@@ -304,10 +315,12 @@ impl SpTernaryArgs {
304315 } )
305316 }
306317}
318+
307319fn no_gap ( left : ZeroRange , right : ZeroRange ) -> bool {
308320 left. row_end == right. row_start
309321 && left. col_end == right. col_start
310322}
323+
311324impl SpTernaryRule {
312325 pub fn check ( & self , acc : & mut Vec < DMLStyleError > ,
313326 ranges : Option < SpTernaryArgs > ) {
@@ -328,6 +341,7 @@ impl SpTernaryRule {
328341 }
329342 }
330343}
344+
331345impl Rule for SpTernaryRule {
332346 fn name ( ) -> & ' static str {
333347 "sp_ternary"
@@ -346,11 +360,13 @@ pub struct SpPunctOptions {}
346360pub struct SpPunctRule {
347361 pub enabled : bool ,
348362}
363+
349364pub struct SpPunctArgs {
350365 before_range_list : Vec < Range < ZeroIndexed > > ,
351366 punct_range_list : Vec < Range < ZeroIndexed > > ,
352367 after_range_list : Vec < Option < Range < ZeroIndexed > > > ,
353368}
369+
354370impl SpPunctArgs {
355371 pub fn from_method ( node : & MethodContent ) -> Option < SpPunctArgs > {
356372 let mut before_range_list = vec ! [ ] ;
@@ -483,14 +499,17 @@ impl Rule for SpPunctRule {
483499 RuleType :: SpPunct
484500 }
485501}
502+
486503#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
487504pub struct NspFunparOptions { }
488505
489506pub struct NspFunparRule {
490507 pub enabled : bool ,
491508}
492- // Single ZeroRange required as input for this rule
509+
510+ // Single ZeroRange required as input for this rule
493511pub type NspFunparArgs = ZeroRange ;
512+
494513impl NspFunparArgs {
495514 fn found_gap ( fn_name : & ZeroRange , lparen : & ZeroRange )
496515 -> Option < NspFunparArgs > {
@@ -512,6 +531,7 @@ impl NspFunparArgs {
512531 Self :: found_gap ( & node. fun . range ( ) , & node. lparen . range ( ) )
513532 }
514533}
534+
515535impl NspFunparRule {
516536 pub fn check ( & self ,
517537 acc : & mut Vec < DMLStyleError > ,
@@ -522,6 +542,7 @@ impl NspFunparRule {
522542 }
523543 }
524544}
545+
525546impl Rule for NspFunparRule {
526547 fn name ( ) -> & ' static str {
527548 "nsp_funpar"
@@ -534,19 +555,20 @@ impl Rule for NspFunparRule {
534555 }
535556}
536557
537-
538558#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
539559pub struct NspInparenOptions { }
540560
541561pub struct NspInparenRule {
542562 pub enabled : bool ,
543563}
564+
544565pub struct NspInparenArgs {
545566 opening : ZeroRange ,
546567 content_start : ZeroRange ,
547568 content_end : ZeroRange ,
548569 closing : ZeroRange ,
549570}
571+
550572impl NspInparenArgs {
551573 pub fn from_method ( node : & MethodContent ) -> Option < NspInparenArgs > {
552574 let content_start_range;
@@ -600,6 +622,7 @@ impl NspInparenArgs {
600622 } )
601623 }
602624}
625+
603626impl NspInparenRule {
604627 pub fn check ( & self ,
605628 acc : & mut Vec < DMLStyleError > ,
@@ -623,6 +646,7 @@ impl NspInparenRule {
623646 }
624647 }
625648}
649+
626650impl Rule for NspInparenRule {
627651 fn name ( ) -> & ' static str {
628652 "nsp_inparen"
@@ -641,8 +665,10 @@ pub struct NspUnaryOptions {}
641665pub struct NspUnaryRule {
642666 pub enabled : bool ,
643667}
668+
644669// Single ZeroRange required as input for this rule
645670pub type NspUnaryArgs = ZeroRange ;
671+
646672impl NspUnaryArgs {
647673 pub fn from_unary_expr ( node : & UnaryExpressionContent )
648674 -> Option < NspUnaryArgs > {
@@ -663,6 +689,7 @@ impl NspUnaryArgs {
663689 } else { None }
664690 }
665691}
692+
666693impl NspUnaryRule {
667694 pub fn check ( & self ,
668695 acc : & mut Vec < DMLStyleError > ,
@@ -673,6 +700,7 @@ impl NspUnaryRule {
673700 }
674701 }
675702}
703+
676704impl Rule for NspUnaryRule {
677705 fn name ( ) -> & ' static str {
678706 "nsp_unary"
@@ -691,6 +719,7 @@ pub struct NspTrailingOptions {}
691719pub struct NspTrailingRule {
692720 pub enabled : bool ,
693721}
722+
694723impl NspTrailingRule {
695724 pub fn check ( & self , acc : & mut Vec < DMLStyleError > , row : usize , line : & str ) {
696725 if !self . enabled { return ; }
@@ -705,6 +734,7 @@ impl NspTrailingRule {
705734 }
706735 }
707736}
737+
708738impl Rule for NspTrailingRule {
709739 fn name ( ) -> & ' static str {
710740 "nsp_trailing"
@@ -716,30 +746,14 @@ impl Rule for NspTrailingRule {
716746 RuleType :: NspTrailing
717747 }
718748}
719- pub struct SpPtrDeclRule {
720- pub enabled : bool ,
721- }
722749
723750#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
724751pub struct SpPtrDeclOptions { }
725752
726- impl Rule for SpPtrDeclRule {
727- fn name ( ) -> & ' static str {
728- "sp_ptrdecl"
729- }
730- fn description ( ) -> & ' static str {
731- "There should be a space between type and * marking a pointer"
732- }
733- fn get_rule_type ( ) -> RuleType {
734- RuleType :: SpPtrDecl
735- }
753+ pub struct SpPtrDeclRule {
754+ pub enabled : bool ,
736755}
737756
738- fn has_space_between ( range_left : & ZeroRange ,
739- range_right : & ZeroRange ) -> bool {
740- return !( ( range_left. row_end == range_right. row_start )
741- && ( range_left. col_end == range_right. col_start ) )
742- }
743757pub struct SpPtrDeclArgs {
744758 type_name_range : ZeroRange ,
745759 operator_ranges : Vec < ZeroRange >
@@ -771,6 +785,12 @@ impl SpPtrDeclArgs {
771785 }
772786}
773787
788+ fn has_space_between ( range_left : & ZeroRange ,
789+ range_right : & ZeroRange ) -> bool {
790+ return !( ( range_left. row_end == range_right. row_start )
791+ && ( range_left. col_end == range_right. col_start ) )
792+ }
793+
774794impl SpPtrDeclRule {
775795 pub fn check ( & self , acc : & mut Vec < DMLStyleError > ,
776796 ranges : Option < SpPtrDeclArgs > ) {
@@ -789,13 +809,25 @@ impl SpPtrDeclRule {
789809 }
790810}
791811
792- pub struct NspPtrDeclRule {
793- pub enabled : bool ,
812+ impl Rule for SpPtrDeclRule {
813+ fn name ( ) -> & ' static str {
814+ "sp_ptrdecl"
815+ }
816+ fn description ( ) -> & ' static str {
817+ "There should be a space between type and * marking a pointer"
818+ }
819+ fn get_rule_type ( ) -> RuleType {
820+ RuleType :: SpPtrDecl
821+ }
794822}
795823
796824#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
797825pub struct NspPtrDeclOptions { }
798826
827+ pub struct NspPtrDeclRule {
828+ pub enabled : bool ,
829+ }
830+
799831pub struct NspPtrDeclArgs {
800832 rightmost_multiply : Option < ZeroRange > ,
801833 identifier_range : ZeroRange
@@ -813,18 +845,6 @@ impl NspPtrDeclArgs {
813845 }
814846}
815847
816- impl Rule for NspPtrDeclRule {
817- fn name ( ) -> & ' static str {
818- "nsp_ptrdecl"
819- }
820- fn description ( ) -> & ' static str {
821- "There should be no space after the * marking a pointer in a declaration"
822- }
823- fn get_rule_type ( ) -> RuleType {
824- RuleType :: NspPtrDecl
825- }
826- }
827-
828848impl NspPtrDeclRule {
829849 pub fn check ( & self , acc : & mut Vec < DMLStyleError > ,
830850 ranges : Option < NspPtrDeclArgs > ) {
@@ -844,4 +864,16 @@ impl NspPtrDeclRule {
844864 }
845865
846866 }
847- }
867+ }
868+
869+ impl Rule for NspPtrDeclRule {
870+ fn name ( ) -> & ' static str {
871+ "nsp_ptrdecl"
872+ }
873+ fn description ( ) -> & ' static str {
874+ "There should be no space after the * marking a pointer in a declaration"
875+ }
876+ fn get_rule_type ( ) -> RuleType {
877+ RuleType :: NspPtrDecl
878+ }
879+ }
0 commit comments