@automattic/eslint-plugin-wpvip 0.4.8 → 0.4.10
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/.eslintrc.js +1 -0
- package/configs/base.js +0 -1
- package/configs/formatting.js +110 -0
- package/configs/index.js +2 -0
- package/configs/javascript.js +69 -135
- package/configs/weak-javascript.js +44 -5
- package/configs/weak-testing.js +24 -0
- package/package.json +1 -1
package/.eslintrc.js
CHANGED
package/configs/base.js
CHANGED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
/**
|
|
3
|
+
* Please include a short description of the rule. For rules that downgrade or
|
|
4
|
+
* disable errors, include a brief justification or reasoning.
|
|
5
|
+
*/
|
|
6
|
+
rules: {
|
|
7
|
+
'array-bracket-spacing': [ 'error', 'always' ],
|
|
8
|
+
|
|
9
|
+
'arrow-parens': [ 'error', 'always' ],
|
|
10
|
+
|
|
11
|
+
'arrow-spacing': 'error',
|
|
12
|
+
|
|
13
|
+
'brace-style': [ 'error', '1tbs' ],
|
|
14
|
+
|
|
15
|
+
// Identifiers should be in camelCase. Object properties are excluded
|
|
16
|
+
// (including when destructuring) since they often come from external
|
|
17
|
+
// sources (like APIs).
|
|
18
|
+
camelcase: [
|
|
19
|
+
'error',
|
|
20
|
+
{
|
|
21
|
+
properties: 'never',
|
|
22
|
+
ignoreDestructuring: true,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
|
|
26
|
+
'comma-dangle': [ 'error', 'always-multiline' ],
|
|
27
|
+
|
|
28
|
+
'comma-spacing': 'error',
|
|
29
|
+
|
|
30
|
+
'comma-style': [ 'error', 'last' ],
|
|
31
|
+
|
|
32
|
+
'computed-property-spacing': [ 'error', 'always' ],
|
|
33
|
+
|
|
34
|
+
curly: [ 'error', 'all' ],
|
|
35
|
+
|
|
36
|
+
'dot-notation': 'error',
|
|
37
|
+
|
|
38
|
+
// Files must end in a newline.
|
|
39
|
+
'eol-last': [ 'error', 'always' ],
|
|
40
|
+
|
|
41
|
+
'func-call-spacing': 'error',
|
|
42
|
+
|
|
43
|
+
indent: [ 'error', 'tab', { SwitchCase: 1 } ],
|
|
44
|
+
|
|
45
|
+
'key-spacing': 'error',
|
|
46
|
+
|
|
47
|
+
'keyword-spacing': 'error',
|
|
48
|
+
|
|
49
|
+
// Lines containing code should be a maximum of 200 characters in length.
|
|
50
|
+
'max-len': [
|
|
51
|
+
'warn',
|
|
52
|
+
{
|
|
53
|
+
code: 200,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
|
|
57
|
+
'no-multi-spaces': 'error',
|
|
58
|
+
|
|
59
|
+
'no-multi-str': 'error',
|
|
60
|
+
|
|
61
|
+
'no-multiple-empty-lines': [ 'error', { max: 1 } ],
|
|
62
|
+
|
|
63
|
+
'no-trailing-spaces': 'error',
|
|
64
|
+
|
|
65
|
+
'no-whitespace-before-property': 'error',
|
|
66
|
+
|
|
67
|
+
'object-curly-spacing': [ 'error', 'always' ],
|
|
68
|
+
|
|
69
|
+
'object-shorthand': 'error',
|
|
70
|
+
|
|
71
|
+
'operator-linebreak': 'error',
|
|
72
|
+
|
|
73
|
+
'padded-blocks': [ 'error', 'never' ],
|
|
74
|
+
|
|
75
|
+
// Arrow functions should be used for function arguments and callbacks.
|
|
76
|
+
'prefer-arrow-callback': 'warn',
|
|
77
|
+
|
|
78
|
+
quotes: [
|
|
79
|
+
'error',
|
|
80
|
+
'single',
|
|
81
|
+
{ allowTemplateLiterals: true, avoidEscape: true },
|
|
82
|
+
],
|
|
83
|
+
|
|
84
|
+
'quote-props': [ 'error', 'as-needed' ],
|
|
85
|
+
|
|
86
|
+
semi: 'error',
|
|
87
|
+
|
|
88
|
+
'semi-spacing': 'error',
|
|
89
|
+
|
|
90
|
+
'space-before-blocks': [ 'error', 'always' ],
|
|
91
|
+
|
|
92
|
+
'space-before-function-paren': [
|
|
93
|
+
'error',
|
|
94
|
+
{ anonymous: 'never', named: 'never', asyncArrow: 'always' },
|
|
95
|
+
],
|
|
96
|
+
|
|
97
|
+
'space-in-parens': [ 'error', 'always' ],
|
|
98
|
+
|
|
99
|
+
'space-infix-ops': 'error',
|
|
100
|
+
|
|
101
|
+
'space-unary-ops': [ 'error', { overrides: { '!': true, yield: true } } ],
|
|
102
|
+
|
|
103
|
+
// Comments should always include consistent spacing for readability.
|
|
104
|
+
'spaced-comment': 'warn',
|
|
105
|
+
|
|
106
|
+
'template-curly-spacing': [ 'error', 'always' ],
|
|
107
|
+
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
package/configs/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
base: require( './base' ),
|
|
3
3
|
cli: require( './cli' ),
|
|
4
|
+
formatting: require( './formatting' ),
|
|
4
5
|
javascript: require( './javascript' ),
|
|
5
6
|
jsdoc: require( './jsdoc' ),
|
|
6
7
|
prettier: require( './prettier' ),
|
|
@@ -8,5 +9,6 @@ module.exports = {
|
|
|
8
9
|
testing: require( './testing' ),
|
|
9
10
|
typescript: require( './typescript' ),
|
|
10
11
|
'weak-javascript': require( './weak-javascript' ),
|
|
12
|
+
'weak-testing': require( './weak-testing' ),
|
|
11
13
|
'weak-typescript': require( './weak-typescript' ),
|
|
12
14
|
};
|
package/configs/javascript.js
CHANGED
|
@@ -29,6 +29,71 @@ module.exports = {
|
|
|
29
29
|
* disable errors, include a brief justification or reasoning.
|
|
30
30
|
*/
|
|
31
31
|
rules: {
|
|
32
|
+
// These rules are from eslint:recommended, but are enumerated here for
|
|
33
|
+
// visibility:
|
|
34
|
+
// https://github.com/eslint/eslint/blob/main/packages/js/src/configs/eslint-recommended.js
|
|
35
|
+
'constructor-super': 'error',
|
|
36
|
+
'for-direction': 'error',
|
|
37
|
+
'getter-return': 'error',
|
|
38
|
+
'no-async-promise-executor': 'error',
|
|
39
|
+
'no-case-declarations': 'error',
|
|
40
|
+
'no-class-assign': 'error',
|
|
41
|
+
'no-compare-neg-zero': 'error',
|
|
42
|
+
// 'no-cond-assign': 'error', // extended below
|
|
43
|
+
'no-const-assign': 'error',
|
|
44
|
+
'no-constant-condition': 'error',
|
|
45
|
+
'no-control-regex': 'error',
|
|
46
|
+
'no-debugger': 'error',
|
|
47
|
+
'no-delete-var': 'error',
|
|
48
|
+
'no-dupe-args': 'error',
|
|
49
|
+
'no-dupe-class-members': 'error',
|
|
50
|
+
'no-dupe-else-if': 'error',
|
|
51
|
+
'no-dupe-keys': 'error',
|
|
52
|
+
'no-duplicate-case': 'error',
|
|
53
|
+
// 'no-empty': 'error', // extended below
|
|
54
|
+
'no-empty-character-class': 'error',
|
|
55
|
+
'no-empty-pattern': 'error',
|
|
56
|
+
'no-ex-assign': 'error',
|
|
57
|
+
'no-extra-boolean-cast': 'error',
|
|
58
|
+
'no-extra-semi': 'error',
|
|
59
|
+
'no-fallthrough': 'error',
|
|
60
|
+
'no-func-assign': 'error',
|
|
61
|
+
'no-global-assign': 'error',
|
|
62
|
+
'no-import-assign': 'error',
|
|
63
|
+
'no-inner-declarations': 'error',
|
|
64
|
+
'no-invalid-regexp': 'error',
|
|
65
|
+
'no-irregular-whitespace': 'error',
|
|
66
|
+
'no-loss-of-precision': 'error',
|
|
67
|
+
'no-misleading-character-class': 'error',
|
|
68
|
+
'no-mixed-spaces-and-tabs': 'error',
|
|
69
|
+
'no-new-symbol': 'error',
|
|
70
|
+
'no-nonoctal-decimal-escape': 'error',
|
|
71
|
+
'no-obj-calls': 'error',
|
|
72
|
+
'no-octal': 'error',
|
|
73
|
+
'no-prototype-builtins': 'error',
|
|
74
|
+
'no-redeclare': 'error',
|
|
75
|
+
'no-regex-spaces': 'error',
|
|
76
|
+
'no-self-assign': 'error',
|
|
77
|
+
'no-setter-return': 'error',
|
|
78
|
+
'no-shadow-restricted-names': 'error',
|
|
79
|
+
'no-sparse-arrays': 'error',
|
|
80
|
+
'no-this-before-super': 'error',
|
|
81
|
+
'no-undef': 'error',
|
|
82
|
+
'no-unexpected-multiline': 'error',
|
|
83
|
+
'no-unreachable': 'error',
|
|
84
|
+
'no-unsafe-finally': 'error',
|
|
85
|
+
'no-unsafe-negation': 'error',
|
|
86
|
+
'no-unsafe-optional-chaining': 'error',
|
|
87
|
+
'no-unused-labels': 'error',
|
|
88
|
+
// 'no-unused-vars': 'error', // extended below
|
|
89
|
+
'no-useless-backreference': 'error',
|
|
90
|
+
'no-useless-catch': 'error',
|
|
91
|
+
'no-useless-escape': 'error',
|
|
92
|
+
'no-with': 'error',
|
|
93
|
+
'require-yield': 'error',
|
|
94
|
+
'use-isnan': 'error',
|
|
95
|
+
// 'valid-typeof': 'error', // extended below
|
|
96
|
+
|
|
32
97
|
// Async/await must not be used in a `.forEach` method, because the result
|
|
33
98
|
// will not be awaited in the outer scope.
|
|
34
99
|
'@automattic/wpvip/no-async-foreach': 'error',
|
|
@@ -40,51 +105,13 @@ module.exports = {
|
|
|
40
105
|
// Unguarded getRangeAt calls can throw errors in some browsers.
|
|
41
106
|
'@automattic/wpvip/no-unguarded-get-range-at': 'error',
|
|
42
107
|
|
|
43
|
-
'array-bracket-spacing': [ 'error', 'always' ],
|
|
44
|
-
|
|
45
108
|
'array-callback-return': 'error',
|
|
46
109
|
|
|
47
|
-
'arrow-parens': [ 'error', 'always' ],
|
|
48
|
-
|
|
49
|
-
'arrow-spacing': 'error',
|
|
50
|
-
|
|
51
|
-
'brace-style': [ 'error', '1tbs' ],
|
|
52
|
-
|
|
53
|
-
// Identifiers should be in camelCase. Object properties are excluded
|
|
54
|
-
// (including when destructuring) since they often come from external
|
|
55
|
-
// sources (like APIs).
|
|
56
|
-
camelcase: [
|
|
57
|
-
'error',
|
|
58
|
-
{
|
|
59
|
-
properties: 'never',
|
|
60
|
-
ignoreDestructuring: true,
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
|
|
64
|
-
'comma-dangle': [ 'error', 'always-multiline' ],
|
|
65
|
-
|
|
66
|
-
'comma-spacing': 'error',
|
|
67
|
-
|
|
68
|
-
'comma-style': [ 'error', 'last' ],
|
|
69
|
-
|
|
70
110
|
// Maximum cyclomatic complexity must not be above 20.
|
|
71
111
|
complexity: 'error',
|
|
72
112
|
|
|
73
|
-
'computed-property-spacing': [ 'error', 'always' ],
|
|
74
|
-
|
|
75
|
-
'constructor-super': 'error',
|
|
76
|
-
|
|
77
|
-
curly: [ 'error', 'all' ],
|
|
78
|
-
|
|
79
|
-
'dot-notation': 'error',
|
|
80
|
-
|
|
81
|
-
// Files must end in a newline.
|
|
82
|
-
'eol-last': [ 'error', 'always' ],
|
|
83
|
-
|
|
84
113
|
eqeqeq: 'error',
|
|
85
114
|
|
|
86
|
-
'func-call-spacing': 'error',
|
|
87
|
-
|
|
88
115
|
// Identifiers should be between 2 and 40 characters in length in order to
|
|
89
116
|
// provide a concise semantic meaning.
|
|
90
117
|
'id-length': [
|
|
@@ -108,22 +135,10 @@ module.exports = {
|
|
|
108
135
|
|
|
109
136
|
'import/no-unresolved': 'error',
|
|
110
137
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
'key-spacing': 'error',
|
|
114
|
-
|
|
115
|
-
'keyword-spacing': 'error',
|
|
116
|
-
|
|
138
|
+
// Enforce Unix linebreaks. Included here and not in "formatting" since it
|
|
139
|
+
// is not controversial and helps with interchange.
|
|
117
140
|
'linebreak-style': [ 'error', 'unix' ],
|
|
118
141
|
|
|
119
|
-
// Lines containing code should be a maximum of 200 characters in length.
|
|
120
|
-
'max-len': [
|
|
121
|
-
'warn',
|
|
122
|
-
{
|
|
123
|
-
code: 200,
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
|
|
127
142
|
'no-alert': 'error',
|
|
128
143
|
|
|
129
144
|
// Async/await must not be used in a loop, because it leads to sequential
|
|
@@ -140,64 +155,28 @@ module.exports = {
|
|
|
140
155
|
// logging function that logs on your behalf (and ignore this rule there).
|
|
141
156
|
'no-console': 'warn',
|
|
142
157
|
|
|
143
|
-
'no-const-assign': 'error',
|
|
144
|
-
|
|
145
|
-
'no-debugger': 'error',
|
|
146
|
-
|
|
147
|
-
'no-dupe-args': 'error',
|
|
148
|
-
|
|
149
|
-
'no-dupe-class-members': 'error',
|
|
150
|
-
|
|
151
|
-
'no-dupe-keys': 'error',
|
|
152
|
-
|
|
153
|
-
'no-duplicate-case': 'error',
|
|
154
|
-
|
|
155
158
|
// A single `import` statement should be used when importing multiple things
|
|
156
159
|
// from a module.
|
|
157
160
|
'no-duplicate-imports': 'error',
|
|
158
161
|
|
|
159
162
|
'no-else-return': 'error',
|
|
160
163
|
|
|
164
|
+
'no-empty': [ 'error', { allowEmptyCatch: true } ],
|
|
165
|
+
|
|
161
166
|
'no-eq-null': 'error',
|
|
162
167
|
|
|
163
168
|
'no-eval': 'error',
|
|
164
169
|
|
|
165
|
-
'no-extra-semi': 'error',
|
|
166
|
-
|
|
167
|
-
'no-fallthrough': 'error',
|
|
168
|
-
|
|
169
|
-
'no-irregular-whitespace': 'error',
|
|
170
|
-
|
|
171
170
|
'no-lonely-if': 'error',
|
|
172
171
|
|
|
173
172
|
'no-mixed-operators': 'error',
|
|
174
173
|
|
|
175
|
-
'no-mixed-spaces-and-tabs': 'error',
|
|
176
|
-
|
|
177
|
-
'no-multi-spaces': 'error',
|
|
178
|
-
|
|
179
|
-
'no-multi-str': 'error',
|
|
180
|
-
|
|
181
|
-
'no-multiple-empty-lines': [ 'error', { max: 1 } ],
|
|
182
|
-
|
|
183
174
|
'no-nested-ternary': 'error',
|
|
184
175
|
|
|
185
|
-
'no-redeclare': 'error',
|
|
186
|
-
|
|
187
176
|
'no-shadow': 'error',
|
|
188
177
|
|
|
189
|
-
'no-trailing-spaces': 'error',
|
|
190
|
-
|
|
191
|
-
'no-undef': 'error',
|
|
192
|
-
|
|
193
178
|
'no-undef-init': 'error',
|
|
194
179
|
|
|
195
|
-
'no-unreachable': 'error',
|
|
196
|
-
|
|
197
|
-
// Negating the left operand of a statment frequently leads to logical
|
|
198
|
-
// errors. Example: `!key in obj` vs. `!(key in obj)`.
|
|
199
|
-
'no-unsafe-negation': 'error',
|
|
200
|
-
|
|
201
180
|
'no-unused-expressions': 'error',
|
|
202
181
|
|
|
203
182
|
'no-unused-vars': [ 'error', { ignoreRestSiblings: true } ],
|
|
@@ -210,57 +189,12 @@ module.exports = {
|
|
|
210
189
|
|
|
211
190
|
'no-var': 'error',
|
|
212
191
|
|
|
213
|
-
'no-whitespace-before-property': 'error',
|
|
214
|
-
|
|
215
|
-
'no-with': 'error',
|
|
216
|
-
|
|
217
|
-
'object-curly-spacing': [ 'error', 'always' ],
|
|
218
|
-
|
|
219
|
-
'object-shorthand': 'error',
|
|
220
|
-
|
|
221
192
|
'one-var': [ 'error', 'never' ],
|
|
222
193
|
|
|
223
|
-
'operator-linebreak': 'error',
|
|
224
|
-
|
|
225
|
-
'padded-blocks': [ 'error', 'never' ],
|
|
226
|
-
|
|
227
|
-
// Arrow functions should be used for function arguments and callbacks.
|
|
228
|
-
'prefer-arrow-callback': 'warn',
|
|
229
|
-
|
|
230
194
|
'prefer-const': [ 'error', { destructuring: 'all' } ],
|
|
231
195
|
|
|
232
196
|
radix: 'error',
|
|
233
197
|
|
|
234
|
-
quotes: [
|
|
235
|
-
'error',
|
|
236
|
-
'single',
|
|
237
|
-
{ allowTemplateLiterals: true, avoidEscape: true },
|
|
238
|
-
],
|
|
239
|
-
|
|
240
|
-
'quote-props': [ 'error', 'as-needed' ],
|
|
241
|
-
|
|
242
|
-
semi: 'error',
|
|
243
|
-
|
|
244
|
-
'semi-spacing': 'error',
|
|
245
|
-
|
|
246
|
-
'space-before-blocks': [ 'error', 'always' ],
|
|
247
|
-
|
|
248
|
-
'space-before-function-paren': [
|
|
249
|
-
'error',
|
|
250
|
-
{ anonymous: 'never', named: 'never', asyncArrow: 'always' },
|
|
251
|
-
],
|
|
252
|
-
|
|
253
|
-
'space-in-parens': [ 'error', 'always' ],
|
|
254
|
-
|
|
255
|
-
'space-infix-ops': 'error',
|
|
256
|
-
|
|
257
|
-
'space-unary-ops': [ 'error', { overrides: { '!': true, yield: true } } ],
|
|
258
|
-
|
|
259
|
-
// Comments should always include consistent spacing for readability.
|
|
260
|
-
'spaced-comment': 'warn',
|
|
261
|
-
|
|
262
|
-
'template-curly-spacing': [ 'error', 'always' ],
|
|
263
|
-
|
|
264
198
|
// The result of `typeof` must always be compared to a literal string.
|
|
265
199
|
'valid-typeof': [
|
|
266
200
|
'error',
|
|
@@ -7,9 +7,48 @@
|
|
|
7
7
|
* temporary basis.
|
|
8
8
|
*/
|
|
9
9
|
module.exports = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
overrides: [
|
|
11
|
+
{
|
|
12
|
+
// Don't apply weak rules to TypeScript files.
|
|
13
|
+
files: [ '**/*.js', '**/*.jsx' ],
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Downgrade rules from the base preset to "warn". Do not disable rules (set
|
|
17
|
+
* to "off"). If a rule is already set to a warning, do not disable it.
|
|
18
|
+
*/
|
|
19
|
+
rules: {
|
|
20
|
+
'@automattic/wpvip/no-unused-vars-before-return': 'warn',
|
|
21
|
+
|
|
22
|
+
complexity: 'warn',
|
|
23
|
+
|
|
24
|
+
eqeqeq: 'warn',
|
|
25
|
+
|
|
26
|
+
'object-shorthand': 'warn',
|
|
27
|
+
|
|
28
|
+
'no-async-promise-executor': 'warn',
|
|
29
|
+
|
|
30
|
+
'no-await-in-loop': 'warn',
|
|
31
|
+
|
|
32
|
+
'no-case-declarations': 'warn',
|
|
33
|
+
|
|
34
|
+
'no-else-return': 'warn',
|
|
35
|
+
|
|
36
|
+
'no-mixed-operators': 'warn',
|
|
37
|
+
|
|
38
|
+
'no-prototype-builtins': 'warn',
|
|
39
|
+
|
|
40
|
+
'no-shadow': 'warn',
|
|
41
|
+
|
|
42
|
+
'no-unused-vars': 'warn',
|
|
43
|
+
|
|
44
|
+
'no-useless-escape': 'warn',
|
|
45
|
+
|
|
46
|
+
'no-var': 'warn',
|
|
47
|
+
|
|
48
|
+
'one-var': 'warn',
|
|
49
|
+
|
|
50
|
+
radix: 'warn',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
15
54
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Weak" testing rules
|
|
3
|
+
* ====================
|
|
4
|
+
* These rules are intended for codebases that are transitioning to the stronger
|
|
5
|
+
* testing preset but need weaker rules to prevent a massive number of changes.
|
|
6
|
+
* They do not provide good protection or standardization, but can useful on a
|
|
7
|
+
* temporary basis.
|
|
8
|
+
*/
|
|
9
|
+
module.exports = {
|
|
10
|
+
/**
|
|
11
|
+
* Downgrade rules from the testing preset to "warn". Do not disable rules
|
|
12
|
+
* (set to "off"). If a rule is already set to a warning, do not disable it.
|
|
13
|
+
*/
|
|
14
|
+
rules: {
|
|
15
|
+
'jest/no-alias-methods': 'warn',
|
|
16
|
+
|
|
17
|
+
'jest/no-done-callback': 'warn',
|
|
18
|
+
|
|
19
|
+
'jest/no-conditional-expect': 'warn',
|
|
20
|
+
|
|
21
|
+
'jest/no-standalone-expect': 'warn',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|