-
-
Notifications
You must be signed in to change notification settings - Fork 788
feat(linter): add eslint-plugin-import/no-nodejs-modules rule
#18006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements the eslint-plugin-import/no-nodejs-modules rule to forbid the use of Node.js builtin modules in client-side projects. The rule detects imports of Node.js builtin modules through various syntax patterns including ES6 imports, CommonJS require calls, dynamic imports, TypeScript import equals declarations, and export declarations.
Changes:
- Adds a new lint rule
no-nodejs-moduleswith configurable allow list for exceptions - Supports detection across multiple import patterns:
import,require(), dynamicimport(), TSimport = require(), andexportdeclarations - Handles both bare module names (
"fs") and Node.js protocol syntax ("node:fs")
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/oxc_linter/src/rules/import/no_nodejs_modules.rs | Core implementation of the rule with comprehensive test coverage |
| crates/oxc_linter/src/rules.rs | Registers the new rule in the linter |
| crates/oxc_linter/src/generated/rule_runner_impls.rs | Auto-generated rule runner implementation specifying AST node types to check |
| crates/oxc_linter/src/snapshots/import_no_nodejs_modules.snap | Test snapshots showing expected diagnostic output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| AstKind::ImportExpression(import) => match &import.source { | ||
| Expression::StringLiteral(str_lit) => Some(str_lit.value), | ||
| _ => None, | ||
| }, |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ImportExpression handler only checks for StringLiteral sources. Template literals without substitutions (e.g., import(\fs`)) should also be checked for Node.js modules, similar to how no_dynamic_requirehandles them. Consider adding support forExpression::TemplateLiteralwhenis_no_substitution_template()` returns true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 17098a4
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
this PR adds
eslint-plugin-import/no-nodejs-modulesrule, passes all tests + some new, like TS import equals or export declarationsissue #1117, also #15208