@@ -105,11 +105,14 @@ struct ScanWithConfig<Printer> {
105
105
arg : ScanArg ,
106
106
printer : Printer ,
107
107
configs : RuleCollection < SgLang > ,
108
+ unused_suppression_rule : RuleConfig < SgLang > ,
108
109
trace : ScanTrace ,
109
110
}
110
111
impl < P : Printer > ScanWithConfig < P > {
111
112
fn try_new ( arg : ScanArg , printer : P , project : Result < ProjectConfig > ) -> Result < Self > {
112
113
let mut rule_trace = RuleTrace :: default ( ) ;
114
+ let overwrite = RuleOverwrite :: new ( & arg. overwrite ) ?;
115
+ let unused_suppression_rule = unused_supression_rule_config ( & overwrite) ;
113
116
let configs = if let Some ( path) = & arg. rule {
114
117
let rules = read_rule_file ( path, None ) ?;
115
118
RuleCollection :: try_new ( rules) . context ( EC :: GlobPattern ) ?
@@ -120,7 +123,6 @@ impl<P: Printer> ScanWithConfig<P> {
120
123
} else {
121
124
// NOTE: only query project here since -r does not need project
122
125
let project_config = project?;
123
- let overwrite = RuleOverwrite :: new ( & arg. overwrite ) ?;
124
126
let ( configs, r_stats) = project_config. find_rules ( overwrite) ?;
125
127
rule_trace = r_stats;
126
128
configs
@@ -130,6 +132,7 @@ impl<P: Printer> ScanWithConfig<P> {
130
132
arg,
131
133
printer,
132
134
configs,
135
+ unused_suppression_rule,
133
136
trace,
134
137
} )
135
138
}
@@ -168,6 +171,7 @@ impl<P: Printer> Worker for ScanWithConfig<P> {
168
171
print_unused_suppressions (
169
172
path,
170
173
scanned. unused_suppressions ,
174
+ & self . unused_suppression_rule ,
171
175
& file_content,
172
176
& self . printer ,
173
177
) ?;
@@ -184,12 +188,7 @@ impl<P: Printer> Worker for ScanWithConfig<P> {
184
188
}
185
189
}
186
190
187
- fn print_unused_suppressions (
188
- path : & Path ,
189
- matches : Vec < NodeMatch < StrDoc < SgLang > > > ,
190
- file_content : & String ,
191
- printer : & impl Printer ,
192
- ) -> Result < ( ) > {
191
+ fn unused_supression_rule_config ( overwrite : & RuleOverwrite ) -> RuleConfig < SgLang > {
193
192
let rule: SerializableRule = serde_json:: from_str ( r#"{"pattern": "a"}"# ) . unwrap ( ) ;
194
193
let core = SerializableRuleCore {
195
194
rule,
@@ -198,21 +197,34 @@ fn print_unused_suppressions(
198
197
transform : None ,
199
198
utils : None ,
200
199
} ;
200
+ let severity = overwrite
201
+ . find ( "unused-suppression" )
202
+ . severity
203
+ . unwrap_or ( Severity :: Hint ) ;
201
204
let config = SerializableRuleConfig :: < SgLang > {
202
205
core,
203
206
id : "unused-suppression" . to_string ( ) ,
207
+ severity,
204
208
files : None ,
205
209
ignores : None ,
206
210
language : "rust" . parse ( ) . unwrap ( ) ,
207
- message : "Unused '@ ast-grep-ignore' directive." . into ( ) ,
211
+ message : "Unused 'ast-grep-ignore' directive." . into ( ) ,
208
212
metadata : None ,
209
213
note : None ,
210
214
rewriters : None ,
211
- severity : Severity :: Hint ,
212
215
url : None ,
213
216
} ;
214
- let rule_config = RuleConfig :: try_from ( config, & Default :: default ( ) ) . unwrap ( ) ;
215
- match_rule_on_file ( path, matches, & rule_config, file_content, printer)
217
+ RuleConfig :: try_from ( config, & Default :: default ( ) ) . unwrap ( )
218
+ }
219
+
220
+ fn print_unused_suppressions (
221
+ path : & Path ,
222
+ matches : Vec < NodeMatch < StrDoc < SgLang > > > ,
223
+ rule_config : & RuleConfig < SgLang > ,
224
+ file_content : & String ,
225
+ printer : & impl Printer ,
226
+ ) -> Result < ( ) > {
227
+ match_rule_on_file ( path, matches, rule_config, file_content, printer)
216
228
}
217
229
218
230
impl < P : Printer > PathWorker for ScanWithConfig < P > {
0 commit comments