diff --git a/crates/oxc_linter/src/generated/rule_runner_impls.rs b/crates/oxc_linter/src/generated/rule_runner_impls.rs index f5c04b9c92ab1..3650f410b5c10 100644 --- a/crates/oxc_linter/src/generated/rule_runner_impls.rs +++ b/crates/oxc_linter/src/generated/rule_runner_impls.rs @@ -428,7 +428,8 @@ impl RuleRunner for crate::rules::eslint::no_nonoctal_decimal_escape::NoNonoctal } impl RuleRunner for crate::rules::eslint::no_obj_calls::NoObjCalls { - const NODE_TYPES: Option<&AstTypesBitset> = None; + const NODE_TYPES: Option<&AstTypesBitset> = + Some(&AstTypesBitset::from_types(&[AstType::CallExpression, AstType::NewExpression])); } impl RuleRunner for crate::rules::eslint::no_object_constructor::NoObjectConstructor { diff --git a/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs b/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs index 438faacd5d561..a37f2d9bd007d 100644 --- a/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs +++ b/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs @@ -126,35 +126,34 @@ fn resolve_global_binding<'a, 'b: 'a>( impl Rule for NoObjCalls { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - let (callee, span) = match node.kind() { - AstKind::NewExpression(expr) => (&expr.callee, expr.span), - AstKind::CallExpression(expr) => (&expr.callee, expr.span), - _ => return, - }; - - match callee { - Expression::Identifier(ident) => { - // handle new Math(), Math(), etc - if let Some(top_level_reference) = - resolve_global_binding(ident, node.scope_id(), ctx) - && is_global_obj(top_level_reference) - { - ctx.diagnostic(no_obj_calls_diagnostic(ident.name.as_str(), span)); - } - } + match node.kind() { + AstKind::NewExpression(expr) => check_callee(&expr.callee, expr.span, node, ctx), + AstKind::CallExpression(expr) => check_callee(&expr.callee, expr.span, node, ctx), + _ => {} + } + } +} - match_member_expression!(Expression) => { - // handle new globalThis.Math(), globalThis.Math(), etc - if let Some(global_member) = global_this_member(callee.to_member_expression()) - && is_global_obj(global_member) - { - ctx.diagnostic(no_obj_calls_diagnostic(global_member, span)); - } +fn check_callee<'a>(callee: &'a Expression, span: Span, node: &AstNode<'a>, ctx: &LintContext<'a>) { + match callee { + Expression::Identifier(ident) => { + // handle new Math(), Math(), etc + if let Some(top_level_reference) = resolve_global_binding(ident, node.scope_id(), ctx) + && is_global_obj(top_level_reference) + { + ctx.diagnostic(no_obj_calls_diagnostic(ident.name.as_str(), span)); } - _ => { - // noop + } + + match_member_expression!(Expression) => { + // handle new globalThis.Math(), globalThis.Math(), etc + if let Some(global_member) = global_this_member(callee.to_member_expression()) + && is_global_obj(global_member) + { + ctx.diagnostic(no_obj_calls_diagnostic(global_member, span)); } } + _ => {} } }