|
| 1 | +use oxc_ast::AstKind; |
1 | 2 | use oxc_diagnostics::OxcDiagnostic; |
2 | 3 | use oxc_macros::declare_oxc_lint; |
3 | | -use oxc_semantic::SymbolId; |
| 4 | +use oxc_semantic::AstNode; |
4 | 5 | use oxc_span::Span; |
5 | 6 |
|
6 | 7 | use crate::{context::LintContext, rule::Rule}; |
@@ -82,17 +83,27 @@ declare_oxc_lint!( |
82 | 83 | ); |
83 | 84 |
|
84 | 85 | 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 | + |
86 | 95 | 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 | + )); |
96 | 107 | } |
97 | 108 | } |
98 | 109 | } |
|
0 commit comments