-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
.eslintrc
161 lines (138 loc) · 5.23 KB
/
.eslintrc
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
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jsdoc/recommended-typescript-error",
"plugin:jest/recommended",
"plugin:prettier/recommended" // MUST BE LAST!
],
"plugins": [
"@typescript-eslint",
"simple-import-sort",
"jest",
"unicorn"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module"
},
"ignorePatterns": ["dist/**"],
"env": {
"jest/globals": true
},
"rules": {
// ***** Files *****
"unicorn/no-empty-file": "error",
"unicorn/filename-case": ["error", {
"case": "camelCase"
}],
// ***** Imports *****
"unicorn/prefer-node-protocol": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
// ***** JSDoc *****
"jsdoc/require-jsdoc": ["error", {
// Require on public parts of classes
"checkConstructors": false,
"contexts": [
"ClassDeclaration",
// TODO(cemmer): require private methods as well
"MethodDefinition[accessibility!=private][key.name!=/^(get|set|with)[A-Z][a-zA-Z]+/]"
]
}],
"jsdoc/require-param": "off",
"jsdoc/require-returns": "off",
"jsdoc/no-blank-blocks": "error",
// ***** Types *****
"unicorn/no-null": "error",
// ***** Promises *****
// Disallow awaiting a value that is not a Thenable.
"@typescript-eslint/await-thenable": "error",
// Disallow async functions which have no `await` expression.
"@typescript-eslint/require-await": "error",
// Enforce consistent returning of awaited values.
"@typescript-eslint/return-await": "error",
// Require any function or method that returns a Promise to be marked async.
"@typescript-eslint/promise-function-async": ["error"],
// ***** Classes *****
"@typescript-eslint/prefer-readonly": "error",
"unicorn/new-for-builtins": "error",
"unicorn/no-static-only-class": "error",
// ***** Functions *****
// Require explicit return types on functions and class methods.
"@typescript-eslint/explicit-function-return-type": "error",
"unicorn/prefer-default-parameters": "error",
// ***** Errors *****
"unicorn/catch-error-name": "error",
"unicorn/prefer-optional-catch-binding": "error",
// ***** Operands *****
"@typescript-eslint/prefer-nullish-coalescing": "error",
// ***** Conditionals *****
// Don't allow unnecessary conditional checks, such as when a value is always true, which can also help catch cases
// such as accidentally checking `if([]){}` vs. `if([].length){}`
"@typescript-eslint/strict-boolean-expressions": ["error", {
"allowAny": true,
"allowNullableBoolean": true,
"allowNullableString": true
}],
// Don't allow truthy or falsey conditionals on array lengths
"unicorn/explicit-length-check": "error",
// ***** Loops *****
"unicorn/no-for-loop": "error",
// ***** Objects *****
"@typescript-eslint/no-unused-vars": ["error", {
// Allow the use of destructuring to remove keys from an object
"ignoreRestSiblings": true
}],
// ***** Arrays *****
"no-restricted-syntax": ["error", {
"selector": "CallExpression[callee.property.name='push'] > SpreadElement",
"message": "Array#push(...Array) can cause 'call stack size exceeded' runtime errors when pushing many values, prefer 'Array = [...Array, ...Array]'"
}],
"unicorn/no-new-array": "error",
// TypeScript doesn't do a good job of reporting indexed values as potentially undefined, such as `[1,2,3][999]`
"unicorn/prefer-at": "error",
// Try to enforce early terminations of loops, rather than statements such as `.find(x=>x)[0]`
"unicorn/prefer-array-find": ["error", {"checkFromLast": false}],
"unicorn/prefer-array-flat": "error",
"unicorn/prefer-array-flat-map": "error",
"unicorn/prefer-includes": "error",
"unicorn/prefer-object-from-entries": "error",
// ***** Numbers *****
"unicorn/no-zero-fractions": "error",
"unicorn/numeric-separators-style": "error",
"unicorn/prefer-number-properties": "error",
// ***** Strings *****
"unicorn/prefer-code-point": "error",
// ********** Recommended Overrides **********
// ***** eslint:recommended *****
// Referencing ASCII characters <32 is entirely legitimate
"no-control-regex": "off",
// ***** plugin:@typescript-eslint/recommended *****
// There are a few places where this needs to be allowed, but only a few, so warn on them
"@typescript-eslint/no-floating-promises": "warn",
// There are a few places where this needs to be allowed, but only a few, so warn on them
"@typescript-eslint/no-unused-expressions": "warn",
// ***** airbnb-base, airbnb-typescript/base *****
"no-await-in-loop": "off",
"no-bitwise": "off",
// ***** plugin:jest/recommended *****
// A lot of test files define their own expect functions
"jest/expect-expect": "off"
},
"overrides": [
{
"files": [
"test/**/*.ts",
// TODO(cemmer)
"src/polyfill/**/*.ts",
"src/types/files/**/*.ts",
"src/types/patches/**/*.ts"
],
"rules": {
"jsdoc/require-jsdoc": "off"
}
}
]
}