Skip to content

Commit

Permalink
perf(linter): iterate over each rule only once
Browse files Browse the repository at this point in the history
  • Loading branch information
camchenry committed Oct 21, 2024
1 parent 1bcd707 commit 318bf0e
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,24 @@ impl Linter {
.map(|rule| (rule, Rc::clone(&ctx_host).spawn(rule)))
.collect::<Vec<_>>();

for (rule, ctx) in &rules {
rule.run_once(ctx);
}
let nodes = ctx_host.semantic().nodes().iter().collect::<Vec<&AstNode>>();

let semantic = ctx_host.semantic();
for symbol in semantic.symbols().symbol_ids() {
for (rule, ctx) in &rules {
let should_run_on_jest_node =
self.options.plugins.has_test() && ctx_host.frameworks().is_test();
for (rule, ref ctx) in &rules {
rule.run_once(ctx);

for symbol in semantic.symbols().symbol_ids() {
rule.run_on_symbol(symbol, ctx);
}
}

for node in semantic.nodes() {
for (rule, ctx) in &rules {
for node in &nodes {
rule.run(node, ctx);
}
}

if ctx_host.frameworks().is_test() && self.options.plugins.has_test() {
for jest_node in iter_possible_jest_call_node(semantic) {
for (rule, ctx) in &rules {
if should_run_on_jest_node {
for jest_node in iter_possible_jest_call_node(semantic) {
rule.run_on_jest_node(&jest_node, ctx);
}
}
Expand Down

0 comments on commit 318bf0e

Please sign in to comment.