File tree Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ use oxc_span::Span;
66use crate :: { AstNode , context:: LintContext , rule:: Rule } ;
77
88fn 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
Original file line number Diff line number Diff line change 11-- -
22source : 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 1 │ var 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 1 │ var appHeader = new require (' headers' ).appHeader
1414 · ──────────────────────
1515 ╰────
16- help : Initialise the constructor separate from the import statement
16+ help : Separate ` require() ` from ` new ` operator
You can’t perform that action at this time.
0 commit comments