@@ -6,8 +6,8 @@ use kernel::config::common::{
66 parse_any_schema_yaml, ConfigError , PathConfig , PathPattern , RuleConfig , RulesetConfig ,
77 WithVersion ,
88} ;
9- use kernel:: config:: file_v1 :: config_file_to_yaml;
10- use kernel:: config:: { file_v1 , file_v2} ;
9+ use kernel:: config:: file_legacy :: config_file_to_yaml;
10+ use kernel:: config:: { file_legacy , file_v2} ;
1111use kernel:: utils:: decode_base64_string;
1212use std:: { borrow:: Cow , fmt:: Debug } ;
1313use tracing:: instrument;
@@ -16,23 +16,23 @@ const WILDCARD_IGNORE: &str = "**";
1616
1717#[ derive( Debug , Clone , PartialEq ) ]
1818pub struct StaticAnalysisConfigFile {
19- config_file : WithVersion < file_v1 :: ConfigFile , file_v2:: YamlConfigFile > ,
19+ config_file : WithVersion < file_legacy :: ConfigFile , file_v2:: YamlConfigFile > ,
2020 original_content : Option < String > ,
2121}
2222
2323impl Default for StaticAnalysisConfigFile {
2424 fn default ( ) -> Self {
2525 Self {
26- config_file : WithVersion :: V1 ( Default :: default ( ) ) ,
26+ config_file : WithVersion :: Legacy ( Default :: default ( ) ) ,
2727 original_content : None ,
2828 }
2929 }
3030}
3131
32- impl From < file_v1 :: ConfigFile > for StaticAnalysisConfigFile {
33- fn from ( value : file_v1 :: ConfigFile ) -> Self {
32+ impl From < file_legacy :: ConfigFile > for StaticAnalysisConfigFile {
33+ fn from ( value : file_legacy :: ConfigFile ) -> Self {
3434 Self {
35- config_file : WithVersion :: V1 ( value) ,
35+ config_file : WithVersion :: Legacy ( value) ,
3636 original_content : None ,
3737 }
3838 }
@@ -57,7 +57,7 @@ impl TryFrom<String> for StaticAnalysisConfigFile {
5757 }
5858 } ) ?;
5959 let config_file = match parsed {
60- WithVersion :: V1 ( yaml) => WithVersion :: V1 ( file_v1 :: ConfigFile :: from ( yaml) ) ,
60+ WithVersion :: Legacy ( yaml) => WithVersion :: Legacy ( file_legacy :: ConfigFile :: from ( yaml) ) ,
6161 WithVersion :: V2 ( yaml) => WithVersion :: V2 ( yaml) ,
6262 } ;
6363 Ok ( Self {
@@ -145,7 +145,7 @@ impl StaticAnalysisConfigFile {
145145 return ;
146146 } ;
147147 match & mut self . config_file {
148- WithVersion :: V1 ( config) => {
148+ WithVersion :: Legacy ( config) => {
149149 // the ruleset may exist and contain other rules so we
150150 // can't update it blindly
151151 if let Some ( existing_ruleset) = config. rulesets . get_mut ( ruleset_name) {
@@ -173,7 +173,7 @@ impl StaticAnalysisConfigFile {
173173 }
174174 }
175175 WithVersion :: V2 ( config) => {
176- // (All logic for this is translated from the V1 match arm)
176+ // (All logic for this is translated from the Legacy match arm)
177177 let map = config. ruleset_configs . get_or_insert_default ( ) ;
178178 let ruleset_config = map. 0 . entry ( ruleset_name. to_string ( ) ) . or_default ( ) ;
179179 let rule_config = ruleset_config
@@ -238,7 +238,7 @@ impl StaticAnalysisConfigFile {
238238 #[ instrument( skip( self ) ) ]
239239 pub fn add_rulesets ( & mut self , rulesets : & [ impl AsRef < str > + Debug ] ) {
240240 match & mut self . config_file {
241- WithVersion :: V1 ( config) => {
241+ WithVersion :: Legacy ( config) => {
242242 for ruleset in rulesets {
243243 if !config. rulesets . contains_key ( ruleset. as_ref ( ) ) {
244244 config
@@ -292,15 +292,15 @@ impl StaticAnalysisConfigFile {
292292 }
293293 } ;
294294 match parsed. config_file {
295- WithVersion :: V1 ( config) => config. rulesets . iter ( ) . map ( |rs| rs. 0 . clone ( ) ) . collect ( ) ,
295+ WithVersion :: Legacy ( config) => config. rulesets . iter ( ) . map ( |rs| rs. 0 . clone ( ) ) . collect ( ) ,
296296 WithVersion :: V2 ( config) => config. use_rulesets . clone ( ) . unwrap_or_default ( ) ,
297297 }
298298 }
299299
300300 #[ instrument( skip( self ) ) ]
301301 pub fn is_onboarding_allowed ( & self ) -> bool {
302302 match & self . config_file {
303- WithVersion :: V1 ( config) => {
303+ WithVersion :: Legacy ( config) => {
304304 config. paths . only . is_none ( ) && config. paths . ignore . is_empty ( )
305305 }
306306 WithVersion :: V2 ( config) => {
@@ -325,7 +325,7 @@ impl StaticAnalysisConfigFile {
325325 #[ instrument( skip( self ) ) ]
326326 pub fn to_string ( & self ) -> Result < String , ConfigFileError > {
327327 let yaml = match & self . config_file {
328- WithVersion :: V1 ( config) => {
328+ WithVersion :: Legacy ( config) => {
329329 let str = config_file_to_yaml ( config) ?;
330330 // fix null maps, note that str will not have comments and it will be using the default serde format.
331331 str. lines ( )
@@ -481,14 +481,14 @@ rulesets:
481481 #[ test]
482482 fn it_works_simple ( ) {
483483 // language=yaml
484- let v1 = r"
484+ let legacy = r"
485485schema-version: v1
486486rulesets:
487487- java-security
488488- java-1
489489" ;
490490 // language=yaml
491- let v1_expected = r"
491+ let legacy_expected = r"
492492schema-version: v1
493493rulesets:
494494 - java-security
@@ -515,7 +515,7 @@ use-rulesets:
515515 - ruleset2
516516 - a-ruleset3
517517" ;
518- for ( yaml, expected) in [ ( v1 , v1_expected ) , ( v2, v2_expected) ] {
518+ for ( yaml, expected) in [ ( legacy , legacy_expected ) , ( v2, v2_expected) ] {
519519 let config = StaticAnalysisConfigFile :: with_added_rulesets (
520520 & [ "ruleset1" , "ruleset2" , "a-ruleset3" ] ,
521521 Some ( to_encoded_content ( yaml) ) ,
@@ -529,13 +529,13 @@ use-rulesets:
529529 #[ test]
530530 fn add_no_duplicate_rulesets ( ) {
531531 // language=yaml
532- let v1 = r"
532+ let legacy = r"
533533schema-version: v1
534534rulesets:
535535- java-security
536536" ;
537537 // language=yaml
538- let v1_expected = r"
538+ let legacy_expected = r"
539539schema-version: v1
540540rulesets:
541541 - java-security
@@ -555,7 +555,7 @@ use-rulesets:
555555 - java-security
556556 - new-ruleset
557557" ;
558- for ( yaml, expected) in [ ( v1 , v1_expected ) , ( v2, v2_expected) ] {
558+ for ( yaml, expected) in [ ( legacy , legacy_expected ) , ( v2, v2_expected) ] {
559559 let config = StaticAnalysisConfigFile :: with_added_rulesets (
560560 & [ "new-ruleset" , "new-ruleset" ] ,
561561 Some ( to_encoded_content ( yaml) ) ,
@@ -657,14 +657,14 @@ rulesets:
657657 #[ test]
658658 fn it_works_with_non_previously_existing_ruleset ( ) {
659659 // language=yaml
660- let v1 = r"
660+ let legacy = r"
661661schema-version: v1
662662rulesets:
663663- java-1
664664- java-security
665665" ;
666666 // language=yaml
667- let v1_expected = r#"
667+ let legacy_expected = r#"
668668schema-version: v1
669669rulesets:
670670 - java-1
@@ -714,7 +714,7 @@ ruleset-configs:
714714"# ;
715715
716716 for ( yaml, expected) in [
717- ( v1 , v1_expected ) ,
717+ ( legacy , legacy_expected ) ,
718718 ( v2_with_rs_configs, v2_with_rs_configs_expected) ,
719719 ( v2_without_rs_configs, v2_without_rs_configs_expected) ,
720720 ] {
@@ -731,15 +731,15 @@ ruleset-configs:
731731 #[ test]
732732 fn it_works_with_a_previously_existing_ruleset ( ) {
733733 // language=yaml
734- let v1 = r"
734+ let legacy = r"
735735schema-version: v1
736736rulesets:
737737- java-1
738738- java-security
739739- ruleset1
740740" ;
741741 // language=yaml
742- let v1_expected = r#"
742+ let legacy_expected = r#"
743743schema-version: v1
744744rulesets:
745745 - java-1
@@ -768,7 +768,7 @@ ruleset-configs:
768768 - "**"
769769"# ;
770770
771- for ( yaml, expected) in [ ( v1 , v1_expected ) , ( v2, v2_expected) ] {
771+ for ( yaml, expected) in [ ( legacy , legacy_expected ) , ( v2, v2_expected) ] {
772772 let config = StaticAnalysisConfigFile :: with_ignored_rule (
773773 "ruleset1/rule1" . into ( ) ,
774774 to_encoded_content ( yaml) ,
@@ -785,7 +785,7 @@ ruleset-configs:
785785 #[ test]
786786 fn it_works_with_a_previously_existing_ruleset_with_same_rule_path_config ( ) {
787787 // language=yaml
788- let v1 = r"
788+ let legacy = r"
789789schema-version: v1
790790rulesets:
791791- java-1
@@ -797,7 +797,7 @@ rulesets:
797797 - foo/bar
798798" ;
799799 // language=yaml
800- let v1_expected = r#"
800+ let legacy_expected = r#"
801801schema-version: v1
802802rulesets:
803803 - java-1
@@ -834,7 +834,7 @@ ruleset-configs:
834834 - "**"
835835"# ;
836836
837- for ( yaml, expected) in [ ( v1 , v1_expected ) , ( v2, v2_expected) ] {
837+ for ( yaml, expected) in [ ( legacy , legacy_expected ) , ( v2, v2_expected) ] {
838838 let config = StaticAnalysisConfigFile :: with_ignored_rule (
839839 "ruleset1/rule1" . into ( ) ,
840840 to_encoded_content ( yaml) ,
@@ -908,7 +908,7 @@ rulesets:
908908 #[ test]
909909 fn it_keeps_existing_properties_when_ignoring_other_rules ( ) {
910910 // language=yaml
911- let v1 = r"
911+ let legacy = r"
912912schema-version: v1
913913rulesets:
914914- java-security
@@ -919,7 +919,7 @@ rulesets:
919919 severity: ERROR
920920" ;
921921 // language=yaml
922- let v1_expected = r#"
922+ let legacy_expected = r#"
923923schema-version: v1
924924rulesets:
925925 - java-security
@@ -955,7 +955,7 @@ ruleset-configs:
955955 - "**"
956956"# ;
957957
958- for ( yaml, expected) in [ ( v1 , v1_expected ) , ( v2, v2_expected) ] {
958+ for ( yaml, expected) in [ ( legacy , legacy_expected ) , ( v2, v2_expected) ] {
959959 let config = StaticAnalysisConfigFile :: with_ignored_rule (
960960 "ruleset1/rule1" . into ( ) ,
961961 to_encoded_content ( yaml) ,
@@ -969,7 +969,7 @@ ruleset-configs:
969969 #[ test]
970970 fn it_keeps_existing_properties_when_ignoring_same_rule ( ) {
971971 // language=yaml
972- let v1 = r"
972+ let legacy = r"
973973schema-version: v1
974974rulesets:
975975- java-security
@@ -980,7 +980,7 @@ rulesets:
980980 severity: ERROR
981981" ;
982982 // language=yaml
983- let v1_expected = r#"
983+ let legacy_expected = r#"
984984schema-version: v1
985985rulesets:
986986 - java-security
@@ -1014,7 +1014,7 @@ ruleset-configs:
10141014 severity: ERROR
10151015"# ;
10161016
1017- for ( yaml, expected) in [ ( v1 , v1_expected ) , ( v2, v2_expected) ] {
1017+ for ( yaml, expected) in [ ( legacy , legacy_expected ) , ( v2, v2_expected) ] {
10181018 let config = StaticAnalysisConfigFile :: with_ignored_rule (
10191019 "ruleset1/rule2" . into ( ) ,
10201020 to_encoded_content ( yaml) ,
@@ -1034,7 +1034,7 @@ ruleset-configs:
10341034 #[ test]
10351035 fn it_should_return_false_for_top_level_ignore_only ( ) {
10361036 // language=yaml
1037- let v1_only = r"#
1037+ let legacy_only = r"#
10381038schema-version: v1
10391039rulesets:
10401040 - java-security
@@ -1043,7 +1043,7 @@ only:
10431043 - domains/project1
10441044" ;
10451045 // language=yaml
1046- let v1_ignore = r"
1046+ let legacy_ignore = r"
10471047schema-version: v1
10481048rulesets:
10491049 - java-security
@@ -1052,7 +1052,7 @@ ignore:
10521052 - domains/project1
10531053" ;
10541054 // language=yaml
1055- let v1_both = r"
1055+ let legacy_both = r"
10561056schema-version: v1
10571057rulesets:
10581058 - java-security
@@ -1086,7 +1086,14 @@ global-config:
10861086 - domains/project1/abc
10871087" ;
10881088
1089- for yaml in [ v1_only, v1_ignore, v1_both, v2_only, v2_ignore, v2_both] {
1089+ for yaml in [
1090+ legacy_only,
1091+ legacy_ignore,
1092+ legacy_both,
1093+ v2_only,
1094+ v2_ignore,
1095+ v2_both,
1096+ ] {
10901097 let config = StaticAnalysisConfigFile :: try_from ( to_encoded_content ( yaml) ) . unwrap ( ) ;
10911098 assert ! ( !config. is_onboarding_allowed( ) )
10921099 }
@@ -1095,7 +1102,7 @@ global-config:
10951102 #[ test]
10961103 fn it_should_return_true_if_ignore_and_only_at_top_level_are_not_present ( ) {
10971104 // language=yaml
1098- let v1 = r"
1105+ let legacy = r"
10991106schema-version: v1
11001107rulesets:
11011108 - java-security
@@ -1113,7 +1120,7 @@ global-config:
11131120 use-gitignore: true
11141121" ;
11151122
1116- for yaml in [ v1 , v2_no_global, v2_with_global] {
1123+ for yaml in [ legacy , v2_no_global, v2_with_global] {
11171124 let config = StaticAnalysisConfigFile :: try_from ( to_encoded_content ( yaml) ) . unwrap ( ) ;
11181125 assert ! ( config. is_onboarding_allowed( ) )
11191126 }
@@ -1122,7 +1129,7 @@ global-config:
11221129 #[ test]
11231130 fn it_should_return_true_with_nested_paths ( ) {
11241131 // language=yaml
1125- let v1 = r"
1132+ let legacy = r"
11261133schema-version: v1
11271134rulesets:
11281135 - java-security
@@ -1139,7 +1146,7 @@ ruleset-configs:
11391146 - domains/project1
11401147" ;
11411148
1142- for yaml in [ v1 , v2] {
1149+ for yaml in [ legacy , v2] {
11431150 let config = StaticAnalysisConfigFile :: try_from ( to_encoded_content ( yaml) ) . unwrap ( ) ;
11441151 assert ! ( config. is_onboarding_allowed( ) )
11451152 }
0 commit comments