diff --git a/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs b/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs index 71254b9c89e4c..343fc3f48e4b3 100644 --- a/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs +++ b/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs @@ -1,5 +1,5 @@ use oxc_ast::{ - AstKind, + AstKind, AstType, ast::{Argument, Expression, MethodDefinitionKind}, }; use oxc_cfg::{ @@ -58,6 +58,11 @@ enum DefinitelyCallsThisBeforeSuper { Maybe(BlockNodeId), } +/// Node types that should be in the file in order to run this analysis. Otherwise, the AST +/// will be skipped for linting. +const NEEDED_NODE_TYPES: &AstTypesBitset = + &AstTypesBitset::from_types(&[AstType::ThisExpression, AstType::Super]); + impl Rule for NoThisBeforeSuper { fn run_once(&self, ctx: &LintContext) { let cfg = ctx.cfg(); @@ -132,6 +137,10 @@ impl Rule for NoThisBeforeSuper { } } } + + fn should_run(&self, ctx: &crate::context::ContextHost) -> bool { + ctx.semantic().nodes().contains_any(NEEDED_NODE_TYPES) + } } impl NoThisBeforeSuper {