-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eslintrc.cjs
414 lines (376 loc) · 15.1 KB
/
.eslintrc.cjs
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/* eslint-disable prettier/prettier, @typescript-eslint/no-var-requires, import/extensions */
const {
rules: baseBestPracticesRules,
} = require('eslint-config-airbnb-base/rules/best-practices');
const {
rules: baseErrorsRules,
} = require('eslint-config-airbnb-base/rules/errors');
const { rules: baseES6Rules } = require('eslint-config-airbnb-base/rules/es6');
const {
rules: baseImportsRules,
} = require('eslint-config-airbnb-base/rules/imports');
const {
rules: baseStyleRules,
} = require('eslint-config-airbnb-base/rules/style');
const {
rules: baseVariablesRules,
} = require('eslint-config-airbnb-base/rules/variables');
/* eslint-enable */
const plugins = [
'@typescript-eslint',
'eslint-comments',
'promise',
'unicorn',
'ava',
];
const extendsModules = [
'plugin:prettier/recommended',
'eslint-config-airbnb-base',
'plugin:@typescript-eslint/recommended',
'plugin:eslint-comments/recommended',
'plugin:promise/recommended',
'prettier',
];
const settings = {
// Apply special parsing for TypeScript files
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'],
},
// Append 'ts' extensions to Airbnb 'import/resolver' setting
'import/resolver': {
node: {
extensions: ['.mjs', '.js', '.ts', '.json'],
},
},
// Append 'ts' extensions to Airbnb 'import/extensions' setting
'import/extensions': ['.js', '.ts', '.mjs'],
};
const env = {
node: true,
browser: true,
};
const rules = {
'no-console': 'off',
// Replace Airbnb 'brace-style' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/brace-style.md
'brace-style': 'off',
'@typescript-eslint/brace-style': 'off', // off because this conflicts with prettier brace rules
// Replace Airbnb 'camelcase' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/camelcase.md
camelcase: 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['camelCase'],
},
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
},
{
selector: 'parameter',
format: ['camelCase', 'PascalCase'],
},
{
selector: 'typeLike',
format: ['PascalCase'],
},
{
selector: 'classProperty',
format: ['camelCase'],
},
{
selector: 'objectLiteralProperty',
format: null,
},
{
selector: 'typeProperty',
format: null,
},
{
selector: 'enum',
format: ['PascalCase', 'UPPER_CASE'],
},
{
selector: 'enumMember',
format: null,
},
],
// Replace Airbnb 'comma-spacing' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/comma-spacing.md
'comma-spacing': 'off',
'@typescript-eslint/comma-spacing': baseStyleRules['comma-spacing'],
// Replace Airbnb 'func-call-spacing' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/func-call-spacing.md
'func-call-spacing': 'off',
'@typescript-eslint/func-call-spacing': baseStyleRules['func-call-spacing'],
// Disable typescript indent since prettier covers this
indent: 'off',
'@typescript-eslint/indent': 'off',
// Replace Airbnb 'no-array-constructor' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-array-constructor.md
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor':
baseStyleRules['no-array-constructor'],
// Replace Airbnb 'no-dupe-class-members' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-dupe-class-members.md
'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members':
baseES6Rules['no-dupe-class-members'],
// Replace Airbnb 'no-empty-function' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-function.md
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function':
baseBestPracticesRules['no-empty-function'],
// Replace Airbnb 'no-extra-parens' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-parens.md
'no-extra-parens': 'off',
'@typescript-eslint/no-extra-parens': baseErrorsRules['no-extra-parens'],
// Replace Airbnb 'no-extra-semi' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-semi.md
'no-extra-semi': 'off',
'@typescript-eslint/no-extra-semi': baseErrorsRules['no-extra-semi'],
// Replace Airbnb 'no-implied-eval' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-implied-eval.md
'no-implied-eval': 'off',
'@typescript-eslint/no-implied-eval':
baseBestPracticesRules['no-implied-eval'],
// Replace Airbnb 'no-magic-numbers' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-magic-numbers.md
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers':
baseBestPracticesRules['no-magic-numbers'],
// Replace Airbnb 'no-throw-literal' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-throw-literal.md
'no-throw-literal': 'off',
'@typescript-eslint/no-throw-literal':
baseBestPracticesRules['no-throw-literal'],
// Replace Airbnb 'no-unused-expressions' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-expressions.md
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions':
baseBestPracticesRules['no-unused-expressions'],
// Replace Airbnb 'no-unused-vars' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': baseVariablesRules['no-unused-vars'],
// Replace Airbnb 'no-use-before-define' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define':
baseVariablesRules['no-use-before-define'],
// Replace Airbnb 'no-useless-constructor' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-useless-constructor.md
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor':
baseES6Rules['no-useless-constructor'],
// Replace Airbnb 'quotes' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/quotes.md
quotes: 'off',
'@typescript-eslint/quotes': baseStyleRules.quotes,
// Replace Airbnb 'semi' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/semi.md
semi: 'off',
'@typescript-eslint/semi': baseStyleRules.semi,
// Replace Airbnb 'space-before-function-paren' rule with '@typescript-eslint' version
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/space-before-function-paren.md
'space-before-function-paren': 'off',
'@typescript-eslint/space-before-function-paren':
baseStyleRules['space-before-function-paren'],
// Append 'ts' and 'tsx' extensions to Airbnb 'import/no-extraneous-dependencies' rule
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
'import/no-extraneous-dependencies': [
baseImportsRules['import/no-extraneous-dependencies'][0],
{
...baseImportsRules['import/no-extraneous-dependencies'][1],
devDependencies: baseImportsRules[
'import/no-extraneous-dependencies'
][1].devDependencies.map((glob) =>
glob.replace('js,jsx', 'js,jsx,ts,tsx'),
),
},
],
// Too restrictive, writing ugly code to defend against a very unlikely scenario: https://eslint.org/docs/rules/no-prototype-builtins
'no-prototype-builtins': 'off',
// https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
'import/prefer-default-export': 'off',
'import/no-default-export': 'error',
// Makes no sense to allow type inferrence for expression parameters, but require typing the response
'@typescript-eslint/explicit-function-return-type': [
'error',
{ allowExpressions: true, allowTypedFunctionExpressions: true },
],
'@typescript-eslint/no-explicit-any': 'off',
'class-methods-use-this': 'off',
'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.',
},
],
// sometimes these are much clearer than if else blocks
'no-nested-ternary': 'off',
// avoid unknown horrors
complexity: ['warn', { max: 9 }],
// enforce kebab case filenames
'unicorn/filename-case': [
'error',
{
case: 'kebabCase',
},
],
'no-underscore-dangle': [
'error',
{
enforceInMethodNames: true,
allowFunctionParams: false,
},
],
// with ts 4.x we need to disable the base rule which incorrectly errors on export enum
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error'],
/*
The "smart" option enforces the use of === and !== except for these cases:
* Comparing two literal values
* Evaluating the value of typeof
* Comparing against null
*/
eqeqeq: ['error', 'smart'],
/*
In many cases the iterations of a loop are not actually independent of each-other. For example, the output of one
iteration might be used as the input to another. Or, loops may be used to retry asynchronous operations that were
unsuccessful. Or, loops may be used to prevent your code from sending an excessive amount of requests in parallel.
*/
'no-await-in-loop': 'off',
// require specifying the file extension when importing from a different file type
// this allows babel to replace the filename on imports/exports with the target file extension
'import/extensions': ['error', 'never', { js: 'always', json: 'always' }],
};
const overrides = [
{
files: ['**/*.test.ts', '**/__mocks__/**/*.ts', '**/__mocks__/*.ts'],
rules: {
'no-underscore-dangle': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'ava/assertion-arguments': 'error',
'ava/hooks-order': 'error',
'ava/max-asserts': ['off', 5],
'ava/no-async-fn-without-await': 'error',
'ava/no-duplicate-modifiers': 'error',
'ava/no-identical-title': 'error',
'ava/no-import-test-files': 'error',
'ava/no-incorrect-deep-equal': 'error',
'ava/no-inline-assertions': 'error',
'ava/no-nested-tests': 'error',
'ava/no-only-test': 'error',
'ava/no-skip-assert': 'error',
'ava/no-skip-test': 'error',
'ava/no-todo-implementation': 'error',
'ava/no-todo-test': 'warn',
'ava/no-unknown-modifiers': 'error',
'ava/prefer-async-await': 'error',
'ava/prefer-power-assert': 'off',
'ava/prefer-t-regex': 'error',
'ava/test-title': 'error',
'ava/test-title-format': 'off',
'ava/use-t': 'error',
'ava/use-t-throws-async-well': 'error',
'ava/use-t-well': 'error',
'ava/use-test': 'error',
'ava/use-true-false': 'error',
},
},
{
files: ['./*.cjs'],
rules: {
'import/no-extraneous-dependencies': 'off',
},
},
{
files: ['*.ts'],
rules: {
// Disable `no-undef` rule within TypeScript files because it incorrectly errors when exporting default interfaces
// https://github.com/iamturns/eslint-config-airbnb-typescript/issues/50
// This will be caught by TypeScript compiler if `strictNullChecks` (or `strict`) is enabled
'no-undef': 'off',
/* Using TypeScript makes it safe enough to disable the checks below */
// Disable ESLint-based module resolution check for improved monorepo support
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
'import/no-unresolved': 'off',
},
},
{
files: ['**/*.js'],
extends: [
'plugin:prettier/recommended',
'eslint-config-airbnb-base',
'plugin:eslint-comments/recommended',
'plugin:promise/recommended',
'prettier',
],
rules: {
// Disable indent since prettier covers this
indent: 'off',
// Too restrictive, writing ugly code to defend against a very unlikely scenario: https://eslint.org/docs/rules/no-prototype-builtins
'no-prototype-builtins': 'off',
// https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
'import/prefer-default-export': 'off',
'import/no-default-export': 'error',
'class-methods-use-this': 'off',
'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.',
},
],
},
},
];
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig-lint.json', './tsconfig.json'],
tsconfigRootDir: __dirname,
extraFileExtensions: ['.mjs', 'cjs'],
},
extends: extendsModules,
plugins,
ignorePatterns: [
'node_modules/',
'generator/',
'**/node_modules/**',
'**/dist/**',
'**/coverage/**',
'.vscode/',
'packages/full/src/main/schema.ts', // ignore the compiled json schema
],
rules,
overrides,
settings,
env,
};