Skip to content

Commit

Permalink
chore(eslint): require prefixed node builtins
Browse files Browse the repository at this point in the history
This adds a rule which requires all `require()`s or `import`s use the `node:` prefix when requesting builtins.

`node:`-prefixed builtins better illustrate intent and reduce the risk of erroneously pulling in 3rd-party packges.
  • Loading branch information
boneskull committed Mar 11, 2024
1 parent 7c9ae4a commit 13b1476
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Expand Up @@ -51,6 +51,7 @@ module.exports = {
env: { [ECMASCRIPT_ENV]: true, node: true },
// the prettier config disables all eslint rules known to conflict with prettier
extends: ['eslint:recommended', 'plugin:n/recommended', 'prettier'],
plugins: ['node-import'],
rules: {
// base rules; none of these are in eslint/recommended
'no-empty': ['error', { allowEmptyCatch: true }],
Expand Down Expand Up @@ -82,6 +83,9 @@ module.exports = {
// we should probably actually fix these three and turn these back on
'n/no-sync': 'off', // very few reasons to actually use this; "CLI tool" is not one of them
'n/no-process-exit': 'off', // should not be used with async code

// require node: prefix for builtin modules
'node-import/prefer-node-protocol': 'error',
},
settings: {
node: {
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -55,6 +55,7 @@
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsonc": "2.13.0",
"eslint-plugin-n": "16.6.2",
"eslint-plugin-node-import": "1.0.4",
"eslint-plugin-react": "7.34.0",
"glob": "10.3.10",
"husky": "9.0.11",
Expand Down

0 comments on commit 13b1476

Please sign in to comment.