diff --git a/crates/oxc_linter/src/rules/node/no_new_require.rs b/crates/oxc_linter/src/rules/node/no_new_require.rs index 20c08cacda814..7f8bcd8c76bf2 100644 --- a/crates/oxc_linter/src/rules/node/no_new_require.rs +++ b/crates/oxc_linter/src/rules/node/no_new_require.rs @@ -6,9 +6,9 @@ use oxc_span::Span; use crate::{AstNode, context::LintContext, rule::Rule}; fn no_new_require(span: Span) -> OxcDiagnostic { - OxcDiagnostic::warn("Unexpected use of new with require") + OxcDiagnostic::warn("Unexpected use of `new` operator with `require`") + .with_help("Separate `require()` from `new` operator") .with_label(span) - .with_help("Initialise the constructor separate from the import statement") } #[derive(Debug, Default, Clone)] @@ -46,12 +46,9 @@ impl Rule for NoNewRequire { let AstKind::NewExpression(new_expression) = node.kind() else { return; }; - - if !new_expression.callee.is_specific_id("require") { - return; + if new_expression.callee.is_specific_id("require") { + ctx.diagnostic(no_new_require(new_expression.span)); } - - ctx.diagnostic(no_new_require(new_expression.span)); } } diff --git a/crates/oxc_linter/src/snapshots/node_no_new_require.snap b/crates/oxc_linter/src/snapshots/node_no_new_require.snap index 43ea431319597..29106e361c353 100644 --- a/crates/oxc_linter/src/snapshots/node_no_new_require.snap +++ b/crates/oxc_linter/src/snapshots/node_no_new_require.snap @@ -1,16 +1,16 @@ --- source: crates/oxc_linter/src/tester.rs --- - ⚠ eslint-plugin-node(no-new-require): Unexpected use of new with require + ⚠ eslint-plugin-node(no-new-require): Unexpected use of `new` operator with `require` ╭─[no_new_require.tsx:1:17] 1 │ var appHeader = new require('app-header') · ───────────────────────── ╰──── - help: Initialise the constructor separate from the import statement + help: Separate `require()` from `new` operator - ⚠ eslint-plugin-node(no-new-require): Unexpected use of new with require + ⚠ eslint-plugin-node(no-new-require): Unexpected use of `new` operator with `require` ╭─[no_new_require.tsx:1:17] 1 │ var appHeader = new require('headers').appHeader · ────────────────────── ╰──── - help: Initialise the constructor separate from the import statement + help: Separate `require()` from `new` operator