@@ -60,98 +60,33 @@ pub struct ESLintRule {
6060impl OxlintRules {
6161 pub ( crate ) fn override_rules ( & self , rules_for_override : & mut RuleSet , all_rules : & [ RuleEnum ] ) {
6262 use itertools:: Itertools ;
63- let mut rules_to_replace: Vec < ( RuleEnum , AllowWarnDeny ) > = vec ! [ ] ;
63+ let mut rules_to_replace = vec ! [ ] ;
6464
65- // Rules can have the same name but different plugin names
6665 let lookup = self . rules . iter ( ) . into_group_map_by ( |r| r. rule_name . as_str ( ) ) ;
6766
6867 for ( name, rule_configs) in & lookup {
69- match rule_configs. len ( ) {
70- 0 => unreachable ! ( ) ,
71- 1 => {
72- let rule_config = & rule_configs[ 0 ] ;
73- let ( rule_name, plugin_name) = transform_rule_and_plugin_name (
74- & rule_config. rule_name ,
75- & rule_config. plugin_name ,
76- ) ;
77- let severity = rule_config. severity ;
78- match severity {
79- AllowWarnDeny :: Warn | AllowWarnDeny :: Deny => {
80- if let Some ( rule) = all_rules
81- . iter ( )
82- . find ( |r| r. name ( ) == rule_name && r. plugin_name ( ) == plugin_name)
83- {
84- let config = rule_config. config . clone ( ) . unwrap_or_default ( ) ;
85- let rule = rule. read_json ( config) ;
86- rules_to_replace. push ( ( rule, severity) ) ;
87- }
88- }
89- AllowWarnDeny :: Allow => {
90- if let Some ( ( rule, _) ) = rules_for_override. iter ( ) . find ( |( r, _) | {
91- r. name ( ) == rule_name && r. plugin_name ( ) == plugin_name
92- } ) {
93- let config = rule_config. config . clone ( ) . unwrap_or_default ( ) ;
94- let rule = rule. read_json ( config) ;
95- rules_to_replace. push ( ( rule, AllowWarnDeny :: Allow ) ) ;
96- }
97- // If the given rule is not found in the rule list (for example, if all rules are disabled),
98- // then look it up in the entire rules list and add it.
99- else if let Some ( rule) = all_rules
100- . iter ( )
101- . find ( |r| r. name ( ) == rule_name && r. plugin_name ( ) == plugin_name)
102- {
103- let config = rule_config. config . clone ( ) . unwrap_or_default ( ) ;
104- let rule = rule. read_json ( config) ;
105- rules_to_replace. push ( ( rule, AllowWarnDeny :: Allow ) ) ;
106- }
107- }
108- }
109- }
110- _ => {
111- let rules = rules_for_override
68+ let rules_map = rules_for_override
69+ . iter ( )
70+ . filter ( |& ( r, _) | ( r. name ( ) == * name) )
71+ . map ( |( r, _) | ( r. plugin_name ( ) , r) )
72+ . collect :: < FxHashMap < _ , _ > > ( ) ;
73+
74+ for rule_config in rule_configs {
75+ let ( rule_name, plugin_name) = transform_rule_and_plugin_name (
76+ & rule_config. rule_name ,
77+ & rule_config. plugin_name ,
78+ ) ;
79+ let config = rule_config. config . clone ( ) . unwrap_or_default ( ) ;
80+ let severity = rule_config. severity ;
81+
82+ let rule = rules_map. get ( & plugin_name) . copied ( ) . or_else ( || {
83+ all_rules
11284 . iter ( )
113- . filter_map ( |( r, _) | {
114- if r. name ( ) == * name { Some ( ( r. plugin_name ( ) , r) ) } else { None }
115- } )
116- . collect :: < FxHashMap < _ , _ > > ( ) ;
117-
118- for rule_config in rule_configs {
119- let ( rule_name, plugin_name) = transform_rule_and_plugin_name (
120- & rule_config. rule_name ,
121- & rule_config. plugin_name ,
122- ) ;
123-
124- if rule_config. severity . is_warn_deny ( ) {
125- let config = rule_config. config . clone ( ) . unwrap_or_default ( ) ;
126- if let Some ( rule) = rules. get ( & plugin_name) {
127- rules_to_replace
128- . push ( ( rule. read_json ( config) , rule_config. severity ) ) ;
129- }
130- // If the given rule is not found in the rule list (for example, if all rules are disabled),
131- // then look it up in the entire rules list and add it.
132- else if let Some ( rule) = all_rules
133- . iter ( )
134- . find ( |r| r. name ( ) == rule_name && r. plugin_name ( ) == plugin_name)
135- {
136- rules_to_replace
137- . push ( ( rule. read_json ( config) , rule_config. severity ) ) ;
138- }
139- } else if let Some ( & rule) = rules. get ( & plugin_name) {
140- let config = rule_config. config . clone ( ) . unwrap_or_default ( ) ;
141- let rule = rule. read_json ( config) ;
142- rules_to_replace. push ( ( rule, AllowWarnDeny :: Allow ) ) ;
143- }
144- // If the given rule is not found in the rule list (for example, if all rules are disabled),
145- // then look it up in the entire rules list and add it with Allow severity.
146- else if let Some ( rule) = all_rules
147- . iter ( )
148- . find ( |r| r. name ( ) == rule_name && r. plugin_name ( ) == plugin_name)
149- {
150- let config = rule_config. config . clone ( ) . unwrap_or_default ( ) ;
151- let rule = rule. read_json ( config) ;
152- rules_to_replace. push ( ( rule, AllowWarnDeny :: Allow ) ) ;
153- }
154- }
85+ . find ( |r| r. name ( ) == rule_name && r. plugin_name ( ) == plugin_name)
86+ } ) ;
87+
88+ if let Some ( rule) = rule {
89+ rules_to_replace. push ( ( rule. read_json ( config) , severity) ) ;
15590 }
15691 }
15792 }
0 commit comments