Skip to content

Commit

Permalink
perf(linter): no_shadow_restricted_names only look up name in hashm…
Browse files Browse the repository at this point in the history
…ap once
  • Loading branch information
overlookmotel committed Jul 25, 2024
1 parent 6b39374 commit a6cbaea
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ declare_oxc_lint!(
correctness
);

#[inline]
fn check_and_diagnostic(s: &str, span: Span, ctx: &LintContext) {
if PRE_DEFINE_VAR.contains_key(s) {
ctx.diagnostic(no_shadow_restricted_names_diagnostic(s, span));
}
}

impl Rule for NoShadowRestrictedNames {
fn run_once(&self, ctx: &LintContext<'_>) {
ctx.symbols().iter().for_each(|symbol_id| {
Expand All @@ -63,9 +56,13 @@ impl Rule for NoShadowRestrictedNames {
}
}

check_and_diagnostic(name, ctx.symbols().get_span(symbol_id), ctx);
for span in ctx.symbols().get_redeclarations(symbol_id) {
check_and_diagnostic(name, *span, ctx);
if PRE_DEFINE_VAR.contains_key(name) {
let span = ctx.symbols().get_span(symbol_id);
ctx.diagnostic(no_shadow_restricted_names_diagnostic(name, span));

for &span in ctx.symbols().get_redeclarations(symbol_id) {
ctx.diagnostic(no_shadow_restricted_names_diagnostic(name, span));
}
}
});
}
Expand Down

0 comments on commit a6cbaea

Please sign in to comment.