Skip to content

Commit e5c0ce4

Browse files
committed
♻️ decide on base set of eslint rules
1 parent 45d6651 commit e5c0ce4

File tree

14 files changed

+236
-47
lines changed

14 files changed

+236
-47
lines changed

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
}
2323
],
2424
"material-icon-theme.files.associations": {
25-
"eslint-config*/*.yaml": "eslint"
25+
"eslint-config*/**/*.yaml": "eslint"
2626
},
2727
"yaml.schemas": {
28-
"https://json.schemastore.org/eslintrc": ["eslint-config*/*.yaml"]
28+
"https://json.schemastore.org/eslintrc": ["eslint-config*/**/*.yaml"]
2929
}
3030
}

eslint-config/base.yaml

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,19 @@
11
extends:
2-
- 'plugin:@shopify/esnext'
2+
- 'eslint:recommended'
33
- 'plugin:prettier/recommended'
4+
- 'plugin:promise/recommended'
5+
- 'plugin:import/recommended'
6+
7+
- './rules/bugs.yaml'
8+
- './rules/deprecated.yaml'
9+
- './rules/footguns.yaml'
10+
- './rules/imports.yaml'
11+
- './rules/miscellaneous.yaml'
12+
- './rules/modern-code.yaml'
13+
- './rules/promises.yaml'
14+
- './rules/readability.yaml'
15+
- './rules/security.yaml'
16+
417
parserOptions:
518
ecmaVersion: 2022 # Version is inline with Node 16
619
sourceType: 'module'
7-
8-
rules:
9-
'@babel/new-cap': 'off'
10-
id-length: 'off'
11-
import/order:
12-
- 'warn'
13-
- groups:
14-
- 'builtin'
15-
- 'external'
16-
- 'internal'
17-
newlines-between: 'ignore'
18-
import/no-default-export: 'error'
19-
line-comment-position: 'off'
20-
no-empty-function: 'warn'
21-
no-negated-condition: 'off'
22-
no-nested-ternary: 'off'
23-
no-warning-comments: 'off'
24-
prettier/prettier: 'warn'
25-
require-atomic-updates: ['warn', { allowProperties: true }]
26-
sort-class-members/sort-class-members: 'off'
27-
import/extensions: 'off'
28-
no-useless-constructor: 'off'
29-
consistent-return: 'off'
30-
require-await: 'off'
31-
no-shadow: 'off'
32-
promise/no-nesting: 'off'
33-
import/no-cycle: 'off'
34-
lines-between-class-members: 'off'
35-
no-useless-return: 'off'
36-
no-use-before-define: 'off'
37-
eslint-comments/no-use: 'warn'
38-
'@shopify/binary-assignment-parens': 'off'
39-
no-console: 'error'
40-
# TODO: ban barrels

