mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
perf(linter): eslint/no_shadow_restricted_names use run_on_symbol (#5618)
This rule was implemented as a `run_once` method which just iterated over symbols. Implement using `run_on_symbol` instead to avoid the additional iteration.
This commit is contained in:
parent
0b7fccf000
commit
37e922c00f
1 changed files with 23 additions and 24 deletions
|
|
@ -2,6 +2,7 @@ use oxc_ast::AstKind;
|
||||||
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, globals::PRE_DEFINE_VAR, rule::Rule};
|
use crate::{context::LintContext, globals::PRE_DEFINE_VAR, rule::Rule};
|
||||||
|
|
||||||
|
|
@ -37,8 +38,7 @@ declare_oxc_lint!(
|
||||||
);
|
);
|
||||||
|
|
||||||
impl Rule for NoShadowRestrictedNames {
|
impl Rule for NoShadowRestrictedNames {
|
||||||
fn run_once(&self, ctx: &LintContext<'_>) {
|
fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) {
|
||||||
ctx.symbols().iter().for_each(|symbol_id| {
|
|
||||||
let name = ctx.symbols().get_name(symbol_id);
|
let name = ctx.symbols().get_name(symbol_id);
|
||||||
|
|
||||||
if !PRE_DEFINE_VAR.contains_key(name) {
|
if !PRE_DEFINE_VAR.contains_key(name) {
|
||||||
|
|
@ -66,7 +66,6 @@ impl Rule for NoShadowRestrictedNames {
|
||||||
for &span in ctx.symbols().get_redeclarations(symbol_id) {
|
for &span in ctx.symbols().get_redeclarations(symbol_id) {
|
||||||
ctx.diagnostic(no_shadow_restricted_names_diagnostic(name, span));
|
ctx.diagnostic(no_shadow_restricted_names_diagnostic(name, span));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue