Skip to content
This repository was archived by the owner on Mar 7, 2019. It is now read-only.

Commit 7b347fd

Browse files
feat: add eslint-plugin-node 💪
1 parent 0aea2c1 commit 7b347fd

File tree

4 files changed

+106
-4
lines changed

4 files changed

+106
-4
lines changed

‎environments/nodejs/recommended.js

+38
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ module.exports = {
2323
node: true,
2424
},
2525

26+
plugins: [
27+
'node',
28+
],
29+
2630
rules: {
2731
// Enforce `require()` on the top-level module scope
2832
// It's arguably harder to identify dependencies when they are deeply nested inside of functions
@@ -67,6 +71,40 @@ module.exports = {
6771
'no-sync': ['warn', {
6872
allowAtRootLevel: true,
6973
}],
74+
75+
// Disallow unsupported ECMAScript features on the specified version
76+
// This rule reports unsupported ECMAScript built-in variables on the configured Node.js version
77+
// as lint errors. This rule reads the engines field of package.json to detect which Node.js
78+
// versions your module is supporting.
79+
'node/no-unsupported-features/es-builtins': 'error',
80+
81+
// Disallow unsupported ECMAScript syntax on the specified version
82+
// This rule reports unsupported ECMAScript syntax on the configured Node.js version as lint
83+
// errors. This rule reads the engines field of package.json to detect which Node.js versions
84+
// your module is supporting.
85+
'node/no-unsupported-features/es-syntax': 'error',
86+
87+
// Disallow unsupported Node.js built-in APIs on the specified version
88+
// This rule reports unsupported Node.js built-in APIs on the configured Node.js version as lint
89+
// errors. This rule reads the engines field of package.json to detect which Node.js versions
90+
// your module is supporting.
91+
'node/no-unsupported-features/node-builtins': 'error',
92+
93+
// Treat process.exit() the same code path as throw
94+
// If you turn this rule on, ESLint comes to address process.exit() as throw in code path
95+
// analysis.
96+
'node/process-exit-as-throw': 'error',
97+
98+
// Suggest correct usage of shebang
99+
// This rule checks bin field of package.json, then if a target file matches one of bin files,
100+
// it checks whether or not there is a correct shebang. Otherwise it checks whether or not there
101+
// is not a shebang.
102+
'node/shebang': 'warn',
103+
104+
// Disallow deprecated API
105+
// Node has many deprecated API. The community is going to remove those API from Node in future,
106+
// so we should not use those.
107+
'node/no-deprecated-api': 'warn',
70108
},
71109

72110
overrides: [{

‎package-lock.json

+31-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"eslint-plugin-import": "^2.14.0",
2020
"eslint-plugin-jsx-a11y": "^6.1.2",
2121
"eslint-plugin-mocha": "^5.2.0",
22+
"eslint-plugin-node": "^8.0.0",
2223
"eslint-plugin-react": "^7.11.1"
2324
},
2425
"devDependencies": {

‎unused.js

+36
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,41 @@ module.exports = {
251251
// Disallow the use of type aliases
252252
// Unused, type aliases seem useful.
253253
'typescript/no-type-alias': 0,
254+
255+
// Disallow import declarations which import extraneous modules
256+
// Unused, already implemented using eslint-plugin-import
257+
'node/no-extraneous-import': 0,
258+
259+
// Disallow require declarations which require extraneous modules
260+
// Unused, already implemented using eslint-plugin-import
261+
'node/no-extraneous-require': 0,
262+
263+
// Disallow import, export and require declarations for files that don't exist
264+
// Unused, already implemented using eslint-plugin-import
265+
'node/no-missing-import': 0,
266+
'node/no-missing-require': 0,
267+
268+
// disallow 'bin' files that npm ignores
269+
// Unused, not very useful and the rule does not work well with compiled files (JSX, Babel etc.)
270+
'node/no-unpublished-bin': 0,
271+
272+
// Disallow import/require declarations which import unpublished files/modules
273+
// Unused, already implemented using eslint-plugin-import
274+
'node/no-unpublished-import': 0,
275+
'node/no-unpublished-require': 0,
276+
277+
// enforce either module.exports or exports
278+
// Unused, implemented in eslint-plugin-import/group-exports
279+
'node/exports-style': 0,
280+
281+
// Prefer global variants of these core modules
282+
// Unused, already being handled by `no-shadow` rule in combination with env: node: true
283+
'node/prefer-global/buffer': 0,
284+
'node/prefer-global/console': 0,
285+
'node/prefer-global/process': 0,
286+
'node/prefer-global/text-decoder': 0,
287+
'node/prefer-global/text-encoder': 0,
288+
'node/prefer-global/url-search-params': 0,
289+
'node/prefer-global/url': 0,
254290
},
255291
}

0 commit comments

Comments
 (0)