Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(linter): no_shadow_restricted_names only look up name in hashmap once #4472

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 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,18 +36,15 @@ 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| {
let name = ctx.symbols().get_name(symbol_id);

if !PRE_DEFINE_VAR.contains_key(name) {
return;
}

if name == "undefined" {
// Allow to declare `undefined` variable but not allow to assign value to it.
let node_id = ctx.semantic().symbols().get_declaration(symbol_id);
Expand All @@ -63,9 +60,11 @@ 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);
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
Loading