-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eslintrc.js
326 lines (275 loc) · 9.36 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
const jsGlobs = ['**/*.?([cm])js', '**/*.js?(x)'];
const tsGlobs = ['**/*.?([cm])ts', '**/*.ts?(x)'];
const jsTsGlobs = [...jsGlobs, ...tsGlobs];
module.exports = {
ignorePatterns: ['node_modules', 'dist', 'coverage', '**/*.d.ts', '!.*.js', '!.*.cjs', '!.*.mjs'],
// warn on unused eslint disable directives
reportUnusedDisableDirectives: true,
extends: ['airbnb-base', 'airbnb-typescript/base'],
settings: {
'import/resolver': {
'babel-module': {},
},
},
rules: {
// set up naming convention rules
'@typescript-eslint/naming-convention': [
'error',
// allow parameters and variables to be named "Model"
{
selector: ['parameter', 'variable'],
filter: { regex: '^Model$', match: true },
format: ['PascalCase'],
},
// camelCase for everything not otherwise indicated
{ selector: 'default', format: ['camelCase'] },
// allow any naming convention for imports
{ selector: 'import', format: null },
// allow known default exclusions
{ selector: 'default', filter: { regex: '^(_id|__v|_raw)$', match: true }, format: null },
// allow variables to be camelCase or UPPER_CASE
{ selector: 'variable', format: ['camelCase', 'UPPER_CASE'] },
// allow known variable exclusions
{
selector: 'variable',
filter: { regex: '^(_id|__v|_raw)$', match: true },
format: null,
},
// do not enforce format on property names
{ selector: 'property', format: null },
// PascalCase for classes and TypeScript keywords
{
selector: ['typeLike'],
format: ['PascalCase'],
},
],
},
overrides: [
{
files: tsGlobs,
rules: {
// enforce return types on module boundaries
'@typescript-eslint/explicit-module-boundary-types': 'error',
},
},
{
files: ['**/types/*.ts'],
rules: {
'import/prefer-default-export': 'off',
'import/no-default-export': 'error',
},
},
{
files: jsTsGlobs,
extends: [
'plugin:jest/recommended',
'plugin:jest/style',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/stylistic',
'plugin:import/typescript',
'prettier',
],
parserOptions: { project: true },
env: { es2021: true, node: true, 'jest/globals': true },
plugins: ['jest'],
rules: {
// enforce curly brace usage
curly: ['error', 'all'],
// allow class methods which do not use this
'class-methods-use-this': 'off',
// Allow use of ForOfStatement - no-restricted-syntax does not allow us to turn off a rule. This block overrides the airbnb rule entirely
// https://github.com/airbnb/javascript/blob/7152396219e290426a03e47837e53af6bcd36bbe/packages/eslint-config-airbnb-base/rules/style.js#L257-L263
'no-restricted-syntax': [
'error',
{
selector: 'ForInStatement',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'LabeledStatement',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
// underscore dangle will be handled by @typescript-eslint/naming-convention
'no-underscore-dangle': 'off',
// enforce consistent sort order
'sort-imports': ['error', { ignoreCase: true, ignoreDeclarationSort: true }],
// disable import/no-cycle due to performance reasons; dpdm will validate this in CI
'import/no-cycle': 'off',
// enforce convention in import order
'import/order': [
'error',
{
'newlines-between': 'never',
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
alphabetize: { order: 'asc', caseInsensitive: true },
},
],
// ensure consistent array typings
'@typescript-eslint/array-type': 'error',
// prefer type imports and exports
'@typescript-eslint/consistent-type-exports': [
'error',
{ fixMixedExportsWithInlineTypeSpecifier: true },
],
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
// enforce consistent order of class members
'@typescript-eslint/member-ordering': 'error',
// ensure unused variables are treated as an error
// overrides @typescript-eslint/recommended -- '@typescript-eslint/no-unused-vars': 'warn'
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended.ts
'@typescript-eslint/no-unused-vars': 'error',
// disallow parameter properties in favor of explicit class declarations
'@typescript-eslint/parameter-properties': 'error',
},
},
{
files: tsGlobs,
extends: [
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
],
rules: {
// ban ts-comment except with description
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': { descriptionFormat: '^: ' },
'ts-ignore': true,
'ts-nocheck': true,
'ts-check': false,
},
],
// disable rules turned on by @typescript-eslint/recommended-type-checked which are too noisy
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended-type-checked.ts
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/unbound-method': 'off',
// force explicit member accessibility modifiers
'@typescript-eslint/explicit-member-accessibility': 'error',
// ban non-null assertions
'@typescript-eslint/no-non-null-assertion': 'error',
// override @typescript-eslint/stylistic-type-checked to ignore booleans in nullish coalescing checks
// https://typescript-eslint.io/rules/prefer-nullish-coalescing#ignoreprimitives
'@typescript-eslint/prefer-nullish-coalescing': [
'error',
{ ignorePrimitives: { boolean: true } },
],
// disallow boolean comparisons against non-boolean values
'@typescript-eslint/strict-boolean-expressions': ['error', { allowNullableBoolean: true }],
},
},
{
files: jsGlobs,
rules: {
// allow ts-nocheck in js files
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': 'allow-with-description',
'ts-ignore': 'allow-with-description',
'ts-nocheck': false,
'ts-check': false,
},
],
},
},
{
files: ['**/index.[jt]s?(x)'],
rules: {
// prefer named exports for certain file types
'import/prefer-default-export': 'off',
'import/no-default-export': 'error',
},
},
{
files: [
'**/test/**/*.[jt]s?(x)',
'**/__tests__/**/*.[jt]s?(x)',
'**/?(*.)+(spec|test).[jt]s?(x)',
],
rules: {
// allow tests to create multiple classes
'max-classes-per-file': 'off',
// allow side effect constructors
'no-new': 'off',
// allow import with CommonJS export
'import/no-import-module-exports': 'off',
// allow dev dependencies
'import/no-extraneous-dependencies': [
'error',
{ devDependencies: true, optionalDependencies: false, peerDependencies: false },
],
// disallow use of "it" for test blocks
'jest/consistent-test-it': ['error', { fn: 'test', withinDescribe: 'test' }],
// ensure all tests contain an assertion
'jest/expect-expect': 'error',
// no commented out tests
'jest/no-commented-out-tests': 'error',
// no duplicate test hooks
'jest/no-duplicate-hooks': 'error',
// valid titles
'jest/valid-title': 'error',
// no conditionals in tests
'jest/no-conditional-in-test': 'error',
// expect statements in test blocks
'jest/no-standalone-expect': 'error',
// disallow returning from test
'jest/no-test-return-statement': 'error',
// disallow truthy and falsy in tests
'jest/no-restricted-matchers': ['error', { toBeFalsy: null, toBeTruthy: null }],
// prefer called with
'jest/prefer-called-with': 'error',
},
},
{
files: ['**/test/**/*.ts?(x)', '**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'],
rules: {
// allow explicit any in tests
'@typescript-eslint/no-explicit-any': 'off',
// allow non-null-assertions
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
{
files: ['./.*.?(c|m)js', './*.?(c|m)js'],
rules: {
// allow requires in config files
'@typescript-eslint/no-var-requires': 'off',
// allow dev dependencies in config files
'import/no-extraneous-dependencies': [
'error',
{ devDependencies: true, optionalDependencies: false, peerDependencies: false },
],
},
},
{
files: ['./.*.js', './*.js', './website/**/*.js'],
rules: {
// allow requires in config files
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['**/scripts/**'],
rules: {
// allow dev dependencies
'import/no-extraneous-dependencies': [
'error',
{ devDependencies: true, optionalDependencies: false, peerDependencies: false },
],
},
},
],
};