mirror of
https://github.com/danbulant/oxc
synced 2026-05-21 13:18:59 +00:00
refactor(linter): eslint/no_redeclare rule use run_on_symbol not run_once (#5201)
`eslint/no_redeclare` rule iterates over all symbols. Use `run_on_symbols` for this, instead of `run_once`.
This commit is contained in:
parent
8ff6f2cb86
commit
2a91ef10ea
1 changed files with 21 additions and 22 deletions
|
|
@ -5,6 +5,7 @@ use oxc_ast::{
|
||||||
use oxc_diagnostics::OxcDiagnostic;
|
use oxc_diagnostics::OxcDiagnostic;
|
||||||
use oxc_macros::declare_oxc_lint;
|
use oxc_macros::declare_oxc_lint;
|
||||||
use oxc_span::Span;
|
use oxc_span::Span;
|
||||||
|
use oxc_syntax::symbol::SymbolId;
|
||||||
|
|
||||||
use crate::{context::LintContext, rule::Rule};
|
use crate::{context::LintContext, rule::Rule};
|
||||||
|
|
||||||
|
|
@ -56,33 +57,31 @@ impl Rule for NoRedeclare {
|
||||||
Self { built_in_globals }
|
Self { built_in_globals }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_once(&self, ctx: &LintContext) {
|
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext) {
|
||||||
let symbol_table = ctx.semantic().symbols();
|
let symbol_table = ctx.semantic().symbols();
|
||||||
|
let decl_node_id = symbol_table.get_declaration(symbol_id);
|
||||||
for symbol_id in ctx.symbols().iter() {
|
match ctx.nodes().kind(decl_node_id) {
|
||||||
let decl = symbol_table.get_declaration(symbol_id);
|
AstKind::VariableDeclarator(var) => {
|
||||||
let symbol_name = symbol_table.get_name(symbol_id);
|
if let BindingPatternKind::BindingIdentifier(ident) = &var.id.kind {
|
||||||
match ctx.nodes().kind(decl) {
|
let symbol_name = symbol_table.get_name(symbol_id);
|
||||||
AstKind::VariableDeclarator(var) => {
|
if symbol_name == ident.name.as_str() {
|
||||||
if let BindingPatternKind::BindingIdentifier(ident) = &var.id.kind {
|
for span in ctx.symbols().get_redeclarations(symbol_id) {
|
||||||
if symbol_name == ident.name.as_str() {
|
self.report_diagnostic(ctx, *span, ident);
|
||||||
for span in ctx.symbols().get_redeclarations(symbol_id) {
|
|
||||||
self.report_diagnostic(ctx, *span, ident);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AstKind::FormalParameter(param) => {
|
|
||||||
if let BindingPatternKind::BindingIdentifier(ident) = ¶m.pattern.kind {
|
|
||||||
if symbol_name == ident.name.as_str() {
|
|
||||||
for span in ctx.symbols().get_redeclarations(symbol_id) {
|
|
||||||
self.report_diagnostic(ctx, *span, ident);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
AstKind::FormalParameter(param) => {
|
||||||
|
if let BindingPatternKind::BindingIdentifier(ident) = ¶m.pattern.kind {
|
||||||
|
let symbol_name = symbol_table.get_name(symbol_id);
|
||||||
|
if symbol_name == ident.name.as_str() {
|
||||||
|
for span in ctx.symbols().get_redeclarations(symbol_id) {
|
||||||
|
self.report_diagnostic(ctx, *span, ident);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue