Skip to content

Commit e5d03c5

Browse files
committed
perf(linter): run no-class-assign on class nodes instead of symbols
1 parent 92e1748 commit e5d03c5

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

crates/oxc_linter/src/generated/rule_runner_impls.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ impl RuleRunner for crate::rules::eslint::no_case_declarations::NoCaseDeclaratio
200200
}
201201

202202
impl RuleRunner for crate::rules::eslint::no_class_assign::NoClassAssign {
203-
const NODE_TYPES: Option<&AstTypesBitset> = None;
204-
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::RunOnSymbol;
203+
const NODE_TYPES: Option<&AstTypesBitset> =
204+
Some(&AstTypesBitset::from_types(&[AstType::Class]));
205+
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
205206
}
206207

207208
impl RuleRunner for crate::rules::eslint::no_compare_neg_zero::NoCompareNegZero {

crates/oxc_linter/src/rules/eslint/no_class_assign.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use oxc_ast::AstKind;
12
use oxc_diagnostics::OxcDiagnostic;
23
use oxc_macros::declare_oxc_lint;
3-
use oxc_semantic::SymbolId;
4+
use oxc_semantic::AstNode;
45
use oxc_span::Span;
56

67
use crate::{context::LintContext, rule::Rule};
@@ -82,17 +83,27 @@ declare_oxc_lint!(
8283
);
8384

8485
impl Rule for NoClassAssign {
85-
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {
86+
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
87+
let AstKind::Class(class) = node.kind() else {
88+
return;
89+
};
90+
91+
let Some(symbol_id) = class.id.as_ref().map(|ident| ident.symbol_id()) else {
92+
return;
93+
};
94+
8695
let symbol_table = ctx.scoping();
87-
if symbol_table.symbol_flags(symbol_id).is_class() {
88-
for reference in symbol_table.get_resolved_references(symbol_id) {
89-
if reference.is_write() {
90-
ctx.diagnostic(no_class_assign_diagnostic(
91-
symbol_table.symbol_name(symbol_id),
92-
symbol_table.symbol_span(symbol_id),
93-
ctx.semantic().reference_span(reference),
94-
));
95-
}
96+
// This should always be considered a class (since we got it from a class declaration),
97+
// but we check in debug mode just to be sure.
98+
debug_assert!(ctx.scoping().symbol_flags(symbol_id).is_class());
99+
100+
for reference in symbol_table.get_resolved_references(symbol_id) {
101+
if reference.is_write() {
102+
ctx.diagnostic(no_class_assign_diagnostic(
103+
symbol_table.symbol_name(symbol_id),
104+
symbol_table.symbol_span(symbol_id),
105+
ctx.semantic().reference_span(reference),
106+
));
96107
}
97108
}
98109
}

0 commit comments

Comments
 (0)