Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 4 additions & 7 deletions crates/oxc_linter/src/rules/node/no_new_require.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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));
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_linter/src/snapshots/node_no_new_require.snap
Original file line number Diff line number Diff line change
@@ -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
Loading