-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
220 lines (208 loc) · 7.04 KB
/
.eslintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
module.exports = {
// Dep names: 'eslint-plugin-jest', 'eslint-plugin-react', 'eslint-plugin-react-hooks', 'eslint-plugin-import', '@typescript-eslint/eslint-plugin', '@typescript-eslint/parser', 'eslint-plugin-jsx-a11y', '@babel/eslint-parser'
// REVIEW: React plugins and rules
// REVIEW: TypeScript rules/config (file extensions, plugins, parsers, etc.)
// REVIEW: Make sure all extensions to be linted (other than .js) are covered at some point in the overrides section. This allows ESLint to lint them without passing in the --ext CLI option. @see https://github.com/eslint/rfcs/pull/20/files?short_path=89f153b#diff-89f153b40e57baa60c4da2693bb17305
// REVIEW: jsx-a11y
plugins: ["react-hooks", "import", "jsx-a11y"],
// jsx-a11y: could remove usage, or even move to "plugin:jsx-a11y/strict"
extends: ["plugin:react/recommended", "plugin:jsx-a11y/recommended"],
env: {
es6: true,
node: true,
},
// REVIEW: Remove this if not using babel
parser: "@babel/eslint-parser",
parserOptions: {
// REVIEW: Depending on the browsers supported for the project, this might need to go down. Safari and non-Chromium Edge seem to be the biggest ones to hold things back, but the things they don't support from 2016 onwards are rarely used. Also, this probably isn't necessary if using Babel
// @see https://kangax.github.io/compat-table/es2016plus/
ecmaVersion: 2020,
sourceType: "module",
},
settings: {
react: {
version: "detect",
},
},
// REVIEW: May need to add things based on the project
ignorePatterns: ["dist/", "build/", "coverage/"],
rules: {
/**
* Possible Errors
*
* https://eslint.org/docs/rules/#possible-errors
*/
"no-compare-neg-zero": 2,
"no-cond-assign": 2,
"no-console": [2, { allow: ["error"] }],
"no-constant-condition": 2,
"no-debugger": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty": [2, { allowEmptyCatch: true }],
"no-empty-character-class": 2,
"no-ex-assign": 2,
"no-extra-boolean-cast": 2,
"no-func-assign": 2,
"no-inner-declarations": 2,
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-obj-calls": 2,
"no-regex-spaces": 2,
"no-sparse-arrays": 0,
"no-template-curly-in-string": 2,
"no-unexpected-multiline": 2,
"no-unreachable": 2,
"no-unsafe-finally": 2,
"use-isnan": 2,
"valid-typeof": 2,
eqeqeq: ["error", "always", { null: "ignore" }],
/**
* Best Practices
*
* https://eslint.org/docs/rules/#best-practices
*/
"prefer-regex-literals": 2,
"no-caller": 2,
"no-case-declarations": 2,
"no-empty-pattern": 2,
"no-extend-native": 2,
"no-new-wrappers": 2,
"no-octal": 2,
"no-redeclare": 2,
"no-self-assign": 2,
"no-unused-labels": 2,
"no-var": 2,
/**
* ESLint's "Variables" rules
*
* https://eslint.org/docs/rules/#variables
*/
"no-delete-var": 2,
"no-undef": 2,
"no-unused-vars": [
2,
{
args: "none",
ignoreRestSiblings: true,
},
],
"no-use-before-define": [
2,
{
functions: false,
},
],
/**
* ECMAScript 6
*
* https://eslint.org/docs/rules/#ecmascript-6
*/
"constructor-super": 2,
/**
* React
*/
// REVIEW: Depends on the project (TS, if you care about prop-types, etc.)
"react/prop-types": 0,
/**
* React hooks
*/
"react-hooks/rules-of-hooks": 2,
"react-hooks/exhaustive-deps": 2,
/**
* eslint-plugin-import
*/
// REVIEW: Check to see if the team is OK with this
"import/no-default-export": 2,
},
overrides: [
/**
* Files only ran in the browser. Modify this to point at the client/src directory, depending on the project
*/
{
files: ["client/**/*+(js|jsx|ts|tsx)"],
env: {
jest: true,
node: false,
browser: true,
},
},
/**
* Test files. Node is enabled, since Jest inherently is ran through Node. Browser is enabled because of the simulated browser env that Jest runs tests in.
*/
{
// REVIEW: Jest setup file, test utils, etc. Anything that's not a `spec` file that should be treated in the test env
files: [
"client/**/*.spec.@(js|jsx|ts|tsx)",
"./jest.setup.js",
"client/test-utils/**/*.(js|jsx|ts|tsx)",
],
plugins: ["jest"],
env: {
jest: true,
node: true,
browser: true,
},
rules: {
"jest/no-disabled-tests": 2,
"jest/no-commented-out-tests": 2,
"jest/no-focused-tests": 2,
"jest/no-identical-title": 2,
"jest/no-jasmine-globals": 2,
"jest/no-jest-import": 2,
"jest/no-mocks-import": 2,
"jest/no-standalone-expect": 2,
"jest/no-test-callback": 2,
"jest/no-test-prefixes": 2,
"jest/no-try-expect": 2,
"jest/prefer-to-be-null": 2,
"jest/prefer-to-be-undefined": 2,
"jest/prefer-to-contain": 2,
"jest/prefer-to-have-length": 2,
"jest/prefer-todo": 2,
"jest/valid-describe": 2,
"jest/valid-expect-in-promise": 2,
"jest/valid-expect": 2,
},
},
/**
* TypeScript files.
*/
{
files: ["**/*.@(ts|tsx)"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
},
plugins: ["@typescript-eslint"],
rules: {
// Turn off rules that TypeScript's compiler can/will catch on its own. This is necessary, since this project has a mix of JS and TS files.
// REVIEW: Make sure the TS compiler enforces these rules on its own before committing to turning these ESLint rules off
"no-unused-vars": 0,
"no-use-before-define": 0,
"no-undef": 0,
// `@typescript-eslint` rules. The default recommended rules are a bit picky, and included useless warnings instead of error. So we explicitly choose the ones that could actually help catch bugs, reasonably enforce consistency, or reasonably enforce modern TS
"@typescript-eslint/await-thenable": 2,
"@typescript-eslint/ban-types": 2,
"@typescript-eslint/consistent-type-assertions": 2,
"@typescript-eslint/no-explicit-any": 2,
"@typescript-eslint/no-for-in-array": 2,
"@typescript-eslint/no-inferrable-types": 2,
"@typescript-eslint/no-misused-new": 2,
"@typescript-eslint/no-misused-promises": 2,
"@typescript-eslint/no-namespace": 2,
"@typescript-eslint/no-this-alias": 2,
"@typescript-eslint/no-unnecessary-type-assertion": 2,
"@typescript-eslint/no-var-requires": 2,
"@typescript-eslint/prefer-includes": 2,
"@typescript-eslint/prefer-namespace-keyword": 2,
"@typescript-eslint/prefer-string-starts-ends-with": 2,
"@typescript-eslint/triple-slash-reference": 2,
"@typescript-eslint/unbound-method": 2,
"@typescript-eslint/no-array-constructor": 2,
"@typescript-eslint/require-await": 2,
},
},
],
}