Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl Linter {
return false;
}
// Skip rules that only run on nodes that this file does not contain
let (ast_types, all_types, only_runs_on_nodes) = rule.types_info();
let (ast_types, all_types, only_runs_on_nodes, _) = rule.types_info();
if !all_types
&& only_runs_on_nodes
&& !ctx_host.semantic().nodes().contains_any(ast_types)
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Linter {
// Collect node type information for rules. In large files, benchmarking showed it was worth
// collecting rules into buckets by AST node type to avoid iterating over all rules for each node.
if rule.should_run(&ctx_host) {
let (ast_types, all_types, _) = rule.types_info();
let (ast_types, all_types, _, _) = rule.types_info();
if all_types {
rules_any_ast_type.push((rule, ctx));
} else {
Expand Down Expand Up @@ -238,7 +238,8 @@ impl Linter {
}
} else {
for (rule, ref ctx) in rules {
let (ast_types, all_types, only_runs_on_nodes) = rule.types_info();
let (ast_types, all_types, only_runs_on_nodes, only_runs_on_jest_nodes) =
rule.types_info();

if only_runs_on_nodes {
if all_types {
Expand All @@ -252,6 +253,12 @@ impl Linter {
}
}
}
} else if only_runs_on_jest_nodes {
if should_run_on_jest_node {
for jest_node in iter_possible_jest_call_node(semantic) {
rule.run_on_jest_node(&jest_node, ctx);
}
}
} else {
rule.run_once(ctx);

Expand Down
16 changes: 12 additions & 4 deletions crates/oxc_linter/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,17 @@ pub trait RuleRunner: Rule {
/// `true` if this rule only has a `run` implementation and does not implement
/// `run_on_symbol`, `run_once`, or `run_on_jest_node`.
const ONLY_RUNS_ON_NODES: bool = false;

fn types_info(&self) -> (&'static AstTypesBitset, bool, bool) {
(Self::NODE_TYPES, Self::ANY_NODE_TYPE, Self::ONLY_RUNS_ON_NODES)
/// `true` if this rule only has a `run_on_jest_node` implementation and does not implement
/// `run_on_symbol`, `run_once`, or `run`.
const ONLY_RUNS_ON_JEST_NODES: bool = false;

fn types_info(&self) -> (&'static AstTypesBitset, bool, bool, bool) {
(
Self::NODE_TYPES,
Self::ANY_NODE_TYPE,
Self::ONLY_RUNS_ON_NODES,
Self::ONLY_RUNS_ON_JEST_NODES,
)
}
}
pub trait RuleMeta {
Expand Down Expand Up @@ -464,7 +472,7 @@ mod test {
rule: &R,
node_types: &[oxc_ast::AstType],
) {
let (types, _, _) = rule.types_info();
let types = rule.types_info().0;
assert!(!R::ANY_NODE_TYPE, "{} should not have ANY_NODE_TYPE set to true", R::NAME);
for node_type in node_types {
assert!(
Expand Down
Loading
Loading