eslint-config/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"@shopify/eslint-plugin": "^43.0.0",
2424
"eslint": "^8.49.0",
2525
"eslint-config-prettier": "^8.5.0",
26-
"eslint-plugin-prettier": "^5.0.0"
26+
"eslint-plugin-import": "^2.28.1",
27+
"eslint-plugin-prettier": "^5.0.0",
28+
"eslint-plugin-promise": "^6.1.1"
2729
},
2830
"peerDependencies": {
2931
"prettier": "^3.0.3"

eslint-config/rules/bugs.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
rules:
2+
# don't compare vars to themselves
3+
no-self-compare: 'error'
4+
5+
# don't use `this` when `this` is `undefined`
6+
no-invalid-this: 'error'
7+
8+
# catch some race conditions
9+
require-atomic-updates: ['warn', { allowProperties: true }]
10+
11+
# don't use `new` keyword when it shouldn't be used
12+
no-new-native-nonconstructor: 'error'
13+
14+
# ensure thrown value extend `Error`
15+
no-throw-literal: 'error'

eslint-config/rules/deprecated.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rules:
2+
# __iterator__ is deprecated
3+
no-iterator: 'error'
4+
5+
# __proto__ is deprecated
6+
no-proto: 'error'
7+
8+
# don't allow var
9+
no-var: 'error'

eslint-config/rules/footguns.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
rules:
2+
# require `parseInt` to have a radix specified since some browsers don't default to base 10
3+
radix: 'error'
4+
5+
# require the use of `===` since `==` has some weird behavior
6+
eqeqeq: ['error', 'smart']
7+
8+
# TODO: ban barrels
9+
# barrel files can lead to a number of hard to debug issues
10+
11+
# prefer binary, octal, and hexadecimal literals instead of parseInt('F', 16)
12+
prefer-numeric-literals: 'error'
13+
14+
# ensure that functional array methods are chainable
15+
array-callback-return: 'error'
16+
17+
# don't return in a constructor
18+
no-constructor-return: 'error'
19+
20+
# don't allow array constructors with multiple params
21+
no-array-constructor: 'error'
22+
23+
# don't use arguments.caller
24+
no-caller: 'error'
25+
26+
# TODO: this is an error by default. should it only be a warn?
27+
# don't allow `delete` since it can have unexpected consequences
28+
no-delete-var: 'warn'
29+
30+
# don't allow monkeypatching
31+
no-extend-native: 'error'
32+
33+
# don't allow sequences
34+
no-sequences: ['error', { allowInParentheses: false }]
35+
36+
# don't allow the void keyword
37+
no-void: 'error'
38+
39+
# ensure regexp uses certain flags
40+
require-unicode-regexp: 'error'
41+
42+
# prevent unintentional numeric literal values (eg: `071 === 51`)
43+
no-octal: 'error'
44+
45+
# prevent labels from sharing name with variable
46+
no-label-var: 'error'

eslint-config/rules/imports.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
rules:
2+
# warn about deprecated imports
3+
import/no-deprecated: 'warn'
4+
5+
# don't export mutable vars
6+
import/no-mutable-exports: 'error'
7+
8+
# don't allow AMD modules
9+
import/no-amd: 'error'
10+
11+
# TODO: can we actually ban this? probably not
12+
# don't allow commonjs modules
13+
import/no-commonjs: 'error'
14+
15+
# don't allow mixing ESM with commonjs exports
16+
import/no-import-module-exports: 'error'
17+
18+
# don't allow importing yourself
19+
import/no-self-import: 'error'
20+
21+
# don't allow webpack imports
22+
import/no-webpack-loader-syntax: 'error'
23+
24+
# ensure imports come first in file
25+
import/first: 'error'
26+
27+
# ensure imports are seperated from the rest of the file
28+
import/newline-after-import: 'error'
29+
30+
# don't allow default exports
31+
import/no-default-export: 'error'
32+
33+
# ensure consistent ordering of imports
34+
import/order:
35+
- 'warn'
36+
- groups:
37+
- 'builtin'
38+
- 'external'
39+
- 'internal'
40+
newlines-between: 'ignore'
41+
42+
# TODO: do I need this?
43+
# Sort import declarations within module
44+
sort-imports: 'off'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
rules:
2+
# prevent `console` and `alert` calls from making it into prod
3+
no-console: 'error'
4+
no-alert: 'error'
5+
6+
# warn about prettier style issues
7+
prettier/prettier: 'warn'
8+
9+
# TODO: do we really want to force a style for comments?
10+
# ensure comments start with a space
11+
spaced-comment: ['error', 'always', { 'block': { 'exceptions': ['-=*'] } }]
12+
13+
# disallow renaming import, export, and destructured assignments to the same name
14+
no-useless-rename: 'error'
15+
16+
# require symbol to have a description
17+
symbol-description: 'error'
18+
19+
# require switch's default case to be last
20+
default-case-last: 'error'

eslint-config/rules/modern-code.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
rules:
2+
# use template literals instead of string concatenation
3+
prefer-template: 'error'
4+
5+
# don't use .apply()
6+
prefer-spread: 'error'
7+
8+
# use `**` instead of `Math.pow`
9+
prefer-exponentiation-operator: 'error'
10+
11+
# use a rest parameter instead of `arguments`
12+
prefer-rest-params: 'error'
13+
14+
# Require method and property shorthand syntax for object literals
15+
object-shorthand: ['error', 'always', { avoidQuotes: true }]
16+
17+
# Suggest using arrow functions as callbacks
18+
prefer-arrow-callback: ['error', { allowNamedFunctions: true }]
19+
20+
# use const for vars that are never modified
21+
prefer-const: 'error'

eslint-config/rules/promises.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
rules:
2+
# TODO: do we actually want this?
3+
# ensure promise errors are caught
4+
promise/catch-or-return: ['error', { allowThen: true }]
5+
6+
# don't call resolve multiple times
7+
promise/no-multiple-resolved: 'error'
8+
9+
# allow nesting promises
10+
promise/no-nesting: 'off'
11+
12+
# allow using promises inside of callbacks
13+
promise/no-promise-in-callback: 'off'
14+
15+
# ensure the proper number of arguments are passed to Promise functions
16+
promise/valid-params: 'error'
17+
18+
# require async functions to contain an await
19+
require-await: 'error'
20+
21+
# prevent synchronous loops (prefering to use `Promise.all`)
22+
no-await-in-loop: 'error'

0 commit comments

Comments
 (0)