@arcgis/eslint-config 5.2.0-next.15 → 5.2.0-next.151
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/LICENSE.md +4 -2
- package/README.md +2 -2
- package/dist/chunks/disabledRules.js +6 -0
- package/dist/{estree-CDc-die8.js → chunks/estree.js} +8 -6
- package/dist/{makePlugin-C2bqt5zI.js → chunks/makePlugin.js} +6 -2
- package/dist/config/applications.js +31 -29
- package/dist/config/core.js +824 -0
- package/dist/config/extra.js +9 -10
- package/dist/config/index.js +518 -460
- package/dist/config/lumina.js +17 -34
- package/dist/plugins/core/index.js +75 -33
- package/dist/plugins/lumina/index.js +63 -32
- package/dist/plugins/utils/makePlugin.d.ts +17 -0
- package/dist/plugins/webgis/index.js +171 -31
- package/dist/utils/disableRules.d.ts +3 -2
- package/dist/utils/disableRules.js +1 -1
- package/package.json +15 -10
package/dist/config/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as jsoncParser from "jsonc-eslint-parser";
|
|
2
2
|
import tsEslint from "typescript-eslint";
|
|
3
3
|
import restrictedGlobals from "confusing-browser-globals";
|
|
4
4
|
import globals from "globals";
|
|
@@ -7,24 +7,104 @@ import { globalIgnores } from "eslint/config";
|
|
|
7
7
|
import markdown from "@eslint/markdown";
|
|
8
8
|
import packageJson from "eslint-plugin-package-json";
|
|
9
9
|
import { importX } from "eslint-plugin-import-x";
|
|
10
|
+
import { createTypeScriptImportResolver } from "eslint-import-resolver-typescript";
|
|
10
11
|
const packageJsonSortableCollections = packageJson.rules["sort-collections"].meta.defaultOptions[0].filter(
|
|
11
12
|
(collection) => !["scripts", "exports"].includes(collection)
|
|
12
13
|
) ?? [];
|
|
14
|
+
const { "import-x/resolver": legacyResolver, ...importXTypeScriptSettings } = importX.flatConfigs.typescript.settings;
|
|
15
|
+
const markdownLanguageOptions = {
|
|
16
|
+
frontmatter: "yaml"
|
|
17
|
+
};
|
|
13
18
|
const config = [
|
|
14
19
|
globalIgnores(["**/www", "**/dist", "**/assets", "**/coverage", "**/.docs"]),
|
|
15
20
|
{
|
|
21
|
+
// TODO: align the config between .js and .ts file, or drop .js files support entirely
|
|
22
|
+
// As it stands these rules contradict .ts config, or add redundant checks
|
|
23
|
+
// Plus, monorepo disables eslint for .js files so these don't even run
|
|
16
24
|
files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
|
|
17
|
-
|
|
25
|
+
rules: {
|
|
26
|
+
"constructor-super": "error",
|
|
27
|
+
"for-direction": "error",
|
|
28
|
+
"getter-return": "error",
|
|
29
|
+
"no-async-promise-executor": "error",
|
|
30
|
+
"no-case-declarations": "error",
|
|
31
|
+
"no-class-assign": "error",
|
|
32
|
+
"no-compare-neg-zero": "error",
|
|
33
|
+
"no-cond-assign": "error",
|
|
34
|
+
"no-const-assign": "error",
|
|
35
|
+
"no-constant-binary-expression": "error",
|
|
36
|
+
"no-constant-condition": "error",
|
|
37
|
+
"no-control-regex": "error",
|
|
38
|
+
"no-debugger": "error",
|
|
39
|
+
"no-delete-var": "error",
|
|
40
|
+
"no-dupe-args": "error",
|
|
41
|
+
"no-dupe-class-members": "error",
|
|
42
|
+
"no-dupe-else-if": "error",
|
|
43
|
+
"no-dupe-keys": "error",
|
|
44
|
+
"no-duplicate-case": "error",
|
|
45
|
+
"no-empty": "error",
|
|
46
|
+
"no-empty-character-class": "error",
|
|
47
|
+
"no-empty-pattern": "error",
|
|
48
|
+
"no-empty-static-block": "error",
|
|
49
|
+
"no-ex-assign": "error",
|
|
50
|
+
"no-extra-boolean-cast": "error",
|
|
51
|
+
"no-fallthrough": "error",
|
|
52
|
+
"no-func-assign": "error",
|
|
53
|
+
"no-global-assign": "error",
|
|
54
|
+
"no-import-assign": "error",
|
|
55
|
+
"no-invalid-regexp": "error",
|
|
56
|
+
"no-irregular-whitespace": "error",
|
|
57
|
+
"no-loss-of-precision": "error",
|
|
58
|
+
"no-misleading-character-class": "error",
|
|
59
|
+
"no-new-native-nonconstructor": "error",
|
|
60
|
+
"no-nonoctal-decimal-escape": "error",
|
|
61
|
+
"no-obj-calls": "error",
|
|
62
|
+
"no-octal": "error",
|
|
63
|
+
"no-prototype-builtins": "error",
|
|
64
|
+
"no-redeclare": "error",
|
|
65
|
+
"no-regex-spaces": "error",
|
|
66
|
+
"no-self-assign": "error",
|
|
67
|
+
"no-setter-return": "error",
|
|
68
|
+
"no-shadow-restricted-names": "error",
|
|
69
|
+
"no-sparse-arrays": "error",
|
|
70
|
+
"no-this-before-super": "error",
|
|
71
|
+
"no-unassigned-vars": "error",
|
|
72
|
+
"no-undef": "error",
|
|
73
|
+
"no-unexpected-multiline": "error",
|
|
74
|
+
"no-unreachable": "error",
|
|
75
|
+
"no-unsafe-finally": "error",
|
|
76
|
+
"no-unsafe-negation": "error",
|
|
77
|
+
"no-unsafe-optional-chaining": "error",
|
|
78
|
+
"no-unused-labels": "error",
|
|
79
|
+
"no-unused-private-class-members": "error",
|
|
80
|
+
"no-unused-vars": "error",
|
|
81
|
+
"no-useless-assignment": "error",
|
|
82
|
+
"no-useless-backreference": "error",
|
|
83
|
+
"no-useless-catch": "error",
|
|
84
|
+
"no-useless-escape": "error",
|
|
85
|
+
"no-with": "error",
|
|
86
|
+
"preserve-caught-error": "error",
|
|
87
|
+
"require-yield": "error",
|
|
88
|
+
"use-isnan": "error",
|
|
89
|
+
"valid-typeof": "error"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
files: ["**/*.ts", "**/*.tsx"],
|
|
94
|
+
languageOptions: { parser: tsEslint.parser, sourceType: "module" },
|
|
95
|
+
plugins: { "@typescript-eslint": tsEslint.plugin }
|
|
18
96
|
},
|
|
19
|
-
...[...tsEslint.configs.strictTypeChecked, ...tsEslint.configs.stylisticTypeChecked].map((config2) => ({
|
|
20
|
-
...config2,
|
|
21
|
-
files: ["**/*.ts", "**/*.tsx"]
|
|
22
|
-
})),
|
|
23
97
|
{
|
|
24
98
|
...webgisPlugin.configs.recommended,
|
|
25
99
|
files: ["**/*.ts", "**/*.tsx"]
|
|
26
100
|
},
|
|
27
|
-
|
|
101
|
+
{
|
|
102
|
+
plugins: { "import-x": importX },
|
|
103
|
+
settings: {
|
|
104
|
+
...importXTypeScriptSettings,
|
|
105
|
+
"import-x/resolver-next": [createTypeScriptImportResolver()]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
28
108
|
{
|
|
29
109
|
files: ["**/*.ts", "**/*.tsx"],
|
|
30
110
|
linterOptions: {
|
|
@@ -40,139 +120,320 @@ const config = [
|
|
|
40
120
|
sourceType: "module"
|
|
41
121
|
},
|
|
42
122
|
rules: {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
"off",
|
|
53
|
-
// This configuration matches TypeScript
|
|
123
|
+
// Require that all overloads for the same method are next to each other in the class
|
|
124
|
+
"@typescript-eslint/adjacent-overload-signatures": "error",
|
|
125
|
+
// Use T[] over Array<T> for consistency
|
|
126
|
+
"@typescript-eslint/array-type": ["warn"],
|
|
127
|
+
// Forbid await of non-promise value
|
|
128
|
+
"@typescript-eslint/await-thenable": "error",
|
|
129
|
+
// Encourage safer ts directive comments, and encourage providing why? comments
|
|
130
|
+
"@typescript-eslint/ban-ts-comment": [
|
|
131
|
+
"error",
|
|
54
132
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
varsIgnorePattern: "^(_|(h|Fragment)$)"
|
|
133
|
+
"ts-expect-error": "allow-with-description",
|
|
134
|
+
"ts-ignore": false,
|
|
135
|
+
"ts-nocheck": "allow-with-description",
|
|
136
|
+
"ts-check": true,
|
|
137
|
+
"minimumDescriptionLength": 3
|
|
61
138
|
}
|
|
62
139
|
],
|
|
63
|
-
//
|
|
64
|
-
"
|
|
65
|
-
//
|
|
66
|
-
"
|
|
67
|
-
// TypeScript
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"@typescript-eslint/
|
|
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
|
-
"no-
|
|
150
|
-
|
|
151
|
-
"no-
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
140
|
+
// Use a=new Set<T> over a:Set<T>=new Set()
|
|
141
|
+
"@typescript-eslint/consistent-generic-constructors": "error",
|
|
142
|
+
// Use Record<string,string> over {[x in string]: string} for consistency
|
|
143
|
+
"@typescript-eslint/consistent-indexed-object-style": "error",
|
|
144
|
+
// Use `a as b` over `<b>a` TypeScript type casting syntax
|
|
145
|
+
"@typescript-eslint/consistent-type-assertions": [
|
|
146
|
+
"warn",
|
|
147
|
+
{
|
|
148
|
+
assertionStyle: "as",
|
|
149
|
+
// In some cases object literal type assertions are necessary
|
|
150
|
+
objectLiteralTypeAssertions: "allow-as-parameter"
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
// Require `type` keyword when exporting/reexporting types for compatibility
|
|
154
|
+
"@typescript-eslint/consistent-type-exports": ["warn", { fixMixedExportsWithInlineTypeSpecifier: true }],
|
|
155
|
+
"@typescript-eslint/consistent-type-imports": [
|
|
156
|
+
"warn",
|
|
157
|
+
{
|
|
158
|
+
prefer: "type-imports",
|
|
159
|
+
fixStyle: "inline-type-imports",
|
|
160
|
+
// Type imports are necessary in namespaces and global augmentations
|
|
161
|
+
disallowTypeAnnotations: false
|
|
162
|
+
}
|
|
163
|
+
],
|
|
164
|
+
// Prefer a.b over a["b"]
|
|
165
|
+
"@typescript-eslint/dot-notation": "warn",
|
|
166
|
+
"@typescript-eslint/explicit-function-return-type": [
|
|
167
|
+
// Providing explicit type improves type-checking performance and
|
|
168
|
+
// catches bugs (when actual return type is not what you are expecting,
|
|
169
|
+
// or return type changed accidentally during incorrect refactoring).
|
|
170
|
+
// It also improves code documentation
|
|
171
|
+
// In some cases, explicit type would be very bloated/complicated (i.e in
|
|
172
|
+
// case of mixins), thus you can silence this rule in those cases
|
|
173
|
+
"error",
|
|
174
|
+
{
|
|
175
|
+
allowConciseArrowFunctionExpressionsStartingWithVoid: true
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
// Error if function has 6+ params. Encourage objects instead (easier to
|
|
179
|
+
// add/remove properties without breaking changes, and less bug prone) or
|
|
180
|
+
// smaller functions.
|
|
181
|
+
// TODO: Subjective, and copilot autofixes this badly - needs more discussion.
|
|
182
|
+
"@typescript-eslint/max-params": ["warn", { max: 5 }],
|
|
183
|
+
// "property" style is more type-safe then "method" (has covariance checks)
|
|
184
|
+
"@typescript-eslint/method-signature-style": "warn",
|
|
185
|
+
"@typescript-eslint/naming-convention": [
|
|
186
|
+
"error",
|
|
187
|
+
{
|
|
188
|
+
/*
|
|
189
|
+
* Use camelCase and PascalCase by default
|
|
190
|
+
* Pascal case is allowed because, despite variable names
|
|
191
|
+
* commonly starting with lower case, there are use cases for
|
|
192
|
+
* capital letter:
|
|
193
|
+
* - functional components
|
|
194
|
+
* - React contexts
|
|
195
|
+
* - constructors/dynamically created classes/mixins
|
|
196
|
+
* - enum-like config objects
|
|
197
|
+
*/
|
|
198
|
+
selector: "default",
|
|
199
|
+
format: ["camelCase", "PascalCase"],
|
|
200
|
+
// Denotes unused variables. Also may denote private members
|
|
201
|
+
leadingUnderscore: "allow",
|
|
202
|
+
trailingUnderscore: "forbid"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
// TypeLike must be in PascalCase
|
|
206
|
+
selector: "typeLike",
|
|
207
|
+
format: ["PascalCase"]
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
// Relax restrictions for keys like `en-US` and etc.
|
|
211
|
+
selector: "default",
|
|
212
|
+
modifiers: ["requiresQuotes"],
|
|
213
|
+
format: null
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
// Enum members should be in upper case
|
|
217
|
+
selector: "enumMember",
|
|
218
|
+
format: ["UPPER_CASE"]
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
"@typescript-eslint/no-array-constructor": ["warn"],
|
|
222
|
+
"@typescript-eslint/no-array-delete": "error",
|
|
223
|
+
// Forbid !a==b when a!=b was meant
|
|
224
|
+
"@typescript-eslint/no-confusing-non-null-assertion": "error",
|
|
225
|
+
// Catch duplicate union members
|
|
226
|
+
"@typescript-eslint/no-duplicate-type-constituents": ["warn"],
|
|
227
|
+
// Forbid `delete` in favor of Map()
|
|
228
|
+
"@typescript-eslint/no-dynamic-delete": "error",
|
|
229
|
+
// If function is empty, require explanation comment
|
|
230
|
+
// False positives:
|
|
231
|
+
// There can be use cases for this (when providing a callback is required
|
|
232
|
+
// but you don't want to do anything)
|
|
233
|
+
"@typescript-eslint/no-empty-function": [
|
|
234
|
+
"warn",
|
|
235
|
+
{
|
|
236
|
+
allow: ["decoratedFunctions", "overrideMethods"]
|
|
237
|
+
}
|
|
238
|
+
],
|
|
239
|
+
// Disallow using {} as a type because it means non-nullish `any` rather than empty object
|
|
240
|
+
"@typescript-eslint/no-empty-object-type": ["warn", { allowInterfaces: "with-single-extends" }],
|
|
241
|
+
// TODO: turn this into an error. Discuss with the team why "any" defeats the purpose and benefits of TypeScript.
|
|
242
|
+
// To get all benefits of TypeScript, you have to go all full-in. Use of any
|
|
243
|
+
// may indicate poor code quality, or lack of understanding of TypeScript.
|
|
244
|
+
// In extreme cases, "unknown" should be used instead of any. There are
|
|
245
|
+
// virtually no correct use cases of any
|
|
246
|
+
// TODO: This needs to be resolved before resolving implicit any
|
|
247
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
248
|
+
// Forbid duplicate !! non null assertion - possible bug
|
|
249
|
+
"@typescript-eslint/no-extra-non-null-assertion": ["warn"],
|
|
250
|
+
// Encourage objects over static classes.
|
|
251
|
+
// TODO: consider dropping (like in core) because class properties are
|
|
252
|
+
// easier to mark readonly than in objects, and classes are better
|
|
253
|
+
// supported in the docs
|
|
254
|
+
"@typescript-eslint/no-extraneous-class": "error",
|
|
255
|
+
// TODO: discuss more
|
|
256
|
+
// Enabled by default, but this was disabled in component packages per
|
|
257
|
+
// feedback from contributors saying it was too annoying.
|
|
258
|
+
// Also, DOM APIs prefer uncaught exceptions, so floating promises are
|
|
259
|
+
// fine in some cases, especially in web components
|
|
260
|
+
"@typescript-eslint/no-floating-promises": ["warn", { ignoreVoid: true }],
|
|
261
|
+
// Forbid eval()-like functions
|
|
262
|
+
"@typescript-eslint/no-implied-eval": "error",
|
|
263
|
+
"@typescript-eslint/no-import-type-side-effects": "error",
|
|
264
|
+
// Prefer `a = 1` over `a: number = 1`
|
|
265
|
+
"@typescript-eslint/no-inferrable-types": ["warn"],
|
|
266
|
+
"@typescript-eslint/no-meaningless-void-operator": "warn",
|
|
267
|
+
// Catch accidental new(){} in classes when constructor(){} was meant
|
|
268
|
+
"@typescript-eslint/no-misused-new": "error",
|
|
269
|
+
"@typescript-eslint/no-misused-promises": [
|
|
270
|
+
"warn",
|
|
271
|
+
{
|
|
272
|
+
// Redundant with TypeScript
|
|
273
|
+
checksSpreads: false,
|
|
274
|
+
checksVoidReturn: {
|
|
275
|
+
arguments: true,
|
|
276
|
+
// Allow for patterns like ref={focusElement}
|
|
277
|
+
attributes: false,
|
|
278
|
+
inheritedMethods: true,
|
|
279
|
+
properties: true,
|
|
280
|
+
returns: true,
|
|
281
|
+
variables: true
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
],
|
|
285
|
+
// Forbid spread of non-spreadable - may indicate forgotten `await`
|
|
286
|
+
"@typescript-eslint/no-misused-spread": "error",
|
|
287
|
+
// Forbid `foo! ?? bar` (non null with a null check)
|
|
288
|
+
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
|
|
289
|
+
// Disallow foo?.bar! (nullable asserted as non-nullable)
|
|
290
|
+
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
|
|
291
|
+
// Catch loss of type precision when `any` in a union overrides all other members
|
|
292
|
+
"@typescript-eslint/no-redundant-type-constituents": "error",
|
|
293
|
+
"@typescript-eslint/no-require-imports": "warn",
|
|
294
|
+
"@typescript-eslint/no-restricted-imports": [
|
|
295
|
+
"error",
|
|
296
|
+
{
|
|
297
|
+
paths: [
|
|
298
|
+
{
|
|
299
|
+
name: "commander",
|
|
300
|
+
importNames: ["Command"],
|
|
301
|
+
message: "Import from @commander-js/extra-typings instead."
|
|
302
|
+
}
|
|
303
|
+
]
|
|
304
|
+
}
|
|
305
|
+
],
|
|
306
|
+
// Use `if(a)` over `if(a===true)` for strictly boolean values - autofixable
|
|
307
|
+
"@typescript-eslint/no-unnecessary-boolean-literal-compare": ["warn"],
|
|
308
|
+
"@typescript-eslint/no-unnecessary-condition": "error",
|
|
309
|
+
// Use "a" over `${"a"}`;
|
|
310
|
+
"@typescript-eslint/no-unnecessary-template-expression": "error",
|
|
311
|
+
// Remove needless `extends any` in type parameters
|
|
312
|
+
"@typescript-eslint/no-unnecessary-type-constraint": "error",
|
|
313
|
+
// Disallow needless runtim type cast
|
|
314
|
+
"@typescript-eslint/no-unnecessary-type-conversion": "warn",
|
|
315
|
+
// Catch passing any value to function
|
|
316
|
+
"@typescript-eslint/no-unsafe-argument": "error",
|
|
317
|
+
// Catch assignment of any value
|
|
318
|
+
"@typescript-eslint/no-unsafe-assignment": "error",
|
|
319
|
+
// Catch call of any function
|
|
320
|
+
"@typescript-eslint/no-unsafe-call": "error",
|
|
321
|
+
// Forbid using the `Function` type which stands for `any function`
|
|
322
|
+
"@typescript-eslint/no-unsafe-function-type": "error",
|
|
323
|
+
// Catch property access on any
|
|
324
|
+
"@typescript-eslint/no-unsafe-member-access": "error",
|
|
325
|
+
"@typescript-eslint/no-unsafe-unary-minus": "error",
|
|
326
|
+
"@typescript-eslint/no-unused-expressions": "error",
|
|
327
|
+
// TODO: disable because Conflicts with API Extractor. export{} is needed
|
|
328
|
+
// sometimes to disambiguate module jsdoc from first declaration's jsdoc
|
|
329
|
+
"@typescript-eslint/no-useless-empty-export": "warn",
|
|
330
|
+
// Require `string` type over `String`. String is almost never intended
|
|
331
|
+
"@typescript-eslint/no-wrapper-object-types": "error",
|
|
332
|
+
// Use ! over `as T` for non-null casts as it is less type unsafe
|
|
333
|
+
"@typescript-eslint/non-nullable-type-assertion-style": ["warn"],
|
|
334
|
+
// Throw only Error objects to preserve stack trace.
|
|
335
|
+
// TODO: consider dropping due to many false positives and requires
|
|
336
|
+
// configuring exceptions for the custom Error objects core has.
|
|
337
|
+
"@typescript-eslint/only-throw-error": "error",
|
|
338
|
+
// Prefer `a = 4 as const` or `readonly a = 4;` over `a: 4 = 4`
|
|
339
|
+
"@typescript-eslint/prefer-as-const": "error",
|
|
340
|
+
"@typescript-eslint/prefer-find": "error",
|
|
341
|
+
// Use ()=>a over {():a}
|
|
342
|
+
"@typescript-eslint/prefer-function-type": ["warn"],
|
|
343
|
+
"@typescript-eslint/prefer-includes": ["warn"],
|
|
344
|
+
"@typescript-eslint/prefer-optional-chain": ["warn"],
|
|
345
|
+
// Throw only Error objects to preserve stack trace.
|
|
346
|
+
// TODO: drop due to many false positives and requires configuring
|
|
347
|
+
// exceptions for the custom Error objects core has.
|
|
348
|
+
"@typescript-eslint/prefer-promise-reject-errors": "error",
|
|
349
|
+
// Use .reduce<T>(...) over .reduce(()=>..., v as T) for type safety
|
|
350
|
+
"@typescript-eslint/prefer-reduce-type-parameter": ["warn"],
|
|
351
|
+
// Return `this` over the class type to improve subclassing support
|
|
352
|
+
"@typescript-eslint/prefer-return-this-type": ["warn"],
|
|
353
|
+
"@typescript-eslint/prefer-string-starts-ends-with": ["warn"],
|
|
354
|
+
// Better documents code, and if exception occurs, results in a rejected
|
|
355
|
+
// promise rather than an unhandled exception
|
|
356
|
+
"@typescript-eslint/promise-function-async": "warn",
|
|
357
|
+
// Catch when getter and setter types are unrelated. Most commonly when getter may return null but
|
|
358
|
+
// setter doesn't accept nul - likely mistake
|
|
359
|
+
"@typescript-eslint/related-getter-setter-pairs": "error",
|
|
360
|
+
// Require comparision function in .sort() to ensure "2" is before "10"
|
|
361
|
+
// Consider using String.prototype.localeCompare()
|
|
362
|
+
"@typescript-eslint/require-array-sort-compare": "warn",
|
|
363
|
+
// Not an error because:
|
|
364
|
+
// If passing function as a prop, and the function is expected to
|
|
365
|
+
// return a promise, making function async is cleaner than
|
|
366
|
+
// returning Promise.resolve()
|
|
367
|
+
"@typescript-eslint/require-await": "warn",
|
|
368
|
+
// Require + is used only with strings and numbers - arrays must be explicitly concatenated. Avoids
|
|
369
|
+
// surprising implicit stringification
|
|
370
|
+
"@typescript-eslint/restrict-plus-operands": ["warn", { allowNumberAndString: true }],
|
|
371
|
+
// Permit only strings and numbers in `${}` expressions to avoid [object Object]
|
|
372
|
+
"@typescript-eslint/restrict-template-expressions": [
|
|
373
|
+
"warn",
|
|
374
|
+
{
|
|
375
|
+
allowNumber: true
|
|
376
|
+
}
|
|
377
|
+
],
|
|
378
|
+
// This improves stack traces, improves performance, and makes code more
|
|
379
|
+
// explicit
|
|
380
|
+
"@typescript-eslint/return-await": ["warn", "always"],
|
|
381
|
+
// TODO: replace with perfectionist/sort-intersection-types and perfectionist/sort-union-types rules.
|
|
382
|
+
// Sort type union members
|
|
383
|
+
// Autofixable, so only a warning to be less disruptive
|
|
384
|
+
"@typescript-eslint/sort-type-constituents": "warn",
|
|
385
|
+
// Detect when switch forgot to handle cases. Can be ignored for intentional cases
|
|
386
|
+
"@typescript-eslint/switch-exhaustiveness-check": "error",
|
|
387
|
+
// TODO: drop. While ///reference can sometimes be replaced with imports, not always -
|
|
388
|
+
// this rule has false positives in Lumina
|
|
389
|
+
"@typescript-eslint/triple-slash-reference": "error",
|
|
390
|
+
// Combine function overloads when possible
|
|
391
|
+
"@typescript-eslint/unified-signatures": "error",
|
|
156
392
|
// This rule can provide optional optimizations. It might be redundant
|
|
157
393
|
// with TypeScript in some cases, but it provides a less-confusing error
|
|
158
394
|
// message (for example in .reduce())
|
|
159
395
|
"array-callback-return": "warn",
|
|
160
|
-
|
|
161
|
-
|
|
396
|
+
"arrow-body-style": "warn",
|
|
397
|
+
// We will enforce strict curly. Rational:
|
|
398
|
+
// - Same as core api
|
|
399
|
+
// - Better for debugging and breakpoints
|
|
400
|
+
"curly": ["warn", "all"],
|
|
401
|
+
// Ensure default: switch case is last for readability
|
|
402
|
+
"default-case-last": "error",
|
|
403
|
+
"eqeqeq": ["error", "always", { null: "ignore" }],
|
|
404
|
+
// Require function(){} syntax to include function name if name is not
|
|
405
|
+
// anomaly assigned by V8 - for debuggability.
|
|
406
|
+
// TODO: drop. In practice, arrow functions have the same issue, so maybe
|
|
407
|
+
// not worth enforcing this inconsistency
|
|
408
|
+
"func-names": ["warn", "as-needed"],
|
|
409
|
+
// Use arrow functions over `const a = function(){}`
|
|
410
|
+
"func-style": ["error", "declaration", { allowArrowFunctions: true, allowTypeAnnotation: true }],
|
|
411
|
+
// Require getter and setter to be next to each other in the class
|
|
162
412
|
"grouped-accessor-pairs": "error",
|
|
413
|
+
// Rationale: https://devtopia.esri.com/WebGIS/webgis-sdk/issues/289
|
|
414
|
+
// TODO: replace with unicorn/prevent-abbreviations
|
|
415
|
+
"id-denylist": ["error", "elt", "elem", "evt", "ev", "cb"],
|
|
416
|
+
// Encourage ui dialogs over alert/prompt.
|
|
417
|
+
// TODO: discuss dropping. This didn't find any valid cases but found some
|
|
418
|
+
// semi-false positives in tests
|
|
419
|
+
"no-alert": "error",
|
|
420
|
+
"no-caller": "error",
|
|
421
|
+
// Do not use `return;` in constructors
|
|
422
|
+
"no-constructor-return": "warn",
|
|
423
|
+
"no-eval": "error",
|
|
424
|
+
// Forbid extending prototype of built-ins to avoid compatibility issues
|
|
425
|
+
"no-extend-native": "error",
|
|
426
|
+
// Detect needless .bind() usages
|
|
163
427
|
"no-extra-bind": "warn",
|
|
428
|
+
"no-fallthrough": ["error", { reportUnusedFallthroughComment: true }],
|
|
429
|
+
// Catch numbers that have more decimal points than JS can represent - these are rounded implicitly
|
|
430
|
+
"no-loss-of-precision": "error",
|
|
431
|
+
// Disallow `a = b = 2` in favor of separate lines for readability
|
|
164
432
|
"no-multi-assign": "error",
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
"no-
|
|
169
|
-
"no-useless-concat": "error",
|
|
170
|
-
"no-unneeded-ternary": "warn",
|
|
171
|
-
"no-useless-call": "error",
|
|
172
|
-
"no-useless-rename": "warn",
|
|
173
|
-
// Useless returns are sometimes used for better readability
|
|
174
|
-
// i.e "default: return;"
|
|
175
|
-
"no-useless-return": "off",
|
|
433
|
+
"no-new-func": "error",
|
|
434
|
+
"no-new-wrappers": "error",
|
|
435
|
+
// Use {} over new Object()
|
|
436
|
+
"no-object-constructor": "error",
|
|
176
437
|
// Prevent accidental usages of global when forgot to declare a
|
|
177
438
|
// variable. If you actually mean to use them, prepend with "globalThis."
|
|
178
439
|
"no-restricted-globals": [
|
|
@@ -193,47 +454,6 @@ const config = [
|
|
|
193
454
|
},
|
|
194
455
|
...restrictedGlobals
|
|
195
456
|
],
|
|
196
|
-
"@typescript-eslint/no-useless-empty-export": "warn",
|
|
197
|
-
// Consider using String.prototype.localeCompare()
|
|
198
|
-
"@typescript-eslint/require-array-sort-compare": "warn",
|
|
199
|
-
"no-object-constructor": "error",
|
|
200
|
-
/**
|
|
201
|
-
* Something as simple as this cannot be typed without a TypeScript error
|
|
202
|
-
* without using void in place of undefined:
|
|
203
|
-
* const a = (callback: ()=>string | undefined) => {};
|
|
204
|
-
* a(()=>{ console.log('1'); })
|
|
205
|
-
*/
|
|
206
|
-
"@typescript-eslint/no-invalid-void-type": "off",
|
|
207
|
-
"@typescript-eslint/no-empty-object-type": ["warn", { allowInterfaces: "with-single-extends" }],
|
|
208
|
-
"@typescript-eslint/no-floating-promises": ["warn", { ignoreVoid: true }],
|
|
209
|
-
"@typescript-eslint/restrict-template-expressions": [
|
|
210
|
-
"warn",
|
|
211
|
-
{
|
|
212
|
-
allowNumber: true
|
|
213
|
-
}
|
|
214
|
-
],
|
|
215
|
-
"@typescript-eslint/restrict-plus-operands": ["warn", { allowNumberAndString: true }],
|
|
216
|
-
// We often actually have control characters in our regexes
|
|
217
|
-
"no-control-regex": "off",
|
|
218
|
-
"@typescript-eslint/no-restricted-imports": [
|
|
219
|
-
"error",
|
|
220
|
-
{
|
|
221
|
-
paths: [
|
|
222
|
-
{
|
|
223
|
-
name: "commander",
|
|
224
|
-
importNames: ["Command"],
|
|
225
|
-
message: "Import from @commander-js/extra-typings instead."
|
|
226
|
-
}
|
|
227
|
-
]
|
|
228
|
-
}
|
|
229
|
-
],
|
|
230
|
-
// Functions that deal with JSON.stringify/localStorage may have a type
|
|
231
|
-
// parameter as a more readable alternative to a type assertion.
|
|
232
|
-
// Also, this rule is quite complicated/expensive.
|
|
233
|
-
"@typescript-eslint/no-unnecessary-type-parameters": "off",
|
|
234
|
-
// Disabling until this is fixed:
|
|
235
|
-
// https://github.com/typescript-eslint/typescript-eslint/issues/9057
|
|
236
|
-
"@typescript-eslint/use-unknown-in-catch-callback-variable": "off",
|
|
237
457
|
/**
|
|
238
458
|
*
|
|
239
459
|
* Disallow deprecated and discouraged language syntax
|
|
@@ -265,95 +485,29 @@ const config = [
|
|
|
265
485
|
message: 'Replace with "createElement as h" (this allows using a single tsconfig.json both for Lumina and Storybook React)'
|
|
266
486
|
}
|
|
267
487
|
],
|
|
268
|
-
//
|
|
269
|
-
|
|
270
|
-
"no-alert": "error",
|
|
271
|
-
"no-caller": "error",
|
|
272
|
-
// TODO: re-enable once https://devtopia.esri.com/WebGIS/arcgis-web-components/issues/1519 is fixed
|
|
273
|
-
// "no-console": 'error',
|
|
274
|
-
"no-eval": "error",
|
|
275
|
-
"no-extend-native": "error",
|
|
276
|
-
// This creates less readable code
|
|
488
|
+
// Forbid assignments inside return as these are likely unintentional,
|
|
489
|
+
// and not very readable
|
|
277
490
|
"no-return-assign": "error",
|
|
491
|
+
// Forbid a.href="javascript:alert(1)" as it is eval-like
|
|
278
492
|
"no-script-url": "error",
|
|
279
|
-
//
|
|
493
|
+
// Forbid a===a needless compare
|
|
494
|
+
"no-self-compare": "error",
|
|
495
|
+
// Detect unexpected use of comma operator - likely syntax error, or
|
|
496
|
+
// less redable code
|
|
280
497
|
"no-sequences": "error",
|
|
281
|
-
|
|
282
|
-
"
|
|
283
|
-
|
|
284
|
-
"
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
"
|
|
290
|
-
"
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
{
|
|
295
|
-
allow: ["decoratedFunctions", "overrideMethods"]
|
|
296
|
-
}
|
|
297
|
-
],
|
|
298
|
-
"no-loss-of-precision": "error",
|
|
299
|
-
"@typescript-eslint/switch-exhaustiveness-check": "error",
|
|
300
|
-
"default-case-last": "error",
|
|
301
|
-
"func-style": ["error", "declaration", { allowArrowFunctions: true, allowTypeAnnotation: true }],
|
|
302
|
-
"no-new-func": "error",
|
|
303
|
-
"no-new-wrappers": "error",
|
|
304
|
-
"@typescript-eslint/no-misused-promises": [
|
|
305
|
-
"warn",
|
|
306
|
-
{
|
|
307
|
-
// Redundant with TypeScript
|
|
308
|
-
checksSpreads: false,
|
|
309
|
-
checksVoidReturn: {
|
|
310
|
-
arguments: true,
|
|
311
|
-
// Allow for patterns like ref={focusElement}
|
|
312
|
-
attributes: false,
|
|
313
|
-
inheritedMethods: true,
|
|
314
|
-
properties: true,
|
|
315
|
-
returns: true,
|
|
316
|
-
variables: true
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
],
|
|
320
|
-
// Generally this should be avoided, but some patterns require it
|
|
321
|
-
// (type-only getters/setters, or mixins)
|
|
322
|
-
"@typescript-eslint/no-unsafe-declaration-merging": "off",
|
|
323
|
-
//#endregion
|
|
324
|
-
//#region Report consistency issues
|
|
325
|
-
// TODO: make these more or less strict as needed
|
|
326
|
-
/**
|
|
327
|
-
* Consistency and clean code rules
|
|
328
|
-
*/
|
|
329
|
-
"arrow-body-style": "warn",
|
|
330
|
-
// This rule is a good idea, but not autofixable, so is only a warning
|
|
331
|
-
// TODO: this has basic type imports support. also consider import/no-duplicates
|
|
332
|
-
"no-duplicate-imports": "off",
|
|
333
|
-
// We will enforce strict curly. Rational:
|
|
334
|
-
// - Same as core api
|
|
335
|
-
// - Better for debugging and breakpoints
|
|
336
|
-
"curly": ["warn", "all"],
|
|
337
|
-
"eqeqeq": ["error", "always", { null: "ignore" }],
|
|
338
|
-
"func-names": ["warn", "as-needed"],
|
|
339
|
-
// Rationale: https://devtopia.esri.com/WebGIS/arcgis-web-components/issues/289
|
|
340
|
-
// TODO: replace with unicorn/prevent-abbreviations
|
|
341
|
-
"id-denylist": ["error", "elt", "elem", "evt", "ev", "cb"],
|
|
342
|
-
// Leave it to developer to decide when it is time to refactor-out
|
|
343
|
-
"complexity": "off",
|
|
344
|
-
// TODO: discuss (this avoids longer lines, improves readability)
|
|
345
|
-
// "no-inline-comments": "error",
|
|
346
|
-
// TODO: discuss (similar to the rule above, might be redundant).
|
|
347
|
-
// "@stylistic/line-comment-position": "error",
|
|
348
|
-
// Explicit boolean cast makes code more readable and catches potential bugs
|
|
349
|
-
"no-extra-boolean-cast": "off",
|
|
350
|
-
/**
|
|
351
|
-
* Code like this is useful for readability:
|
|
352
|
-
* ```ts
|
|
353
|
-
* const component = this;
|
|
354
|
-
* ```
|
|
355
|
-
*/
|
|
356
|
-
"@typescript-eslint/no-this-alias": "off",
|
|
498
|
+
// Replace a?true:false with a
|
|
499
|
+
"no-unneeded-ternary": "warn",
|
|
500
|
+
// Forbid loop that always breaks on the first iteration
|
|
501
|
+
"no-unreachable-loop": "error",
|
|
502
|
+
// Forbid !a==b when a!=b was meant. Redundant with TypeScript but has
|
|
503
|
+
// autofix so enabled for convenience
|
|
504
|
+
"no-unsafe-negation": "warn",
|
|
505
|
+
// Catch needless .call() and .apply() usages
|
|
506
|
+
"no-useless-call": "error",
|
|
507
|
+
// Use "ab" over "a" + "b"
|
|
508
|
+
"no-useless-concat": "error",
|
|
509
|
+
"no-useless-rename": "warn",
|
|
510
|
+
"no-var": "error",
|
|
357
511
|
"no-warning-comments": [
|
|
358
512
|
"error",
|
|
359
513
|
{
|
|
@@ -377,7 +531,26 @@ const config = [
|
|
|
377
531
|
// without moving the line - makes refactoring harder, and makes git's
|
|
378
532
|
// diff larger
|
|
379
533
|
"one-var": ["warn", "never"],
|
|
534
|
+
"prefer-arrow-callback": ["warn", { allowNamedFunctions: true }],
|
|
535
|
+
"prefer-const": "warn",
|
|
536
|
+
// Use 0b111110111 over parseInt("111110111", 2).
|
|
537
|
+
// TODO: consider disabling because this is likely too niche - not sure it
|
|
538
|
+
// ever caught anything
|
|
539
|
+
"prefer-numeric-literals": "warn",
|
|
540
|
+
// Use Object.hasOwn over Object.prototype.hasOwnProperty.call
|
|
541
|
+
"prefer-object-has-own": "warn",
|
|
542
|
+
// Use spread over Object.assign
|
|
543
|
+
"prefer-object-spread": "warn",
|
|
544
|
+
// Detect needless new RegExp() that can be written as /regex/
|
|
380
545
|
"prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
|
|
546
|
+
// Use ...rest over `arguments`. Helps v8 optimize
|
|
547
|
+
"prefer-rest-params": "error",
|
|
548
|
+
// Use spread over .apply
|
|
549
|
+
"prefer-spread": "error",
|
|
550
|
+
// Prefer template `${}` syntax over string concat
|
|
551
|
+
"prefer-template": "warn",
|
|
552
|
+
// Good rule to have, but many false positives, so only a warning
|
|
553
|
+
"require-atomic-updates": "warn",
|
|
381
554
|
// "u" flag in regex does two important things:
|
|
382
555
|
// - support unicode surrogate paris (properly parse glyphs that are more
|
|
383
556
|
// than one code point - i.e emojis)
|
|
@@ -390,232 +563,69 @@ const config = [
|
|
|
390
563
|
// user and you want to be more lenient with parsing (u enables stricter
|
|
391
564
|
// Regex)
|
|
392
565
|
"require-unicode-regexp": "error",
|
|
393
|
-
//
|
|
394
|
-
|
|
566
|
+
// Forbid "use strict"; in ESM modules as it is redundant
|
|
567
|
+
"strict": "warn",
|
|
568
|
+
// Require symbols to have a name for easier debugging.
|
|
569
|
+
// TODO: consider dropping. In practice most
|
|
570
|
+
// places in the code only deal with a single symbol kind at a time, so
|
|
571
|
+
// discrimination using a name is not mandatory - leave the name to the developer
|
|
395
572
|
"symbol-description": "warn",
|
|
396
|
-
//
|
|
397
|
-
"yoda": "warn",
|
|
573
|
+
// Forbid BOM marker as it is needless in utf8. Could be a copy paste error
|
|
398
574
|
"unicode-bom": "warn",
|
|
399
|
-
//
|
|
400
|
-
|
|
401
|
-
"
|
|
402
|
-
"error",
|
|
403
|
-
{
|
|
404
|
-
"ts-expect-error": "allow-with-description",
|
|
405
|
-
"ts-ignore": false,
|
|
406
|
-
"ts-nocheck": "allow-with-description",
|
|
407
|
-
"ts-check": true,
|
|
408
|
-
"minimumDescriptionLength": 3
|
|
409
|
-
}
|
|
410
|
-
],
|
|
411
|
-
// Getters are slower than direct property access. And if library user has
|
|
412
|
-
// TypeScript, overwriting readonly will be flagged as an error
|
|
413
|
-
"@typescript-eslint/class-literal-property-style": "off",
|
|
414
|
-
"@typescript-eslint/array-type": ["warn"],
|
|
415
|
-
"@typescript-eslint/consistent-type-assertions": [
|
|
416
|
-
// In some cases object literal type assertions are necessary
|
|
417
|
-
"warn",
|
|
418
|
-
{
|
|
419
|
-
assertionStyle: "as",
|
|
420
|
-
objectLiteralTypeAssertions: "allow-as-parameter"
|
|
421
|
-
}
|
|
422
|
-
],
|
|
423
|
-
"@typescript-eslint/consistent-type-exports": ["warn", { fixMixedExportsWithInlineTypeSpecifier: true }],
|
|
424
|
-
"@typescript-eslint/no-import-type-side-effects": "error",
|
|
425
|
-
"default-param-last": "off",
|
|
426
|
-
// `undefined` can also be used to trigger default value
|
|
427
|
-
"@typescript-eslint/default-param-last": "off",
|
|
428
|
-
"@typescript-eslint/explicit-function-return-type": [
|
|
429
|
-
// Providing explicit type improves type-checking performance and
|
|
430
|
-
// catches bugs (when actual return type is not what you are expecting,
|
|
431
|
-
// or return type changed accidentally during incorrect refactoring).
|
|
432
|
-
// It also improves code documentation
|
|
433
|
-
// In some cases, explicit type would be very bloated/complicated (i.e in
|
|
434
|
-
// case of mixins), thus you can silence this rule in those cases
|
|
435
|
-
"error",
|
|
436
|
-
{
|
|
437
|
-
allowConciseArrowFunctionExpressionsStartingWithVoid: true
|
|
438
|
-
}
|
|
439
|
-
],
|
|
440
|
-
"max-params": "off",
|
|
441
|
-
// Two spaces is more readable than " {2}"
|
|
442
|
-
"no-regex-spaces": "off",
|
|
443
|
-
"prefer-const": "warn",
|
|
444
|
-
"no-var": "error",
|
|
445
|
-
// Prefer passing parameters as an object instead to be less error prone
|
|
446
|
-
// and make adding/removing properties require less refactoring
|
|
447
|
-
"@typescript-eslint/max-params": ["warn", { max: 5 }],
|
|
448
|
-
// "property" style is more type-safe then "method" (has covariance checks)
|
|
449
|
-
"@typescript-eslint/method-signature-style": "warn",
|
|
450
|
-
"@typescript-eslint/no-inferrable-types": ["warn"],
|
|
451
|
-
"@typescript-eslint/non-nullable-type-assertion-style": ["warn"],
|
|
452
|
-
"@typescript-eslint/dot-notation": "warn",
|
|
453
|
-
"@typescript-eslint/prefer-function-type": ["warn"],
|
|
454
|
-
"@typescript-eslint/prefer-optional-chain": ["warn"],
|
|
455
|
-
"@typescript-eslint/prefer-string-starts-ends-with": ["warn"],
|
|
456
|
-
"@typescript-eslint/no-array-constructor": ["warn"],
|
|
457
|
-
"@typescript-eslint/no-duplicate-type-constituents": ["warn"],
|
|
458
|
-
"@typescript-eslint/no-unnecessary-boolean-literal-compare": ["warn"],
|
|
459
|
-
"@typescript-eslint/no-extra-non-null-assertion": ["warn"],
|
|
460
|
-
// False positive for the following:
|
|
461
|
-
// this.listen<CustomEvent>("arcgisChartsJSDataProcessComplete", this.handleDataProcessComplete);
|
|
462
|
-
"@typescript-eslint/no-unnecessary-type-arguments": "off",
|
|
463
|
-
// The autofix creates TS errors in makeT9nController(). This is a new
|
|
464
|
-
// rule - give it more time to catch the bug cases. Also, this rule
|
|
465
|
-
// changes runtime behavior, and may lead to breaking changes.
|
|
466
|
-
"@typescript-eslint/no-useless-default-assignment": "off",
|
|
467
|
-
"@typescript-eslint/no-unnecessary-type-assertion": ["warn"],
|
|
468
|
-
"@typescript-eslint/prefer-includes": ["warn"],
|
|
469
|
-
"@typescript-eslint/prefer-reduce-type-parameter": ["warn"],
|
|
470
|
-
"@typescript-eslint/prefer-return-this-type": ["warn"],
|
|
471
|
-
"@typescript-eslint/naming-convention": [
|
|
472
|
-
"error",
|
|
473
|
-
{
|
|
474
|
-
/*
|
|
475
|
-
* Use camelCase and PascalCase by default
|
|
476
|
-
* Pascal case is allowed because, despite variable names
|
|
477
|
-
* commonly starting with lower case, there are use cases for
|
|
478
|
-
* capital letter:
|
|
479
|
-
* - functional components
|
|
480
|
-
* - React contexts
|
|
481
|
-
* - constructors/dynamically created classes/mixins
|
|
482
|
-
* - enum-like config objects
|
|
483
|
-
*/
|
|
484
|
-
selector: "default",
|
|
485
|
-
format: ["camelCase", "PascalCase"],
|
|
486
|
-
// Denotes unused variables. Also may denote private members
|
|
487
|
-
leadingUnderscore: "allow",
|
|
488
|
-
trailingUnderscore: "forbid"
|
|
489
|
-
},
|
|
490
|
-
{
|
|
491
|
-
// TypeLike must be in PascalCase
|
|
492
|
-
selector: "typeLike",
|
|
493
|
-
format: ["PascalCase"]
|
|
494
|
-
},
|
|
495
|
-
{
|
|
496
|
-
// Relax restrictions for keys like `en-US` and etc.
|
|
497
|
-
selector: "default",
|
|
498
|
-
modifiers: ["requiresQuotes"],
|
|
499
|
-
format: null
|
|
500
|
-
},
|
|
501
|
-
{
|
|
502
|
-
// Enum members should be in upper case
|
|
503
|
-
selector: "enumMember",
|
|
504
|
-
format: ["UPPER_CASE"]
|
|
505
|
-
}
|
|
506
|
-
],
|
|
507
|
-
// TODO: turn this into an error. Discuss with the team why "any" defeats the purpose and benefits of TypeScript.
|
|
508
|
-
// To get all benefits of TypeScript, you have to go all full-in. Use of any
|
|
509
|
-
// may indicate poor code quality, or lack of understanding of TypeScript.
|
|
510
|
-
// In extreme cases, "unknown" should be used instead of any. There are
|
|
511
|
-
// virtually no correct use cases of any
|
|
512
|
-
"@typescript-eslint/no-explicit-any": "warn",
|
|
513
|
-
// There are cases where non-null assertions are useful as TypeScript fails
|
|
514
|
-
// to detect the preceding non-null check. Example:
|
|
515
|
-
// const key = 'key' as string; // Some dynamic key
|
|
516
|
-
// const a: Record<string, string[] | undefined> = {};
|
|
517
|
-
// a[key] ??= [];
|
|
518
|
-
// a[key].push("a"); // False error
|
|
519
|
-
//
|
|
520
|
-
// Also, while you can explicitly check for non-null and throw an exception,
|
|
521
|
-
// if you use !, the browser will automatically throw an exception for you:
|
|
522
|
-
// if(someObject == null) throw new Error('someObject is not defined');
|
|
523
|
-
// someObject.a();
|
|
524
|
-
// is equivalent to:
|
|
525
|
-
// someObject!.a();
|
|
526
|
-
// (and browser's exception message may be more useful)
|
|
527
|
-
//
|
|
528
|
-
// More thoughts on this:
|
|
529
|
-
// https://github.com/maxpatiiuk/dotfiles/blob/main/npm%2Feslint-config%2Feslint.config.js#L577-L602
|
|
530
|
-
"@typescript-eslint/no-non-null-assertion": "off",
|
|
531
|
-
"@typescript-eslint/no-require-imports": "warn",
|
|
532
|
-
// Better documents code, and if exception occurs, results in a rejected
|
|
533
|
-
// promise rather than an unhandled exception
|
|
534
|
-
"@typescript-eslint/promise-function-async": "warn",
|
|
535
|
-
// Not an error because:
|
|
536
|
-
// If passing function as a prop, and the function is expected to
|
|
537
|
-
// return a promise, making function async is cleaner than
|
|
538
|
-
// returning Promise.resolve()
|
|
539
|
-
"@typescript-eslint/require-await": "warn",
|
|
540
|
-
// This improves stack traces, improves performance, and makes code more
|
|
541
|
-
// explicit
|
|
542
|
-
"@typescript-eslint/return-await": ["warn", "always"],
|
|
543
|
-
// TODO: replace with perfectionist/sort-intersection-types and perfectionist/sort-union-types rules.
|
|
544
|
-
// Autofixable, so only a warning to be less disruptive
|
|
545
|
-
"@typescript-eslint/sort-type-constituents": "warn",
|
|
546
|
-
// The string.match() is more intuitive than the RegExp.exec()
|
|
547
|
-
"@typescript-eslint/prefer-regexp-exec": "off",
|
|
548
|
-
// Both types and interfaces have uses in the edge cases. In the common
|
|
549
|
-
// cases it often does not matter.
|
|
550
|
-
// See alsohttps://www.youtube.com/watch?v=zM9UPcIyyhQ
|
|
551
|
-
"@typescript-eslint/consistent-type-definitions": ["off", "type"],
|
|
552
|
-
// This is error by default. Turning into warning because it falsely
|
|
553
|
-
// reports when component tries to emit an event that is marked as
|
|
554
|
-
// deprecated.
|
|
555
|
-
"@typescript-eslint/no-deprecated": "warn",
|
|
556
|
-
// For can be useful in support packages and hot paths
|
|
557
|
-
"@typescript-eslint/prefer-for-of": "off",
|
|
558
|
-
// Enums are generally discouraged. Not much harm in this particular issue though
|
|
559
|
-
"@typescript-eslint/no-mixed-enums": "off",
|
|
560
|
-
// ENUM values like "1<<0" ... "1<<9" are very useful
|
|
561
|
-
"@typescript-eslint/prefer-literal-enum-member": "off",
|
|
562
|
-
// We discourage enums, so little added value in this check
|
|
563
|
-
"@typescript-eslint/no-duplicate-enum-values": "off",
|
|
564
|
-
// We discourage enums, so little added value in this check
|
|
565
|
-
"@typescript-eslint/no-unsafe-enum-comparison": "off",
|
|
566
|
-
// Developer may actually mean to use ||
|
|
567
|
-
// Also, refactoring this out may break things
|
|
568
|
-
"@typescript-eslint/prefer-nullish-coalescing": "off",
|
|
569
|
-
"@typescript-eslint/no-unnecessary-type-conversion": "warn"
|
|
570
|
-
//#endregion
|
|
575
|
+
// Use if(a==="b") over if("b"===a) for consistency
|
|
576
|
+
// Autofixable, so only a warning
|
|
577
|
+
"yoda": "warn"
|
|
571
578
|
// TODO: go over https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting
|
|
572
579
|
}
|
|
573
580
|
},
|
|
574
|
-
...markdown.configs.recommended,
|
|
575
581
|
{
|
|
576
582
|
files: ["**/*.md"],
|
|
583
|
+
plugins: { markdown },
|
|
577
584
|
language: "markdown/gfm",
|
|
578
|
-
languageOptions:
|
|
579
|
-
frontmatter: "yaml"
|
|
580
|
-
},
|
|
585
|
+
languageOptions: markdownLanguageOptions,
|
|
581
586
|
rules: {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
"markdown/no-
|
|
587
|
+
"markdown/fenced-code-language": "error",
|
|
588
|
+
"markdown/heading-increment": "error",
|
|
589
|
+
"markdown/no-duplicate-definitions": "error",
|
|
590
|
+
"markdown/no-empty-definitions": "error",
|
|
591
|
+
"markdown/no-empty-images": "error",
|
|
592
|
+
"markdown/no-empty-links": "error",
|
|
593
|
+
"markdown/no-invalid-label-refs": "error",
|
|
594
|
+
"markdown/no-missing-atx-heading-space": "error",
|
|
595
|
+
"markdown/no-missing-link-fragments": "error",
|
|
585
596
|
// We allow frontmatter titles to be different from the h1 by setting to "" which never matches
|
|
586
597
|
// This is useful to have a shorter title in the TOC than on the page.
|
|
587
|
-
"markdown/no-multiple-h1": ["error", { frontmatterTitle: "" }]
|
|
598
|
+
"markdown/no-multiple-h1": ["error", { frontmatterTitle: "" }],
|
|
599
|
+
"markdown/no-reference-like-urls": "error",
|
|
600
|
+
"markdown/no-reversed-media-syntax": "error",
|
|
601
|
+
"markdown/no-space-in-emphasis": "error",
|
|
602
|
+
"markdown/no-unused-definitions": "error",
|
|
603
|
+
"markdown/require-alt-text": "error",
|
|
604
|
+
"markdown/table-column-count": "error"
|
|
588
605
|
}
|
|
589
606
|
},
|
|
590
607
|
{
|
|
591
608
|
// Don't do type-aware linting for untyped files
|
|
592
609
|
files: ["**/*.js"],
|
|
593
|
-
|
|
610
|
+
languageOptions: {
|
|
611
|
+
parserOptions: {
|
|
612
|
+
program: null,
|
|
613
|
+
project: false,
|
|
614
|
+
projectService: false
|
|
615
|
+
}
|
|
616
|
+
}
|
|
594
617
|
},
|
|
595
|
-
packageJson.configs.recommended,
|
|
596
618
|
{
|
|
597
619
|
files: ["**/package.json"],
|
|
620
|
+
plugins: { "package-json": packageJson },
|
|
621
|
+
languageOptions: { parser: jsoncParser },
|
|
598
622
|
rules: {
|
|
599
|
-
// We don't want to sort scripts and exports
|
|
600
|
-
"package-json/sort-collections": ["warn", packageJsonSortableCollections],
|
|
601
|
-
// Making a warning for now to avoid disrupting current work but we should go to error later
|
|
602
|
-
"package-json/require-description": "warn",
|
|
603
623
|
"package-json/bin-name-casing": "warn",
|
|
604
624
|
// Allow empty "files" field to explicitly indicate that no files
|
|
605
625
|
// should be included in the package
|
|
606
626
|
"package-json/no-empty-fields": ["error", { ignoreProperties: ["files"] }],
|
|
607
|
-
|
|
608
|
-
"package-json/
|
|
609
|
-
// We are not open source
|
|
610
|
-
"package-json/require-repository": "off",
|
|
611
|
-
// This option is tricky to set right, especially for web component
|
|
612
|
-
// libraries that have many side effect entrypoints. It can also get out
|
|
613
|
-
// of date easily. If we don't explicitly indicate sideEffects, bundlers
|
|
614
|
-
// have good default AST-based heuristics.
|
|
615
|
-
"package-json/require-sideEffects": "off",
|
|
616
|
-
// Can't address these till 6.0 without breaking changes.
|
|
617
|
-
// Most errors are in react wrappers which will be dropped in 6.0.
|
|
618
|
-
"package-json/require-exports": "off",
|
|
627
|
+
"package-json/no-redundant-files": "error",
|
|
628
|
+
"package-json/no-redundant-publishConfig": "error",
|
|
619
629
|
// Enforce a specific property order for better readability and consistency
|
|
620
630
|
"package-json/order-properties": [
|
|
621
631
|
"warn",
|
|
@@ -647,7 +657,55 @@ const config = [
|
|
|
647
657
|
"packageManager"
|
|
648
658
|
]
|
|
649
659
|
}
|
|
650
|
-
]
|
|
660
|
+
],
|
|
661
|
+
"package-json/repository-shorthand": "error",
|
|
662
|
+
// Making a warning for now to avoid disrupting current work but we should go to error later
|
|
663
|
+
"package-json/require-description": "warn",
|
|
664
|
+
"package-json/require-files": "error",
|
|
665
|
+
"package-json/require-license": "error",
|
|
666
|
+
"package-json/require-name": "error",
|
|
667
|
+
"package-json/require-type": "error",
|
|
668
|
+
"package-json/require-version": "error",
|
|
669
|
+
// We don't want to sort scripts and exports
|
|
670
|
+
"package-json/sort-collections": ["warn", packageJsonSortableCollections],
|
|
671
|
+
"package-json/specify-peers-locally": "error",
|
|
672
|
+
"package-json/unique-dependencies": "error",
|
|
673
|
+
"package-json/valid-author": "error",
|
|
674
|
+
"package-json/valid-bin": "error",
|
|
675
|
+
"package-json/valid-bugs": "error",
|
|
676
|
+
"package-json/valid-bundleDependencies": "error",
|
|
677
|
+
"package-json/valid-config": "error",
|
|
678
|
+
"package-json/valid-contributors": "error",
|
|
679
|
+
"package-json/valid-cpu": "error",
|
|
680
|
+
"package-json/valid-dependencies": "error",
|
|
681
|
+
"package-json/valid-description": "error",
|
|
682
|
+
"package-json/valid-devDependencies": "error",
|
|
683
|
+
"package-json/valid-devEngines": "error",
|
|
684
|
+
"package-json/valid-directories": "error",
|
|
685
|
+
"package-json/valid-engines": "error",
|
|
686
|
+
"package-json/valid-exports": "error",
|
|
687
|
+
"package-json/valid-files": "error",
|
|
688
|
+
"package-json/valid-funding": "error",
|
|
689
|
+
"package-json/valid-homepage": "error",
|
|
690
|
+
"package-json/valid-keywords": "error",
|
|
691
|
+
"package-json/valid-license": "error",
|
|
692
|
+
"package-json/valid-main": "error",
|
|
693
|
+
"package-json/valid-man": "error",
|
|
694
|
+
"package-json/valid-module": "error",
|
|
695
|
+
"package-json/valid-name": "error",
|
|
696
|
+
"package-json/valid-optionalDependencies": "error",
|
|
697
|
+
"package-json/valid-os": "error",
|
|
698
|
+
"package-json/valid-packageManager": "error",
|
|
699
|
+
"package-json/valid-peerDependencies": "error",
|
|
700
|
+
"package-json/valid-private": "error",
|
|
701
|
+
"package-json/valid-publishConfig": "error",
|
|
702
|
+
"package-json/valid-repository": "error",
|
|
703
|
+
"package-json/valid-repository-directory": "error",
|
|
704
|
+
"package-json/valid-scripts": "error",
|
|
705
|
+
"package-json/valid-sideEffects": "error",
|
|
706
|
+
"package-json/valid-type": "error",
|
|
707
|
+
"package-json/valid-version": "error",
|
|
708
|
+
"package-json/valid-workspaces": "error"
|
|
651
709
|
}
|
|
652
710
|
}
|
|
653
711
|
];
|