feat(linter): add n/global-require rule#17283
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds the n/global-require linter rule from eslint-plugin-n, which enforces that require() calls are placed at top-level module scope. This helps improve code clarity by making dependencies easier to identify and prevents potential performance issues from synchronous loading within functions or conditional statements.
Key Changes:
- Implements the
GlobalRequirerule that detectsrequire()calls not at module scope - Adds comprehensive test cases covering various invalid patterns (functions, conditionals, try-catch, arrow functions)
- Properly handles shadowed
requireidentifiers to avoid false positives
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/node/global_require.rs | Core implementation of the global-require rule with logic to detect non-top-level require() calls |
| crates/oxc_linter/src/snapshots/node_global_require.snap | Snapshot test output showing expected diagnostic messages for various violation patterns |
| crates/oxc_linter/src/rules.rs | Registers the new global_require module in the node plugin section |
| crates/oxc_linter/src/generated/rule_runner_impls.rs | Generated implementation registering the rule to run on CallExpression AST nodes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7fe9586 to
d559fef
Compare
CodSpeed Performance ReportMerging #17283 will not alter performanceComparing Summary
Footnotes
|
this PR adds
n/global-requirerule, issue #493source doc
source code