@@ -141,7 +141,24 @@ impl Linter {
141141
142142 let rules = rules
143143 . iter ( )
144- . filter ( |( rule, _) | rule. should_run ( & ctx_host) && !rule. is_tsgolint_rule ( ) )
144+ . filter ( |( rule, _) | {
145+ if !rule. should_run ( & ctx_host) {
146+ return false ;
147+ }
148+ // Skip tsgolint rules in Rust linter
149+ if rule. is_tsgolint_rule ( ) {
150+ return false ;
151+ }
152+ // Skip rules that only run on nodes that this file does not contain
153+ let ( ast_types, all_types, only_runs_on_nodes) = rule. types_info ( ) ;
154+ if !all_types
155+ && only_runs_on_nodes
156+ && !ctx_host. semantic ( ) . nodes ( ) . contains_any ( ast_types)
157+ {
158+ return false ;
159+ }
160+ true
161+ } )
145162 . map ( |( rule, severity) | ( rule, Rc :: clone ( & ctx_host) . spawn ( rule, * severity) ) ) ;
146163
147164 let semantic = ctx_host. semantic ( ) ;
@@ -183,7 +200,7 @@ impl Linter {
183200 // Collect node type information for rules. In large files, benchmarking showed it was worth
184201 // collecting rules into buckets by AST node type to avoid iterating over all rules for each node.
185202 if rule. should_run ( & ctx_host) {
186- let ( ast_types, all_types) = rule. types_info ( ) ;
203+ let ( ast_types, all_types, _ ) = rule. types_info ( ) ;
187204 if all_types {
188205 rules_any_ast_type. push ( ( rule, ctx) ) ;
189206 } else {
@@ -229,7 +246,7 @@ impl Linter {
229246
230247 // For smaller files, benchmarking showed it was faster to iterate over all rules and just check the
231248 // node types as we go, rather than pre-bucketing rules by AST node type and doing extra allocations.
232- let ( ast_types, all_types) = rule. types_info ( ) ;
249+ let ( ast_types, all_types, _ ) = rule. types_info ( ) ;
233250 if all_types {
234251 for node in semantic. nodes ( ) {
235252 rule. run ( node, ctx) ;
0 commit comments