Skip to content

Commit 54b001f

Browse files
committed
refactor(linter/no-new-require): improve diagnostic message clarity (#14511)
1 parent ea3f362 commit 54b001f

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

crates/oxc_linter/src/rules/node/no_new_require.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use oxc_span::Span;
66
use crate::{AstNode, context::LintContext, rule::Rule};
77

88
fn no_new_require(span: Span) -> OxcDiagnostic {
9-
OxcDiagnostic::warn("Unexpected use of new with require")
9+
OxcDiagnostic::warn("Unexpected use of `new` operator with `require`")
10+
.with_help("Separate `require()` from `new` operator")
1011
.with_label(span)
11-
.with_help("Initialise the constructor separate from the import statement")
1212
}
1313

1414
#[derive(Debug, Default, Clone)]
@@ -46,12 +46,9 @@ impl Rule for NoNewRequire {
4646
let AstKind::NewExpression(new_expression) = node.kind() else {
4747
return;
4848
};
49-
50-
if !new_expression.callee.is_specific_id("require") {
51-
return;
49+
if new_expression.callee.is_specific_id("require") {
50+
ctx.diagnostic(no_new_require(new_expression.span));
5251
}
53-
54-
ctx.diagnostic(no_new_require(new_expression.span));
5552
}
5653
}
5754

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
22
source: crates/oxc_linter/src/tester.rs
33
---
4-
eslint-plugin-node(no-new-require): Unexpected use of new with require
4+
eslint-plugin-node(no-new-require): Unexpected use of `new` operator with `require`
55
╭─[no_new_require.tsx:1:17]
66
1var appHeader = new require('app-header')
77
· ─────────────────────────
88
╰────
9-
help: Initialise the constructor separate from the import statement
9+
help: Separate `require()` from `new` operator
1010

11-
eslint-plugin-node(no-new-require): Unexpected use of new with require
11+
eslint-plugin-node(no-new-require): Unexpected use of `new` operator with `require`
1212
╭─[no_new_require.tsx:1:17]
1313
1var appHeader = new require('headers').appHeader
1414
· ──────────────────────
1515
╰────
16-
help: Initialise the constructor separate from the import statement
16+
help: Separate `require()` from `new` operator

0 commit comments

Comments
 (0)