From 2760591c9665e806b705ddcdc491a641cfb16c0a Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Wed, 25 Jun 2025 10:58:45 +0000 Subject: [PATCH] refactor(linter/no-console): early return if ident does not match (#11895) --- .../oxc_linter/src/rules/eslint/no_console.rs | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_console.rs b/crates/oxc_linter/src/rules/eslint/no_console.rs index 0ebac5c9ebba5..175b1ccb1a8b5 100644 --- a/crates/oxc_linter/src/rules/eslint/no_console.rs +++ b/crates/oxc_linter/src/rules/eslint/no_console.rs @@ -111,28 +111,30 @@ impl Rule for NoConsole { return; }; - if ident.name == "console" - && ctx.scoping().root_unresolved_references().contains_key("console") + if ident.name != "console" + || !ctx.scoping().root_unresolved_references().contains_key("console") { - if let Some((mem_span, prop_name)) = member_expr.static_property_info() { - if self.allow.iter().any(|allowed_name| allowed_name == prop_name) { - return; - } + return; + } - let diagnostic_span = ident.span().merge(mem_span); + if let Some((mem_span, prop_name)) = member_expr.static_property_info() { + if self.allow.iter().any(|allowed_name| allowed_name == prop_name) { + return; + } - ctx.diagnostic_with_suggestion( - no_console_diagnostic(diagnostic_span, &self.allow), - |fixer| { - if let Some(parent) = ctx.nodes().parent_node(node.id()) { - if let AstKind::CallExpression(_) = parent.kind() { - return remove_console(fixer, ctx, parent); - } + let diagnostic_span = ident.span().merge(mem_span); + + ctx.diagnostic_with_suggestion( + no_console_diagnostic(diagnostic_span, &self.allow), + |fixer| { + if let Some(parent) = ctx.nodes().parent_node(node.id()) { + if let AstKind::CallExpression(_) = parent.kind() { + return remove_console(fixer, ctx, parent); } - fixer.noop() - }, - ); - } + } + fixer.noop() + }, + ); } } }