Skip to content

Commit 29f38f8

Browse files
committed
✨ add eslint rules for node
1 parent 4bc8ad4 commit 29f38f8

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

eslint-config-node/base.yaml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,49 @@
11
extends:
2-
- 'plugin:@shopify/node'
2+
- 'plugin:n/recommended-module'
3+
4+
env:
5+
node: true
6+
7+
# plugin:n/recommended-module disables some globals we still want
8+
globals:
9+
__dirname: 'readonly'
10+
__filename: 'readonly'
11+
require: 'readonly'
312

413
rules:
14+
# node has a consistent radix for parseInt
515
radix: 'off'
6-
node/exports-style: 'warn'
7-
no-console: 'error' # this is a dupe from the base config, but shopify overrides it
16+
# we should be reading any env config into a specific config module
17+
n/no-process-env: 'error'
18+
# Enforce return upon a callback
19+
n/callback-return: ['error', ['callback', 'cb', 'next']]
20+
# Disallow require() outside of the top-level module scope
21+
n/global-require: 'error'
22+
# Enforces error handling in callbacks
23+
n/handle-callback-err: ['error', '^.*[eE]rr(or)?$']
24+
# Disallow mixing regular variable and require declarations
25+
n/no-mixed-requires: 'error'
26+
# Disallow use of new operator with the require function
27+
n/no-new-require: 'error'
28+
# Disallow string concatenation with __dirname and __filename
29+
n/no-path-concat: 'error'
30+
# Restrict usage of specified node modules
31+
n/no-restricted-import: 'off'
32+
n/no-restricted-require: 'off'
33+
# Disallow use of synchronous methods
34+
n/no-sync: 'error'
35+
# defer to import/no-extraneous-dependencies
36+
n/no-extraneous-import: 'off'
37+
n/no-extraneous-require: 'off'
38+
# use `module.exports` for commonjs
39+
n/exports-style: ['error', 'module.exports']
40+
# use imports instead of globals
41+
n/prefer-global/text-decoder: 'never'
42+
n/prefer-global/text-encoder: 'never'
43+
n/prefer-global/url-search-params: 'never'
44+
n/prefer-global/url: 'never'
45+
# use promise APIs
46+
n/prefer-promises/dns: 'error'
47+
n/prefer-promises/fs: 'error'
48+
# make sure callbacks pass error as 1st param
49+
node/no-callback-literal: 'error'

eslint-config-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test": "node --require ts-node/register --test test/index.ts"
2121
},
2222
"dependencies": {
23-
"@shopify/eslint-plugin": "^43.0.0"
23+
"eslint-plugin-n": "^16.1.0"
2424
},
2525
"peerDependencies": {
2626
"@dudeofawesome/eslint-config": "^1.3.0",

0 commit comments

Comments
 (0)