@petbee/eslint-config 1.0.1-alpha-1.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +13 -59
- package/lib/utils.js +11 -0
- package/package.json +18 -8
- package/rules/best-practices.js +303 -0
- package/rules/errors.js +41 -0
- package/rules/imports.js +54 -0
- package/rules/node.js +42 -0
- package/rules/prettier.js +8 -0
- package/rules/style.js +210 -0
- package/rules/tests.js +78 -0
- package/rules/typescript.js +286 -0
- package/rules/variables.js +53 -0
package/index.js
CHANGED
|
@@ -1,74 +1,28 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
parser: '@typescript-eslint/parser',
|
|
3
2
|
parserOptions: {
|
|
4
3
|
project: 'tsconfig.json',
|
|
5
4
|
sourceType: 'module',
|
|
6
|
-
warnOnUnsupportedTypeScriptVersion: false,
|
|
7
5
|
},
|
|
8
6
|
plugins: ['@typescript-eslint/eslint-plugin'],
|
|
9
7
|
extends: [
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
8
|
+
'eslint:recommended',
|
|
9
|
+
'./rules/prettier.js',
|
|
10
|
+
'./rules/errors.js',
|
|
11
|
+
'./rules/node.js',
|
|
12
|
+
'./rules/style.js',
|
|
13
|
+
'./rules/variables.js',
|
|
14
|
+
'./rules/best-practices.js',
|
|
15
|
+
'./rules/imports.js',
|
|
16
|
+
'./rules/typescript.js',
|
|
17
|
+
'./rules/tests.js',
|
|
14
18
|
],
|
|
15
19
|
root: true,
|
|
16
20
|
env: {
|
|
17
21
|
node: true,
|
|
18
22
|
jest: true,
|
|
23
|
+
es6: true,
|
|
19
24
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
'@typescript-eslint/interface-name-prefix': 'off',
|
|
23
|
-
|
|
24
|
-
// Allow inferring types for functions
|
|
25
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
26
|
-
|
|
27
|
-
// Allow inferring types for exported things
|
|
28
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
29
|
-
|
|
30
|
-
// Don't allow "any" at all
|
|
31
|
-
'@typescript-eslint/no-explicit-any': 'error',
|
|
32
|
-
|
|
33
|
-
// Make sure we are awaiting or explicitly voiding all Promises
|
|
34
|
-
'@typescript-eslint/no-floating-promises': 'error',
|
|
35
|
-
|
|
36
|
-
// Allow using functions that are defined later in the file (fine thanks to hoisting)
|
|
37
|
-
'@typescript-eslint/no-use-before-define': [
|
|
38
|
-
'error',
|
|
39
|
-
{ functions: false, classes: false, variables: true },
|
|
40
|
-
],
|
|
41
|
-
|
|
42
|
-
// This rule makes no difference - ' and " are fine, > and } are already compile errors
|
|
43
|
-
'react/no-unescaped-entities': 'off',
|
|
44
|
-
|
|
45
|
-
// Disable validation of prop types, because we use TS instead and it gets confused
|
|
46
|
-
'react/prop-types': 'off',
|
|
47
|
-
|
|
48
|
-
// Make sure comments are starting with an uppercase letter, to encourage correct grammar
|
|
49
|
-
'capitalized-comments': [
|
|
50
|
-
'warn',
|
|
51
|
-
'always',
|
|
52
|
-
{
|
|
53
|
-
ignorePattern: 'prettier|c8',
|
|
54
|
-
ignoreConsecutiveComments: true,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
|
|
58
|
-
// Disable specific syntax features
|
|
59
|
-
'no-restricted-syntax': [
|
|
60
|
-
'error',
|
|
61
|
-
// Don't allow TS enums at all, since they have multiple unintuitive footguns
|
|
62
|
-
{
|
|
63
|
-
selector: 'TSEnumDeclaration',
|
|
64
|
-
message:
|
|
65
|
-
'Unexpected enum. Use a literal string union or a const object instead.',
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
},
|
|
69
|
-
settings: {
|
|
70
|
-
react: {
|
|
71
|
-
version: 'detect',
|
|
72
|
-
},
|
|
25
|
+
globals: {
|
|
26
|
+
__DEV__: true,
|
|
73
27
|
},
|
|
74
28
|
}
|
package/lib/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@petbee/eslint-config",
|
|
3
|
-
"version": "1.0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Petbee's eslint config",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"main": "index.js",
|
|
13
13
|
"files": [
|
|
14
|
-
"index.js"
|
|
14
|
+
"index.js",
|
|
15
|
+
"rules/",
|
|
16
|
+
"lib/"
|
|
15
17
|
],
|
|
16
18
|
"repository": {
|
|
17
19
|
"type": "git",
|
|
@@ -31,17 +33,25 @@
|
|
|
31
33
|
"url": "https://github.com/petbee/typescript/issues"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "6.10.0",
|
|
35
|
-
"@typescript-eslint/parser": "6.10.0",
|
|
36
|
-
"
|
|
37
|
-
"eslint-
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
37
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
38
|
+
"confusing-browser-globals": "^1.0.11",
|
|
39
|
+
"eslint-config-prettier": "^9.0.0",
|
|
40
|
+
"eslint-plugin-cypress": "^2.15.1",
|
|
41
|
+
"eslint-plugin-import": "^2.29.0",
|
|
42
|
+
"eslint-plugin-jest": "^27.6.0",
|
|
43
|
+
"eslint-plugin-node": "^11.1.0",
|
|
44
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
45
|
+
"eslint-plugin-react": "7.33.2",
|
|
46
|
+
"eslint-plugin-vtex": "^2.2.1"
|
|
38
47
|
},
|
|
39
48
|
"peerDependencies": {
|
|
40
49
|
"eslint": "^8.0.0",
|
|
50
|
+
"prettier": "^2",
|
|
41
51
|
"typescript": "^4.0.0 || ^5.0.0"
|
|
42
52
|
},
|
|
43
53
|
"devDependencies": {
|
|
44
|
-
"@petbee/prettier-config": "
|
|
54
|
+
"@petbee/prettier-config": "^1.0.1",
|
|
45
55
|
"@types/react": "18.2.37",
|
|
46
56
|
"eslint": "8.53.0",
|
|
47
57
|
"prettier": "3.0.3",
|
|
@@ -51,5 +61,5 @@
|
|
|
51
61
|
"publishConfig": {
|
|
52
62
|
"access": "public"
|
|
53
63
|
},
|
|
54
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "2dd307b99bfc315b04625fa5d4376b9a846fb062"
|
|
55
65
|
}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
rules: {
|
|
3
|
+
// Enforces return statements in callbacks of array's methods
|
|
4
|
+
// https://eslint.org/docs/rules/array-callback-return
|
|
5
|
+
'array-callback-return': ['error', { allowImplicit: true }],
|
|
6
|
+
|
|
7
|
+
// Treat var statements as if they were block scoped
|
|
8
|
+
// https://eslint.org/docs/rules/block-scoped-var
|
|
9
|
+
'block-scoped-var': 'error',
|
|
10
|
+
|
|
11
|
+
// Require default case in switch statements
|
|
12
|
+
// https://eslint.org/docs/rules/default-case
|
|
13
|
+
'default-case': ['error', { commentPattern: '^no default$' }],
|
|
14
|
+
|
|
15
|
+
// Disallow case statement fallthrough
|
|
16
|
+
// https://eslint.org/docs/rules/no-fallthrough
|
|
17
|
+
'no-fallthrough': [
|
|
18
|
+
'error',
|
|
19
|
+
{
|
|
20
|
+
commentPattern: '(break[\\s\\w]*omitted|falls\\s?through)',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
|
|
24
|
+
// Enforce parameters with default values to be last
|
|
25
|
+
// https://eslint.org/docs/rules/default-param-last
|
|
26
|
+
'default-param-last': 'error',
|
|
27
|
+
|
|
28
|
+
// Encourages use of dot notation whenever possible
|
|
29
|
+
// https://eslint.org/docs/rules/dot-notation
|
|
30
|
+
'dot-notation': ['error', { allowKeywords: true }],
|
|
31
|
+
|
|
32
|
+
// Require the use of === and !==
|
|
33
|
+
// https://eslint.org/docs/rules/eqeqeq
|
|
34
|
+
eqeqeq: ['error', 'always', { null: 'ignore' }],
|
|
35
|
+
|
|
36
|
+
// Require grouped accessor pairs in object literals and classes
|
|
37
|
+
// https://eslint.org/docs/rules/grouped-accessor-pairs
|
|
38
|
+
'grouped-accessor-pairs': 'error',
|
|
39
|
+
|
|
40
|
+
// Enforce a maximum number of classes per file
|
|
41
|
+
// https://eslint.org/docs/rules/max-classes-per-file
|
|
42
|
+
// TODO, maybe turn on
|
|
43
|
+
'max-classes-per-file': ['off', 1],
|
|
44
|
+
|
|
45
|
+
// Disallow the use of alert, confirm, and prompt
|
|
46
|
+
// https://eslint.org/docs/rules/no-alert
|
|
47
|
+
'no-alert': 'warn',
|
|
48
|
+
|
|
49
|
+
// Disallow use of arguments.caller or arguments.callee
|
|
50
|
+
// https://eslint.org/docs/rules/no-caller
|
|
51
|
+
'no-caller': 'error',
|
|
52
|
+
|
|
53
|
+
// Disallow lexical declarations in case/default clauses
|
|
54
|
+
// https://eslint.org/docs/rules/no-case-declarations
|
|
55
|
+
'no-case-declarations': 'error',
|
|
56
|
+
|
|
57
|
+
// Disallow returning value in constructor
|
|
58
|
+
// https://eslint.org/docs/rules/no-constructor-return
|
|
59
|
+
'no-constructor-return': 'error',
|
|
60
|
+
|
|
61
|
+
// Disallow else after a return in an if
|
|
62
|
+
// https://eslint.org/docs/rules/no-else-return
|
|
63
|
+
'no-else-return': ['error', { allowElseIf: false }],
|
|
64
|
+
|
|
65
|
+
// Disallow empty functions, except for standalone funcs/arrows
|
|
66
|
+
// https://eslint.org/docs/rules/no-empty-function
|
|
67
|
+
'no-empty-function': [
|
|
68
|
+
'error',
|
|
69
|
+
{
|
|
70
|
+
allow: ['arrowFunctions', 'functions', 'methods'],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
|
|
74
|
+
// Disallow use of eval()
|
|
75
|
+
// https://eslint.org/docs/rules/no-eval
|
|
76
|
+
'no-eval': 'error',
|
|
77
|
+
|
|
78
|
+
// Disallow adding to native types
|
|
79
|
+
// https://eslint.org/docs/rules/no-extend-native
|
|
80
|
+
'no-extend-native': 'error',
|
|
81
|
+
|
|
82
|
+
// Disallow unnecessary function binding
|
|
83
|
+
// https://eslint.org/docs/rules/no-extra-bind
|
|
84
|
+
'no-extra-bind': 'error',
|
|
85
|
+
|
|
86
|
+
// Disallow Unnecessary Labels
|
|
87
|
+
// https://eslint.org/docs/rules/no-extra-label
|
|
88
|
+
'no-extra-label': 'error',
|
|
89
|
+
|
|
90
|
+
// Disallow the use of leading or trailing decimal points in numeric literals
|
|
91
|
+
// https://eslint.org/docs/rules/no-floating-decimal
|
|
92
|
+
// Disabled because prettier already handle this rule
|
|
93
|
+
'no-floating-decimal': 'off',
|
|
94
|
+
|
|
95
|
+
// Disallow reassignments of native objects or read-only globals
|
|
96
|
+
// https://eslint.org/docs/rules/no-global-assign
|
|
97
|
+
'no-global-assign': 'error',
|
|
98
|
+
|
|
99
|
+
// Disallow use of eval()-like methods
|
|
100
|
+
// https://eslint.org/docs/rules/no-implied-eval
|
|
101
|
+
'no-implied-eval': 'error',
|
|
102
|
+
|
|
103
|
+
// Disallow usage of __iterator__ property
|
|
104
|
+
// https://eslint.org/docs/rules/no-iterator
|
|
105
|
+
'no-iterator': 'error',
|
|
106
|
+
|
|
107
|
+
// Disallow use of labels for anything other then loops and switches
|
|
108
|
+
// https://eslint.org/docs/rules/no-labels
|
|
109
|
+
'no-labels': 'error',
|
|
110
|
+
|
|
111
|
+
// Disallow unnecessary nested blocks
|
|
112
|
+
// https://eslint.org/docs/rules/no-lone-blocks
|
|
113
|
+
'no-lone-blocks': 'error',
|
|
114
|
+
|
|
115
|
+
// Disallow creation of functions within loops
|
|
116
|
+
// https://eslint.org/docs/rules/no-loop-func
|
|
117
|
+
'no-loop-func': 'error',
|
|
118
|
+
|
|
119
|
+
// Disallow magic numbers
|
|
120
|
+
// https://eslint.org/docs/rules/no-magic-numbers
|
|
121
|
+
// TODO enable? maybe too much
|
|
122
|
+
'no-magic-numbers': [
|
|
123
|
+
'off',
|
|
124
|
+
{
|
|
125
|
+
ignore: [0, 1, 2, 3],
|
|
126
|
+
ignoreArrayIndexes: true,
|
|
127
|
+
enforceConst: true,
|
|
128
|
+
detectObjects: false,
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
|
|
132
|
+
// Disallow use of multiline strings
|
|
133
|
+
// https://eslint.org/docs/rules/no-multi-str
|
|
134
|
+
'no-multi-str': 'error',
|
|
135
|
+
|
|
136
|
+
// Disallow use of new operator for Function object
|
|
137
|
+
// https://eslint.org/docs/rules/no-new-func
|
|
138
|
+
'no-new-func': 'error',
|
|
139
|
+
|
|
140
|
+
// Disallows creating new instances of String, Number, and Boolean
|
|
141
|
+
// https://eslint.org/docs/rules/no-new-wrappers
|
|
142
|
+
'no-new-wrappers': 'error',
|
|
143
|
+
|
|
144
|
+
// Disallow use of octal escape sequences in string literals, such as
|
|
145
|
+
// var foo = 'Copyright \251';
|
|
146
|
+
// https://eslint.org/docs/rules/no-octal-escape
|
|
147
|
+
'no-octal-escape': 'error',
|
|
148
|
+
|
|
149
|
+
// Disallow usage of __proto__ property
|
|
150
|
+
// https://eslint.org/docs/rules/no-proto
|
|
151
|
+
'no-proto': 'error',
|
|
152
|
+
|
|
153
|
+
// Disallow declaring the same variable more then once
|
|
154
|
+
// https://eslint.org/docs/rules/no-redeclare
|
|
155
|
+
'no-redeclare': 'error',
|
|
156
|
+
|
|
157
|
+
// Disallow use of assignment in return statement
|
|
158
|
+
// https://eslint.org/docs/rules/no-return-assign
|
|
159
|
+
'no-return-assign': ['error', 'except-parens'],
|
|
160
|
+
|
|
161
|
+
// Disallow redundant `return await`
|
|
162
|
+
// https://eslint.org/docs/rules/no-return-await
|
|
163
|
+
'no-return-await': 'error',
|
|
164
|
+
|
|
165
|
+
// Disallow use of `javascript:` urls.
|
|
166
|
+
// https://eslint.org/docs/rules/no-script-url
|
|
167
|
+
'no-script-url': 'error',
|
|
168
|
+
|
|
169
|
+
// Disallow comparisons where both sides are exactly the same
|
|
170
|
+
// https://eslint.org/docs/rules/no-self-compare
|
|
171
|
+
'no-self-compare': 'error',
|
|
172
|
+
|
|
173
|
+
// Disallow use of comma operator
|
|
174
|
+
// https://eslint.org/docs/rules/no-sequences
|
|
175
|
+
'no-sequences': 'error',
|
|
176
|
+
|
|
177
|
+
// Disallow unused labels
|
|
178
|
+
// https://eslint.org/docs/rules/no-unused-labels
|
|
179
|
+
'no-unused-labels': 'error',
|
|
180
|
+
|
|
181
|
+
// Disallow unnecessary catch clauses
|
|
182
|
+
// https://eslint.org/docs/rules/no-useless-catch
|
|
183
|
+
// TODO enable?
|
|
184
|
+
'no-useless-catch': 'off',
|
|
185
|
+
|
|
186
|
+
// Disallow unnecessary string escaping
|
|
187
|
+
// https://eslint.org/docs/rules/no-useless-escape
|
|
188
|
+
'no-useless-escape': 'error',
|
|
189
|
+
|
|
190
|
+
// Disallow redundant return; keywords
|
|
191
|
+
// https://eslint.org/docs/rules/no-useless-return
|
|
192
|
+
'no-useless-return': 'error',
|
|
193
|
+
|
|
194
|
+
// Disallow use of void operator
|
|
195
|
+
// https://eslint.org/docs/rules/no-void
|
|
196
|
+
'no-void': 'error',
|
|
197
|
+
|
|
198
|
+
// Prefer using regex literals instead of constructor
|
|
199
|
+
// https://eslint.org/docs/rules/prefer-regex-literals
|
|
200
|
+
'prefer-regex-literals': 'warn',
|
|
201
|
+
|
|
202
|
+
// Require use of the second argument for parseInt()
|
|
203
|
+
// https://eslint.org/docs/rules/radix
|
|
204
|
+
radix: 'error',
|
|
205
|
+
|
|
206
|
+
// Requires to declare all vars on top of their containing scope
|
|
207
|
+
// https://eslint.org/docs/rules/vars-on-top
|
|
208
|
+
'vars-on-top': 'error',
|
|
209
|
+
// https://eslint.org/docs/rules/constructor-super
|
|
210
|
+
'constructor-super': 'error',
|
|
211
|
+
|
|
212
|
+
// Disallow useless computed property keys
|
|
213
|
+
// https://eslint.org/docs/rules/no-useless-computed-key
|
|
214
|
+
'no-useless-computed-key': 'error',
|
|
215
|
+
|
|
216
|
+
// Disallow unnecessary constructor
|
|
217
|
+
// https://eslint.org/docs/rules/no-useless-constructor
|
|
218
|
+
'no-useless-constructor': 'error',
|
|
219
|
+
|
|
220
|
+
// Disallow renaming import, export, and destructured assignments to the same name
|
|
221
|
+
// https://eslint.org/docs/rules/no-useless-rename
|
|
222
|
+
'no-useless-rename': ['error'],
|
|
223
|
+
|
|
224
|
+
// Require let or const instead of var
|
|
225
|
+
// https://eslint.org/docs/rules/no-var
|
|
226
|
+
'no-var': 'error',
|
|
227
|
+
|
|
228
|
+
// Require method and property shorthand syntax for object literals
|
|
229
|
+
// https://eslint.org/docs/rules/object-shorthand
|
|
230
|
+
'object-shorthand': [
|
|
231
|
+
'error',
|
|
232
|
+
'always',
|
|
233
|
+
{
|
|
234
|
+
ignoreConstructors: false,
|
|
235
|
+
avoidQuotes: true,
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
|
|
239
|
+
// Suggest using arrow functions as callbacks
|
|
240
|
+
// https://eslint.org/docs/rules/prefer-arrow-callback
|
|
241
|
+
// TODO discussion
|
|
242
|
+
'prefer-arrow-callback': [
|
|
243
|
+
'off',
|
|
244
|
+
{
|
|
245
|
+
allowNamedFunctions: false,
|
|
246
|
+
allowUnboundThis: true,
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
|
|
250
|
+
// Suggest using of const declaration for variables that are never modified after declared
|
|
251
|
+
// https://eslint.org/docs/rules/prefer-const
|
|
252
|
+
'prefer-const': [
|
|
253
|
+
'error',
|
|
254
|
+
{
|
|
255
|
+
destructuring: 'all',
|
|
256
|
+
ignoreReadBeforeAssign: true,
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
|
|
260
|
+
// Prefer destructuring from arrays and objects
|
|
261
|
+
// https://eslint.org/docs/rules/prefer-destructuring
|
|
262
|
+
'prefer-destructuring': [
|
|
263
|
+
'warn',
|
|
264
|
+
{
|
|
265
|
+
VariableDeclarator: {
|
|
266
|
+
array: true,
|
|
267
|
+
object: true,
|
|
268
|
+
},
|
|
269
|
+
AssignmentExpression: {
|
|
270
|
+
array: false,
|
|
271
|
+
object: false,
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
enforceForRenamedProperties: false,
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
|
|
279
|
+
// Disallow parseInt() in favor of binary, octal, and hexadecimal literals
|
|
280
|
+
// https://eslint.org/docs/rules/prefer-numeric-literals
|
|
281
|
+
'prefer-numeric-literals': 'error',
|
|
282
|
+
|
|
283
|
+
// Use rest parameters instead of arguments
|
|
284
|
+
// https://eslint.org/docs/rules/prefer-rest-params
|
|
285
|
+
'prefer-rest-params': 'error',
|
|
286
|
+
|
|
287
|
+
// Suggest using the spread operator instead of .apply()
|
|
288
|
+
// https://eslint.org/docs/rules/prefer-spread
|
|
289
|
+
'prefer-spread': 'error',
|
|
290
|
+
|
|
291
|
+
// Suggest using template literals instead of string concatenation
|
|
292
|
+
// https://eslint.org/docs/rules/prefer-template
|
|
293
|
+
'prefer-template': 'warn',
|
|
294
|
+
|
|
295
|
+
// Disallow generator functions that do not have yield
|
|
296
|
+
// https://eslint.org/docs/rules/require-yield
|
|
297
|
+
'require-yield': 'error',
|
|
298
|
+
|
|
299
|
+
// Require a Symbol description
|
|
300
|
+
// https://eslint.org/docs/rules/symbol-description
|
|
301
|
+
'symbol-description': 'error',
|
|
302
|
+
},
|
|
303
|
+
}
|
package/rules/errors.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
// only rules not included in 'eslint:recommended' or with different values
|
|
3
|
+
rules: {
|
|
4
|
+
// Enforces that a return statement is present in property getters
|
|
5
|
+
// https://eslint.org/docs/rules/getter-return
|
|
6
|
+
'getter-return': ['error', { allowImplicit: true }],
|
|
7
|
+
|
|
8
|
+
// Disallow await inside of loops
|
|
9
|
+
// https://eslint.org/docs/rules/no-await-in-loop
|
|
10
|
+
'no-await-in-loop': 'error',
|
|
11
|
+
|
|
12
|
+
// Disallow assignment in conditional expressions
|
|
13
|
+
// https://eslint.org/docs/rules/no-cond-assign
|
|
14
|
+
'no-cond-assign': ['error', 'except-parens'],
|
|
15
|
+
|
|
16
|
+
// Disallow use of console
|
|
17
|
+
// https://eslint.org/docs/rules/no-console
|
|
18
|
+
'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
|
|
19
|
+
|
|
20
|
+
// Disallow template literal placeholder syntax in regular strings
|
|
21
|
+
// https://eslint.org/docs/rules/no-template-curly-in-string
|
|
22
|
+
'no-template-curly-in-string': 'error',
|
|
23
|
+
|
|
24
|
+
// Disallow assignments that can lead to race conditions due to usage of await or yield
|
|
25
|
+
// https://eslint.org/docs/rules/require-atomic-updates
|
|
26
|
+
'require-atomic-updates': 'warn',
|
|
27
|
+
|
|
28
|
+
//! Require eslint >= 6.7.0
|
|
29
|
+
|
|
30
|
+
// Disallow duplicate conditions in if-else-if chains
|
|
31
|
+
// https://eslint.org/docs/rules/no-dupe-else-if
|
|
32
|
+
'no-dupe-else-if': 'error',
|
|
33
|
+
|
|
34
|
+
// https://eslint.org/docs/rules/no-import-assign
|
|
35
|
+
'no-import-assign': 'error',
|
|
36
|
+
|
|
37
|
+
// Disallow returning values from setters
|
|
38
|
+
// https://eslint.org/docs/rules/no-setter-return
|
|
39
|
+
'no-setter-return': 'error',
|
|
40
|
+
},
|
|
41
|
+
}
|
package/rules/imports.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules
|
|
2
|
+
module.exports = {
|
|
3
|
+
extends: ['plugin:import/typescript'],
|
|
4
|
+
plugins: ['import'],
|
|
5
|
+
rules: {
|
|
6
|
+
// Disallow non-import statements appearing before import statements
|
|
7
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/first.md
|
|
8
|
+
'import/first': 'error',
|
|
9
|
+
|
|
10
|
+
// Disallow duplicate imports
|
|
11
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
|
|
12
|
+
'import/no-duplicates': 'error',
|
|
13
|
+
|
|
14
|
+
// Ensure native, external and internal imports are separated, above relative imports and that unassigned imports are ignored
|
|
15
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
|
|
16
|
+
'import/order': [
|
|
17
|
+
'error',
|
|
18
|
+
{
|
|
19
|
+
'newlines-between': 'always',
|
|
20
|
+
groups: [
|
|
21
|
+
'builtin',
|
|
22
|
+
'external',
|
|
23
|
+
'internal',
|
|
24
|
+
['parent', 'sibling', 'index'],
|
|
25
|
+
'type',
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
|
|
30
|
+
// Require a newline after the last import/require in a group
|
|
31
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
|
|
32
|
+
'import/newline-after-import': 'error',
|
|
33
|
+
|
|
34
|
+
// Forbid import of modules using absolute paths
|
|
35
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
|
|
36
|
+
'import/no-absolute-path': 'error',
|
|
37
|
+
|
|
38
|
+
// Forbid mutable exports
|
|
39
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
|
|
40
|
+
'import/no-mutable-exports': 'error',
|
|
41
|
+
|
|
42
|
+
// Disallow invalid exports, e.g. multiple defaults
|
|
43
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/export.md
|
|
44
|
+
'import/export': 'error',
|
|
45
|
+
|
|
46
|
+
// Ensures that there are no useless path segments
|
|
47
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-useless-path-segments.md
|
|
48
|
+
'import/no-useless-path-segments': ['error', { commonjs: true }],
|
|
49
|
+
|
|
50
|
+
// Forbid a module from importing itself
|
|
51
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-self-import.md
|
|
52
|
+
'import/no-self-import': 'error',
|
|
53
|
+
},
|
|
54
|
+
}
|
package/rules/node.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
plugins: ['node'],
|
|
3
|
+
env: {
|
|
4
|
+
node: true,
|
|
5
|
+
},
|
|
6
|
+
rules: {
|
|
7
|
+
// Disallow use of process.env
|
|
8
|
+
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-process-env.md
|
|
9
|
+
'node/no-process-env': 'off',
|
|
10
|
+
|
|
11
|
+
// Enforce a callback to return
|
|
12
|
+
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/callback-return.md
|
|
13
|
+
//! too annoying
|
|
14
|
+
'node/callback-return': 'off',
|
|
15
|
+
|
|
16
|
+
// Require all requires be top-level
|
|
17
|
+
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/global-require.md
|
|
18
|
+
'node/global-require': 'error',
|
|
19
|
+
|
|
20
|
+
// Disallow use of new operator with the require function
|
|
21
|
+
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-new-require.md
|
|
22
|
+
'node/no-new-require': 'error',
|
|
23
|
+
|
|
24
|
+
// Disallow string concatenation with __dirname and __filename
|
|
25
|
+
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-path-concat.md
|
|
26
|
+
'node/no-path-concat': 'error',
|
|
27
|
+
|
|
28
|
+
// Make process.exit() expressions the same code path as throw
|
|
29
|
+
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/process-exit-as-throw.md
|
|
30
|
+
'node/process-exit-as-throw': 'error',
|
|
31
|
+
|
|
32
|
+
// Disallow deprecated APIs
|
|
33
|
+
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-deprecated-api.md
|
|
34
|
+
'node/no-deprecated-api': 'error',
|
|
35
|
+
|
|
36
|
+
// Encourages use of promise APIs instead o callback APIs
|
|
37
|
+
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/prefer-promises/fs.md
|
|
38
|
+
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/prefer-promises/dns.md
|
|
39
|
+
'node/prefer-promises/fs': 'warn',
|
|
40
|
+
'node/prefer-promises/dns': 'warn',
|
|
41
|
+
},
|
|
42
|
+
}
|
package/rules/style.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
rules: {
|
|
3
|
+
// Allow brace-less single-line if, else if, else, for, while, or do, while still enforcing the use of curly braces for other instances.
|
|
4
|
+
// https://eslint.org/docs/rules/curly
|
|
5
|
+
// Disabled because conflicts with prettier
|
|
6
|
+
// https://github.com/prettier/eslint-config-prettier#curly
|
|
7
|
+
curly: 'off',
|
|
8
|
+
|
|
9
|
+
// Require camel case names
|
|
10
|
+
// https://eslint.org/docs/rules/camelcase
|
|
11
|
+
camelcase: [
|
|
12
|
+
'error',
|
|
13
|
+
{
|
|
14
|
+
properties: 'never',
|
|
15
|
+
ignoreDestructuring: false,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
|
|
19
|
+
// Require function expressions to have a name
|
|
20
|
+
// https://eslint.org/docs/rules/func-names
|
|
21
|
+
'func-names': 'warn',
|
|
22
|
+
|
|
23
|
+
// Enforce position of line comments
|
|
24
|
+
// https://eslint.org/docs/rules/line-comment-position
|
|
25
|
+
// TODO https://github.com/vtex/front-end-coding-standard/issues/30
|
|
26
|
+
'line-comment-position': [
|
|
27
|
+
'off',
|
|
28
|
+
{
|
|
29
|
+
position: 'above',
|
|
30
|
+
applyDefaultPatterns: true,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
|
|
34
|
+
// Disallow comments inline after code
|
|
35
|
+
// https://eslint.org/docs/rules/no-inline-comments
|
|
36
|
+
// TODO https://github.com/vtex/front-end-coding-standard/issues/30
|
|
37
|
+
'no-inline-comments': 'off',
|
|
38
|
+
|
|
39
|
+
// Require or disallow newlines around directives
|
|
40
|
+
// https://eslint.org/docs/rules/lines-around-directive
|
|
41
|
+
'lines-around-directive': [
|
|
42
|
+
'error',
|
|
43
|
+
{
|
|
44
|
+
before: 'always',
|
|
45
|
+
after: 'always',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
|
|
49
|
+
// Limit the number of parameters that can be used in the function declaration.
|
|
50
|
+
// https://eslint.org/docs/rules/max-params
|
|
51
|
+
'max-params': [
|
|
52
|
+
'warn',
|
|
53
|
+
{
|
|
54
|
+
max: 3,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
|
|
58
|
+
// Require a capital letter for constructors
|
|
59
|
+
// https://eslint.org/docs/rules/new-cap
|
|
60
|
+
'new-cap': [
|
|
61
|
+
'error',
|
|
62
|
+
{
|
|
63
|
+
newIsCap: true,
|
|
64
|
+
capIsNew: false,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
|
|
68
|
+
// Disallow use of the Array constructor
|
|
69
|
+
// https://eslint.org/docs/rules/no-array-constructor
|
|
70
|
+
'no-array-constructor': 'error',
|
|
71
|
+
|
|
72
|
+
// Disallow if as the only statement in an else block
|
|
73
|
+
// https://eslint.org/docs/rules/no-lonely-if
|
|
74
|
+
'no-lonely-if': 'error',
|
|
75
|
+
|
|
76
|
+
// Disallow use of chained assignment expressions
|
|
77
|
+
// https://eslint.org/docs/rules/no-multi-assign
|
|
78
|
+
'no-multi-assign': 'error',
|
|
79
|
+
|
|
80
|
+
// Disallow negated conditions
|
|
81
|
+
// https://eslint.org/docs/rules/no-negated-condition
|
|
82
|
+
'no-negated-condition': 'warn',
|
|
83
|
+
|
|
84
|
+
// Disallow use of the Object constructor
|
|
85
|
+
// https://eslint.org/docs/rules/no-new-object
|
|
86
|
+
'no-new-object': 'error',
|
|
87
|
+
|
|
88
|
+
// Disallow certain syntax forms
|
|
89
|
+
// https://eslint.org/docs/rules/no-restricted-syntax
|
|
90
|
+
'no-restricted-syntax': [
|
|
91
|
+
'error',
|
|
92
|
+
{
|
|
93
|
+
selector: 'LabeledStatement',
|
|
94
|
+
message:
|
|
95
|
+
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
selector: 'WithStatement',
|
|
99
|
+
message:
|
|
100
|
+
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
|
|
101
|
+
},
|
|
102
|
+
// ban all enums
|
|
103
|
+
{
|
|
104
|
+
selector: 'TSEnumDeclaration:not([const=true])',
|
|
105
|
+
message:
|
|
106
|
+
"Literal types and enums, in many cases, solve the same problem while enum has some trade-offs that usually literal types don't. Consider using a literal type instead. See https://github.com/vtex/typescript/issues/60 for more information.",
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
|
|
110
|
+
// Disallow the use of Boolean literals in conditional expressions
|
|
111
|
+
// Also, prefer `a || b` over `a ? a : b`
|
|
112
|
+
// https://eslint.org/docs/rules/no-unneeded-ternary
|
|
113
|
+
'no-unneeded-ternary': ['error', { defaultAssignment: false }],
|
|
114
|
+
|
|
115
|
+
// Allow just one var statement per function
|
|
116
|
+
// https://eslint.org/docs/rules/one-var
|
|
117
|
+
'one-var': ['error', 'never'],
|
|
118
|
+
|
|
119
|
+
// Require assignment operator shorthand where possible or prohibit it entirely
|
|
120
|
+
// https://eslint.org/docs/rules/operator-assignment
|
|
121
|
+
'operator-assignment': ['error', 'always'],
|
|
122
|
+
|
|
123
|
+
// Prefer use of an object spread over Object.assign
|
|
124
|
+
// https://eslint.org/docs/rules/prefer-object-spread
|
|
125
|
+
'prefer-object-spread': 'error',
|
|
126
|
+
|
|
127
|
+
// Require or disallow a space immediately following the // or /* in a comment
|
|
128
|
+
// https://eslint.org/docs/rules/spaced-comment
|
|
129
|
+
'spaced-comment': [
|
|
130
|
+
'error',
|
|
131
|
+
'always',
|
|
132
|
+
{
|
|
133
|
+
line: {
|
|
134
|
+
exceptions: ['-', '+'],
|
|
135
|
+
markers: ['-', '+', '?', '!'],
|
|
136
|
+
},
|
|
137
|
+
block: {
|
|
138
|
+
exceptions: ['-', '+'],
|
|
139
|
+
markers: ['-', '+', '?', '!'],
|
|
140
|
+
balanced: true,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
|
|
145
|
+
// Require or disallow padding lines between statements
|
|
146
|
+
// https://eslint.org/docs/rules/padding-line-between-statements
|
|
147
|
+
'padding-line-between-statements': [
|
|
148
|
+
'warn',
|
|
149
|
+
// empty lines after declarations
|
|
150
|
+
{
|
|
151
|
+
blankLine: 'always',
|
|
152
|
+
prev: ['const', 'let', 'var'],
|
|
153
|
+
next: '*',
|
|
154
|
+
},
|
|
155
|
+
// allow to have none or one blank line between declarations
|
|
156
|
+
{
|
|
157
|
+
blankLine: 'any',
|
|
158
|
+
prev: ['const', 'let', 'var'],
|
|
159
|
+
next: ['const', 'let', 'var'],
|
|
160
|
+
},
|
|
161
|
+
// enforce blank lines after multiline declarations
|
|
162
|
+
{
|
|
163
|
+
blankLine: 'always',
|
|
164
|
+
prev: ['multiline-const', 'multiline-let', 'multiline-var'],
|
|
165
|
+
next: '*',
|
|
166
|
+
},
|
|
167
|
+
// empty lines before returns
|
|
168
|
+
{
|
|
169
|
+
blankLine: 'always',
|
|
170
|
+
prev: '*',
|
|
171
|
+
next: 'return',
|
|
172
|
+
},
|
|
173
|
+
// empty lines between switch cases and breaks
|
|
174
|
+
{
|
|
175
|
+
blankLine: 'always',
|
|
176
|
+
prev: ['case', 'break'],
|
|
177
|
+
next: ['case', 'break', 'default'],
|
|
178
|
+
},
|
|
179
|
+
// always require blankline after function, class declarations and multiline blocks (if, try-catch, etc)
|
|
180
|
+
{
|
|
181
|
+
blankLine: 'always',
|
|
182
|
+
prev: ['function', 'class', 'multiline-block-like'],
|
|
183
|
+
next: '*',
|
|
184
|
+
},
|
|
185
|
+
// import/order already handle padding lines between cjs-imports
|
|
186
|
+
// see https://github.com/vtex/typescript/issues/82
|
|
187
|
+
{
|
|
188
|
+
blankLine: 'any',
|
|
189
|
+
prev: ['cjs-import'],
|
|
190
|
+
next: ['cjs-import'],
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
|
|
194
|
+
// Require or disallow padding lines between class members
|
|
195
|
+
// https://eslint.org/docs/rules/lines-between-class-members
|
|
196
|
+
'lines-between-class-members': [
|
|
197
|
+
'error',
|
|
198
|
+
'always',
|
|
199
|
+
{
|
|
200
|
+
exceptAfterSingleLine: true,
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
|
|
204
|
+
//! Require eslint >= 6.7.0
|
|
205
|
+
|
|
206
|
+
// Disallow the use of Math.pow in favor of the ** operator
|
|
207
|
+
// https://eslint.org/docs/rules/prefer-exponentiation-operator
|
|
208
|
+
'prefer-exponentiation-operator': 'error',
|
|
209
|
+
},
|
|
210
|
+
}
|
package/rules/tests.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Jest:
|
|
2
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules
|
|
3
|
+
// Cypress: https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules
|
|
4
|
+
const { hasPackage } = require('../lib/utils')
|
|
5
|
+
|
|
6
|
+
const hasJest = hasPackage('jest')
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
overrides: [
|
|
10
|
+
// ! CYPRESS
|
|
11
|
+
{
|
|
12
|
+
files: ['**/cypress/**/*.{ts,tsx,js,jsx}'],
|
|
13
|
+
extends: ['plugin:cypress/recommended'],
|
|
14
|
+
rules: {
|
|
15
|
+
// Enforce assertions before taking a screenshot
|
|
16
|
+
// https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/assertion-before-screenshot.md
|
|
17
|
+
'cypress/assertion-before-screenshot': 'warn',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
// ! JEST
|
|
21
|
+
{
|
|
22
|
+
// Run through every test file found
|
|
23
|
+
files: ['*.{test,spec}.{ts,tsx,js,jsx}'],
|
|
24
|
+
// Unless it's inside a cypress directory
|
|
25
|
+
excludedFiles: ['**/cypress/**'],
|
|
26
|
+
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
|
|
27
|
+
settings: {
|
|
28
|
+
// need to explicitly set this for the IO apps.
|
|
29
|
+
// we need to explicitly define jest version because IO apps
|
|
30
|
+
// have jest installed in a subdirectory.
|
|
31
|
+
jest: {
|
|
32
|
+
...(hasJest === false && {
|
|
33
|
+
version: 26,
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
rules: {
|
|
38
|
+
// Enforce consistent a test method name
|
|
39
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/consistent-test-it.md
|
|
40
|
+
'jest/consistent-test-it': [
|
|
41
|
+
'warn',
|
|
42
|
+
{
|
|
43
|
+
fn: 'test',
|
|
44
|
+
withinDescribe: 'it',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
|
|
48
|
+
// Disallow alias methods
|
|
49
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-alias-methods.md
|
|
50
|
+
'jest/no-alias-methods': 'error',
|
|
51
|
+
|
|
52
|
+
// Disallow duplicate setup/teardown hooks
|
|
53
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-duplicate-hooks.md
|
|
54
|
+
'jest/no-duplicate-hooks': 'error',
|
|
55
|
+
|
|
56
|
+
// Suggest to have all hooks at top-level before tests
|
|
57
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-hooks-on-top.md
|
|
58
|
+
'jest/prefer-hooks-on-top': 'error',
|
|
59
|
+
|
|
60
|
+
// Suggest jest.spyOn() instead of jest.fn()
|
|
61
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-spy-on.md
|
|
62
|
+
'jest/prefer-spy-on': 'warn',
|
|
63
|
+
|
|
64
|
+
// Suggest using test.todo()
|
|
65
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-todo.md
|
|
66
|
+
'jest/prefer-todo': 'warn',
|
|
67
|
+
|
|
68
|
+
// Disallow return statements from tests
|
|
69
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-test-return-statement.md
|
|
70
|
+
'jest/no-test-return-statement': 'warn',
|
|
71
|
+
|
|
72
|
+
// Disallow deprecated jest functions
|
|
73
|
+
// https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-deprecated-functions.md
|
|
74
|
+
'jest/no-deprecated-functions': 'error',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
const { hasPackage } = require('../lib/utils')
|
|
2
|
+
|
|
3
|
+
const hasTypescript = hasPackage('typescript')
|
|
4
|
+
|
|
5
|
+
module.exports = !hasTypescript
|
|
6
|
+
? {}
|
|
7
|
+
: {
|
|
8
|
+
overrides: [
|
|
9
|
+
{
|
|
10
|
+
files: ['*.ts', '*.tsx'],
|
|
11
|
+
extends: ['plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended'],
|
|
12
|
+
plugins: ['@typescript-eslint'],
|
|
13
|
+
parser: '@typescript-eslint/parser',
|
|
14
|
+
parserOptions: {
|
|
15
|
+
ecmaVersion: 2019,
|
|
16
|
+
sourceType: 'module',
|
|
17
|
+
project: [
|
|
18
|
+
// look in the root
|
|
19
|
+
'tsconfig{.eslint.json,.json}',
|
|
20
|
+
// look in dirs like node/react
|
|
21
|
+
'*/tsconfig{.eslint.json,.json}',
|
|
22
|
+
// look in dirs like packages/package/*
|
|
23
|
+
'*/*/tsconfig{.eslint.json,.json}',
|
|
24
|
+
],
|
|
25
|
+
projectFolderIgnoreList: [/node_modules/i],
|
|
26
|
+
// We need this configuration to avoid performance issues in monorepos
|
|
27
|
+
// https://github.com/typescript-eslint/typescript-eslint/issues/1192#issuecomment-862414778
|
|
28
|
+
allowAutomaticSingleRunInference: true,
|
|
29
|
+
},
|
|
30
|
+
rules: {
|
|
31
|
+
//! extensions of native eslint rules
|
|
32
|
+
//! when modifying a rule here, make sure to modify the native one and vice-versa
|
|
33
|
+
|
|
34
|
+
// Don't require a weird naming convention for interfaces
|
|
35
|
+
'@typescript-eslint/interface-name-prefix': 'off',
|
|
36
|
+
|
|
37
|
+
// Disallow declaration of variables already declared in the outer scope
|
|
38
|
+
// https://eslint.org/docs/rules/no-shadow
|
|
39
|
+
'no-shadow': 'off',
|
|
40
|
+
'@typescript-eslint/no-shadow': [
|
|
41
|
+
'error',
|
|
42
|
+
{
|
|
43
|
+
allow: ['done', 'next', 'resolve', 'reject', 'cb'],
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
|
|
47
|
+
// Prevent unused declared variables
|
|
48
|
+
// https://typescript-eslint.io/rules/no-unused-vars/
|
|
49
|
+
'no-unused-vars': 'off',
|
|
50
|
+
'@typescript-eslint/no-unused-vars': [
|
|
51
|
+
'warn',
|
|
52
|
+
{
|
|
53
|
+
ignoreRestSiblings: true,
|
|
54
|
+
argsIgnorePattern: '_+',
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
|
|
58
|
+
// Disallows the use of eval()-like methods
|
|
59
|
+
// https://typescript-eslint.io/rules/no-magic-numbers/
|
|
60
|
+
'no-magic-numbers': 'off',
|
|
61
|
+
'@typescript-eslint/no-magic-numbers': [
|
|
62
|
+
'off',
|
|
63
|
+
{
|
|
64
|
+
ignore: [0, 1, 2, 3],
|
|
65
|
+
ignoreArrayIndexes: true,
|
|
66
|
+
enforceConst: true,
|
|
67
|
+
detectObjects: false,
|
|
68
|
+
ignoreNumericLiteralTypes: true,
|
|
69
|
+
ignoreEnums: true,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
|
|
73
|
+
// Enforce parameters with default values to be last
|
|
74
|
+
// https://typescript-eslint.io/rules/default-param-last/
|
|
75
|
+
'default-param-last': 'off',
|
|
76
|
+
'@typescript-eslint/default-param-last': 'error',
|
|
77
|
+
|
|
78
|
+
// Disallow useless constructors
|
|
79
|
+
// https://typescript-eslint.io/rules/no-useless-constructor/
|
|
80
|
+
'no-useless-constructor': 'off',
|
|
81
|
+
'@typescript-eslint/no-useless-constructor': 'error',
|
|
82
|
+
|
|
83
|
+
// Disallow empty functions, except for standalone funcs/arrows
|
|
84
|
+
// https://eslint.org/docs/rules/no-empty-function
|
|
85
|
+
'no-empty-function': 'off',
|
|
86
|
+
'@typescript-eslint/no-empty-function': [
|
|
87
|
+
'error',
|
|
88
|
+
{
|
|
89
|
+
allow: ['arrowFunctions', 'functions', 'methods'],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
|
|
93
|
+
// Require a consistent naming convention
|
|
94
|
+
// https://typescript-eslint.io/rules/naming-convention/
|
|
95
|
+
camelcase: 'off',
|
|
96
|
+
'@typescript-eslint/naming-convention': [
|
|
97
|
+
'error',
|
|
98
|
+
{
|
|
99
|
+
selector: 'default',
|
|
100
|
+
format: ['camelCase'],
|
|
101
|
+
leadingUnderscore: 'allow',
|
|
102
|
+
trailingUnderscore: 'allow',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
selector: 'variable',
|
|
106
|
+
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
|
|
107
|
+
leadingUnderscore: 'allow',
|
|
108
|
+
trailingUnderscore: 'allow',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
selector: 'function',
|
|
112
|
+
format: ['camelCase', 'PascalCase'],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
selector: 'typeLike',
|
|
116
|
+
format: ['PascalCase'],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
selector: 'memberLike',
|
|
120
|
+
format: null,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
// have to leave this for now as this rule
|
|
124
|
+
// doesn't separate regular parameters from
|
|
125
|
+
// destructured parameters
|
|
126
|
+
selector: 'parameter',
|
|
127
|
+
format: null,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
|
|
131
|
+
// Disallow use of variables before they are defined
|
|
132
|
+
// https://typescript-eslint.io/rules/no-use-before-define/
|
|
133
|
+
'no-use-before-define': 'off',
|
|
134
|
+
'@typescript-eslint/no-use-before-define': [
|
|
135
|
+
'error',
|
|
136
|
+
{
|
|
137
|
+
functions: false,
|
|
138
|
+
classes: false,
|
|
139
|
+
variables: true,
|
|
140
|
+
enums: false,
|
|
141
|
+
typedefs: false,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
// ! ts only rules
|
|
145
|
+
// Enforce explicit accessibility modifiers on class properties and methods
|
|
146
|
+
// https://typescript-eslint.io/rules/explicit-member-accessibility/
|
|
147
|
+
'@typescript-eslint/explicit-member-accessibility': [
|
|
148
|
+
'error',
|
|
149
|
+
{
|
|
150
|
+
accessibility: 'explicit',
|
|
151
|
+
overrides: {
|
|
152
|
+
accessors: 'explicit',
|
|
153
|
+
constructors: 'no-public',
|
|
154
|
+
methods: 'explicit',
|
|
155
|
+
parameterProperties: 'explicit',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
|
|
160
|
+
// Don't allow "any" at all
|
|
161
|
+
// https://typescript-eslint.io/rules/no-explicit-any
|
|
162
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
163
|
+
|
|
164
|
+
// Enforce explicit function return type
|
|
165
|
+
// https://typescript-eslint.io/rules/explicit-function-return-type/
|
|
166
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
167
|
+
|
|
168
|
+
// Enforce a consistent way of typing arrays
|
|
169
|
+
// https://typescript-eslint.io/rules/array-type/v
|
|
170
|
+
'@typescript-eslint/array-type': [
|
|
171
|
+
'warn',
|
|
172
|
+
{
|
|
173
|
+
default: 'array-simple',
|
|
174
|
+
readonly: 'array-simple',
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
|
|
178
|
+
// Enforce a consitent way to type objects
|
|
179
|
+
// https://typescript-eslint.io/rules/consistent-type-definitions/
|
|
180
|
+
'@typescript-eslint/consistent-type-definitions': 'off',
|
|
181
|
+
|
|
182
|
+
// Disallow non null assertions (!), comes from the recommended config
|
|
183
|
+
// https://typescript-eslint.io/rules/no-non-null-assertion/
|
|
184
|
+
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
185
|
+
|
|
186
|
+
// Enforce that when adding two variables, operands must both be of type number or of type string
|
|
187
|
+
// https://typescript-eslint.io/rules/restrict-plus-operands/
|
|
188
|
+
'@typescript-eslint/restrict-plus-operands': [
|
|
189
|
+
'error',
|
|
190
|
+
{
|
|
191
|
+
skipCompoundAssignments: true,
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
|
|
195
|
+
// Enforce optional chaining over chaining AND (&&) operators
|
|
196
|
+
// https://typescript-eslint.io/rules/prefer-optional-chain/
|
|
197
|
+
'@typescript-eslint/prefer-optional-chain': 'warn',
|
|
198
|
+
|
|
199
|
+
// Enforce optional chaining over chaining AND (&&) operators
|
|
200
|
+
// https://typescript-eslint.io/rules/no-non-null-asserted-optional-chain/
|
|
201
|
+
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
|
|
202
|
+
|
|
203
|
+
// Enforce nullish coalescing over short-circuiting
|
|
204
|
+
// https://typescript-eslint.io/rules/prefer-nullish-coalescing/
|
|
205
|
+
'@typescript-eslint/prefer-nullish-coalescing': [
|
|
206
|
+
'warn',
|
|
207
|
+
{
|
|
208
|
+
ignoreConditionalTests: true,
|
|
209
|
+
ignoreMixedLogicalExpressions: true,
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
|
|
213
|
+
// Prefer usage of as const over literal type
|
|
214
|
+
// https://typescript-eslint.io/rules/prefer-as-const/
|
|
215
|
+
'@typescript-eslint/prefer-as-const': 'error',
|
|
216
|
+
|
|
217
|
+
// Prevent unnecessary type arguments
|
|
218
|
+
// https://typescript-eslint.io/rules/no-unnecessary-type-arguments/
|
|
219
|
+
'@typescript-eslint/no-unnecessary-type-arguments': 'warn',
|
|
220
|
+
|
|
221
|
+
// Warns when a namespace qualifier is unnecessary
|
|
222
|
+
// https://typescript-eslint.io/rules/no-unnecessary-qualifier/
|
|
223
|
+
'@typescript-eslint/no-unnecessary-qualifier': 'warn',
|
|
224
|
+
|
|
225
|
+
// Disallow throwing literals as exceptions
|
|
226
|
+
// https://typescript-eslint.io/rules/no-throw-literal/
|
|
227
|
+
'@typescript-eslint/no-throw-literal': 'warn',
|
|
228
|
+
|
|
229
|
+
// Disallows invocation of require() in favor of import statements
|
|
230
|
+
// https://typescript-eslint.io/rules/no-require-imports/
|
|
231
|
+
'@typescript-eslint/no-require-imports': 'warn',
|
|
232
|
+
|
|
233
|
+
// Disallows the use of eval()-like methods
|
|
234
|
+
// https://typescript-eslint.io/rules/no-implied-eval/
|
|
235
|
+
'@typescript-eslint/no-implied-eval': 'error',
|
|
236
|
+
|
|
237
|
+
// Requires Array#sort calls to always provide a compareFunction
|
|
238
|
+
// https://typescript-eslint.io/rules/require-array-sort-compare/
|
|
239
|
+
'@typescript-eslint/require-array-sort-compare': 'error',
|
|
240
|
+
|
|
241
|
+
// Enforce explicit enum item values
|
|
242
|
+
// https://typescript-eslint.io/rules/prefer-enum-initializers/
|
|
243
|
+
'@typescript-eslint/prefer-enum-initializers': 'warn',
|
|
244
|
+
|
|
245
|
+
// Explicitly defines what a module scoped method returns
|
|
246
|
+
// https://typescript-eslint.io/rules/explicit-module-boundary-types/
|
|
247
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
248
|
+
|
|
249
|
+
// Disallow // @ts comments
|
|
250
|
+
// https://typescript-eslint.io/rules/ban-ts-comment/
|
|
251
|
+
'@typescript-eslint/ban-ts-comment': [
|
|
252
|
+
'error',
|
|
253
|
+
{
|
|
254
|
+
'ts-expect-error': 'allow-with-description',
|
|
255
|
+
'ts-ignore': true,
|
|
256
|
+
'ts-nocheck': true,
|
|
257
|
+
'ts-check': false,
|
|
258
|
+
minimumDescriptionLength: 3,
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
|
|
262
|
+
// Disallows unnecessary constraints on generic types
|
|
263
|
+
// https://typescript-eslint.io/rules/no-unnecessary-type-constraint/
|
|
264
|
+
'@typescript-eslint/no-unnecessary-type-constraint': 'warn',
|
|
265
|
+
|
|
266
|
+
// Enforces consistent usage of type imports
|
|
267
|
+
// https://typescript-eslint.io/rules/consistent-type-imports/
|
|
268
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
269
|
+
'warn',
|
|
270
|
+
{
|
|
271
|
+
prefer: 'type-imports',
|
|
272
|
+
disallowTypeAnnotations: false,
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
files: ['*.d.ts'],
|
|
279
|
+
rules: {
|
|
280
|
+
'import/order': 'off',
|
|
281
|
+
'import/no-duplicates': 'off',
|
|
282
|
+
'import/export': 'off',
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const confusingBrowserGlobals = require('confusing-browser-globals')
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
rules: {
|
|
5
|
+
// Disallow labels that share a name with a variable
|
|
6
|
+
// https://eslint.org/docs/rules/no-label-var
|
|
7
|
+
'no-label-var': 'error',
|
|
8
|
+
|
|
9
|
+
// Disallow specific globals
|
|
10
|
+
// https://eslint.org/docs/rules/no-restricted-globals
|
|
11
|
+
'no-restricted-globals': ['error', 'isFinite', 'isNaN'].concat(
|
|
12
|
+
confusingBrowserGlobals
|
|
13
|
+
),
|
|
14
|
+
|
|
15
|
+
// Disallow declaration of variables already declared in the outer scope
|
|
16
|
+
// https://eslint.org/docs/rules/no-shadow
|
|
17
|
+
'no-shadow': [
|
|
18
|
+
'error',
|
|
19
|
+
{
|
|
20
|
+
allow: ['done', 'next', 'resolve', 'reject', 'cb'],
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
|
|
24
|
+
// Disallow shadowing of names such as arguments
|
|
25
|
+
// https://eslint.org/docs/rules/no-shadow-restricted-names
|
|
26
|
+
'no-shadow-restricted-names': 'error',
|
|
27
|
+
|
|
28
|
+
// Disallow use of undefined when initializing variables
|
|
29
|
+
// https://eslint.org/docs/rules/no-undef-init
|
|
30
|
+
'no-undef-init': 'error',
|
|
31
|
+
|
|
32
|
+
// Disallow declaration of variables that are not used in the code
|
|
33
|
+
// https://eslint.org/docs/rules/no-unused-vars
|
|
34
|
+
'no-unused-vars': [
|
|
35
|
+
'error',
|
|
36
|
+
{
|
|
37
|
+
ignoreRestSiblings: true,
|
|
38
|
+
argsIgnorePattern: '_+',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
|
|
42
|
+
// Disallow use of variables before they are defined
|
|
43
|
+
// https://eslint.org/docs/rules/no-use-before-define
|
|
44
|
+
'no-use-before-define': [
|
|
45
|
+
'off',
|
|
46
|
+
{
|
|
47
|
+
functions: false,
|
|
48
|
+
classes: false,
|
|
49
|
+
variables: true,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
}
|