@josundt/eslint-config 4.9.7 → 5.2.0

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.
@@ -0,0 +1,124 @@
1
+ const eslintRuleSet = require("../eslint.js");
2
+ const { deepMergeObjects } = require("../../utils/merge.js");
3
+
4
+ const eslintRules = eslintRuleSet.rules;
5
+
6
+ // Map of all the typescript-eslint extensions.
7
+ // If extension rule has additional properties compared to standard eslint rule:
8
+ // If the map value is null:
9
+ // The options from the standard rule will be used as is.
10
+ // If the map value is an object:
11
+ // The object will be merged merged with standard rule (rule object 1).
12
+ // If the map value is an array:
13
+ // The items of the array will be added as a new rule options object.
14
+ // If the map value is a function:
15
+ // The standard eslint options object will be passed as parameters, the return statement will be added as options.
16
+
17
+ const extensions = new Map([
18
+ ["default-param-last", true],
19
+ [
20
+ "dot-notation",
21
+ {
22
+ allowPrivateClassPropertyAccess: false,
23
+ allowProtectedClassPropertyAccess: false,
24
+ allowIndexSignaturePropertyAccess: false
25
+ }
26
+ ],
27
+ ["init-declarations", true],
28
+ [
29
+ "lines-between-class-members",
30
+ {
31
+ exceptAfterOverload: true
32
+ }
33
+ ],
34
+ ["no-array-constructor", true],
35
+ ["no-dupe-class-members", true],
36
+ ["no-duplicate-imports", true],
37
+ [
38
+ "no-empty-function",
39
+ {
40
+ allow: [
41
+ "private-constructors",
42
+ "protected-constructors" /* "decoratedFunctions", "overrideMethods" */
43
+ ]
44
+ }
45
+ ],
46
+ ["no-extra-semi", true],
47
+ ["no-implied-eval", true],
48
+ ["no-invalid-this", false],
49
+ ["no-loop-func", true],
50
+ ["no-loss-of-precision", true],
51
+ ["no-magic-numbers", true],
52
+ ["no-redeclare", true],
53
+ ["no-restricted-imports", true],
54
+ [
55
+ "no-shadow",
56
+ v => {
57
+ const o = {
58
+ ...v,
59
+ ignoreTypeValueShadow: true,
60
+ ignoreFunctionTypeParameterNameValueShadow: true
61
+ };
62
+ delete o["ignoreOnInitialization"]; // Temporary bug in @typescript/eslint "no-shadow" extension rule - "ignoreOnInitialization" property considered invalid
63
+ return o;
64
+ }
65
+ ],
66
+ ["no-throw-literal", true],
67
+ ["no-unused-expressions", true],
68
+ ["no-unused-vars", false],
69
+ ["no-use-before-define", false],
70
+ ["no-useless-constructor", false],
71
+ ["require-await", true],
72
+ ["return-await", true]
73
+ ]);
74
+
75
+ // console.log(extensionRules);
76
+ // console.log(`Converted ${Object.keys(extensionRules).filter(k => !k.startsWith("@typescript")).length} of ${extensions.size} available extension rules`);
77
+ // console.log("Not converted:", Array.from(extensions.keys()).filter(k => !Object.keys(extensionRules).filter(k => !k.startsWith("@typescript")).includes(k)));
78
+
79
+ // Building eslint-typescript rules for existsing eslint rules and switching off original eslint rule
80
+ module.exports.typescriptEslintExtensionrules = Object.entries(
81
+ eslintRules
82
+ ).reduce((extRules, [key, value]) => {
83
+ // Try to get from known extensions map
84
+ const extension = extensions.get(key);
85
+
86
+ // If found in known typescript eslint extension rules map
87
+ if (extension !== undefined) {
88
+ // Switch off standard eslint rule
89
+ extRules[key] = "off";
90
+
91
+ // Special handling of certain extension rules that need to be switched off:
92
+ if (extension === false) {
93
+ extRules[`@typescript-eslint/${key}`] = "off";
94
+ } else {
95
+ // If extension rule has extended options, merge with standard eslint rule options:
96
+ if (extension !== true) {
97
+ // Ensure value is array if only severity string:
98
+ value = Array.isArray(value) ? [...value] : [value];
99
+ if (Array.isArray(extension)) {
100
+ value.push(...extension);
101
+ } else if (typeof extension === "object") {
102
+ // If array only contains severity string, push object
103
+ if (value.length === 1) {
104
+ value.push(extension);
105
+ // Else merge object
106
+ } else {
107
+ value[value.length - 1] = deepMergeObjects(
108
+ value[value.length - 1],
109
+ extension
110
+ );
111
+ }
112
+ } else if (typeof extension === "function") {
113
+ const [, ...options] = value;
114
+ value[value.length - 1] = { ...extension(...options) };
115
+ }
116
+ }
117
+ // Add extension rule value with the @typescript-eslint key prefix
118
+ extRules[`@typescript-eslint/${key}`] = value;
119
+ }
120
+ }
121
+ // else: if no extension rule exists, the standard eslint rule will be used through the "extends" configuration below
122
+
123
+ return extRules;
124
+ }, {});
@@ -0,0 +1,299 @@
1
+ /* Main @typescript-eslint rules */
2
+ const rules = {
3
+ "adjacent-overload-signatures": "error",
4
+ "array-type": [
5
+ "error",
6
+ {
7
+ default: "array-simple",
8
+ readonly: "array-simple"
9
+ }
10
+ ],
11
+ "await-thenable": "error",
12
+ "ban-ts-comment": [
13
+ "error",
14
+ {
15
+ "ts-expect-error": "allow-with-description",
16
+ "ts-ignore": true,
17
+ "ts-nocheck": true,
18
+ "ts-check": false,
19
+ "minimumDescriptionLength": 10
20
+ //"descriptionFormat": "someformathere"
21
+ }
22
+ ],
23
+ "ban-tslint-comment": "error", // No longer use tslint - remove rules
24
+ "ban-types": "off", // Can be used to ban certain types
25
+ "class-literal-property-style": "off",
26
+ "consistent-generic-constructors": ["off", "constructor"],
27
+ "consistent-indexed-object-style": ["error", "record"],
28
+ "consistent-type-assertions": [
29
+ "error",
30
+ {
31
+ assertionStyle: "as",
32
+ objectLiteralTypeAssertions: "allow"
33
+ }
34
+ ],
35
+ "consistent-type-definitions": ["error", "interface"],
36
+ "consistent-type-exports": [
37
+ "error",
38
+ {
39
+ fixMixedExportsWithInlineTypeSpecifier: true
40
+ }
41
+ ],
42
+ "consistent-type-imports": [
43
+ "error",
44
+ {
45
+ prefer: "type-imports",
46
+ fixStyle: "inline-type-imports",
47
+ disallowTypeAnnotations: false
48
+ }
49
+ ],
50
+ "explicit-function-return-type": [
51
+ "error",
52
+ {
53
+ allowConciseArrowFunctionExpressionsStartingWithVoid: true,
54
+ allowExpressions: true,
55
+ allowFunctionsWithoutTypeParameters: false,
56
+ allowHigherOrderFunctions: true,
57
+ allowIIFEs: false,
58
+ allowTypedFunctionExpressions: true,
59
+ allowedNames: []
60
+ }
61
+ ],
62
+ "explicit-member-accessibility": [
63
+ "error",
64
+ {
65
+ accessibility: "no-public"
66
+ }
67
+ ],
68
+ "explicit-module-boundary-types": [
69
+ // same as "recommended" except error instead of warning
70
+ "error",
71
+ {
72
+ allowArgumentsExplicitlyTypedAsAny: false,
73
+ allowDirectConstAssertionInArrowFunctions: true,
74
+ allowHigherOrderFunctions: true,
75
+ allowTypedFunctionExpressions: true,
76
+ allowedNames: []
77
+ }
78
+ ],
79
+ "member-delimiter-style": [
80
+ "error",
81
+ {
82
+ multiline: {
83
+ delimiter: "semi",
84
+ requireLast: true
85
+ },
86
+ singleline: {
87
+ delimiter: "semi",
88
+ requireLast: false
89
+ }
90
+ }
91
+ ],
92
+ "member-ordering": "off",
93
+ "method-signature-style": "off", // useful rule since lambda method notation enforces stricter type checking, but has somme inconveniences for ovelaoads, "implement interface" refactoring, and general code complexity
94
+ "naming-convention": [
95
+ "error",
96
+ {
97
+ selector: "default",
98
+ format: ["camelCase"],
99
+ leadingUnderscore: "forbid",
100
+ trailingUnderscore: "forbid"
101
+ },
102
+ {
103
+ selector: "typeLike",
104
+ format: ["PascalCase"]
105
+ },
106
+ {
107
+ selector: "method",
108
+ modifiers: [
109
+ // "#private", // Did not work even if it was added in 5.49.0
110
+ "private"
111
+ ],
112
+ format: ["camelCase"],
113
+ leadingUnderscore: "allow",
114
+ trailingUnderscore: "forbid"
115
+ },
116
+ {
117
+ selector: "property",
118
+ modifiers: [
119
+ // "#private", // Did not work even if it was added in 5.49.0
120
+ "private"
121
+ ],
122
+ format: ["camelCase"],
123
+ leadingUnderscore: "allow",
124
+ trailingUnderscore: "forbid"
125
+ },
126
+ {
127
+ selector: "enumMember",
128
+ format: ["camelCase", "PascalCase"]
129
+ }
130
+ ],
131
+ "no-base-to-string": "error",
132
+ "no-confusing-non-null-assertion": "error",
133
+ "no-confusing-void-expression": [
134
+ "error",
135
+ {
136
+ ignoreArrowShorthand: true
137
+ }
138
+ ],
139
+ "no-duplicate-enum-values": "error",
140
+ "no-duplicate-type-constituents": "error",
141
+ "no-dynamic-delete": "error",
142
+ "no-empty-interface": "off",
143
+ "no-explicit-any": [
144
+ "off",
145
+ {
146
+ ignoreRestArgs: "false"
147
+ }
148
+ ],
149
+ "no-extra-non-null-assertion": "error",
150
+ "no-extraneous-class": "error",
151
+ "no-floating-promises": "error", // Must be switched on to prevent promises not awaited
152
+ "no-for-in-array": "error",
153
+ "no-import-type-side-effects": "error",
154
+ "no-inferrable-types": "off",
155
+ "no-invalid-void-type": [
156
+ "error",
157
+ {
158
+ allowInGenericTypeArguments: true,
159
+ allowAsThisParameter: true
160
+ }
161
+ ],
162
+ "no-meaningless-void-operator": "error",
163
+ "no-misused-new": "error",
164
+ "no-misused-promises": [
165
+ "error",
166
+ {
167
+ checksConditionals: true,
168
+ checksSpreads: true,
169
+ checksVoidReturn: true // {
170
+ // arguments: true, //Disables checking an asynchronous function passed as argument where the parameter type expects a function that returns void
171
+ // attributes: true, //Disables checking an asynchronous function passed as a JSX attribute expected to be a function that returns void
172
+ // properties: true, //Disables checking an asynchronous function passed as an object property expected to be a function that returns void
173
+ // returns: true, //Disables checking an asynchronous function returned in a function whose return type is a function that returns void
174
+ // variables: true //Disables checking an asynchronous function used as a variable whose return type is a function that returns void
175
+ // }
176
+ }
177
+ ],
178
+ "no-mixed-enums": "error",
179
+ "no-namespace": "off",
180
+ "no-non-null-asserted-nullish-coalescing": "error",
181
+ "no-non-null-asserted-optional-chain": "error",
182
+ "no-non-null-assertion": "off",
183
+ "no-redundant-type-constituents": "error",
184
+ "no-require-imports": "error",
185
+ "no-unsafe-enum-comparison": "error",
186
+ "no-this-alias": "error",
187
+ "no-throw-literal": [
188
+ "error",
189
+ {
190
+ allowThrowingAny: false, // Default is to allow throwing values of type any
191
+ allowThrowingUnknown: true // Default is to allow throwing values of type unknown
192
+ }
193
+ ],
194
+ "no-type-alias": "off",
195
+ "no-unnecessary-boolean-literal-compare": "error",
196
+ "no-unnecessary-condition": "off", // allow runtime null checks etc even if reported not necessary by type system
197
+ "no-unnecessary-qualifier": "error",
198
+ "no-unnecessary-type-arguments": "off",
199
+ "no-unnecessary-type-assertion": "off",
200
+ "no-unnecessary-type-constraint": "error",
201
+ "no-unsafe-argument": "error",
202
+ "no-unsafe-assignment": "error",
203
+ "no-unsafe-call": "error",
204
+ "no-unsafe-member-access": "error",
205
+ "no-unsafe-return": "error",
206
+ "no-unused-vars-experimental": "off", // to strict with method params...
207
+ "no-useless-empty-export": "error",
208
+ "no-var-requires": "error",
209
+ "non-nullable-type-assertion-style": "error",
210
+ "parameter-properties": [
211
+ "error",
212
+ {
213
+ prefer: "class-property", // or "parameter-property"
214
+ allow: ["private readonly", "private", "protected readonly"]
215
+ }
216
+ ],
217
+ "prefer-as-const": "off",
218
+ "prefer-enum-initializers": "error",
219
+ "prefer-for-of": "error",
220
+ "prefer-function-type": "error",
221
+ "prefer-includes": "error",
222
+ "prefer-literal-enum-member": "error",
223
+ "prefer-namespace-keyword": "error",
224
+ "prefer-nullish-coalescing": [
225
+ "error",
226
+ {
227
+ ignoreConditionalTests: true,
228
+ ignoreTernaryTests: true,
229
+ ignoreMixedLogicalExpressions: true
230
+ }
231
+ ],
232
+ "prefer-optional-chain": "error",
233
+ "prefer-readonly": "error",
234
+ "prefer-readonly-parameter-types": "off", // Could be useful but requires too much work and verbose notation
235
+ "prefer-reduce-type-parameter": "error",
236
+ "prefer-regexp-exec": "error",
237
+ "prefer-return-this-type": "error",
238
+ "prefer-string-starts-ends-with": "error",
239
+ "prefer-ts-expect-error": "error",
240
+ "promise-function-async": "off",
241
+ "require-array-sort-compare": "error",
242
+ "restrict-plus-operands": [
243
+ "error",
244
+ {
245
+ checkCompoundAssignments: true,
246
+ allowAny: false
247
+ }
248
+ ],
249
+ "restrict-template-expressions": [
250
+ "error",
251
+ {
252
+ allowAny: false,
253
+ allowBoolean: false,
254
+ allowNever: false,
255
+ allowNullish: false,
256
+ allowNumber: true,
257
+ allowRegExp: false
258
+ }
259
+ ],
260
+ "sort-type-constituents": "off",
261
+ "strict-boolean-expressions": [
262
+ "off",
263
+ {
264
+ allowString: true,
265
+ allowNumber: true,
266
+ allowNullableObject: true,
267
+ allowNullableString: true,
268
+ allowNullableNumber: true,
269
+ allowNullableBoolean: true,
270
+ allowAny: false
271
+ }
272
+ ],
273
+ "switch-exhaustiveness-check": "error",
274
+ "triple-slash-reference": "error",
275
+ "type-annotation-spacing": "error", // This is a formatting rule
276
+ "typedef": [
277
+ "error",
278
+ {
279
+ arrayDestructuring: false,
280
+ arrowParameter: false,
281
+ memberVariableDeclaration: true,
282
+ objectDestructuring: false,
283
+ parameter: true,
284
+ propertyDeclaration: true,
285
+ variableDeclaration: false
286
+ }
287
+ ],
288
+ "unbound-method": "error",
289
+ "unified-signatures": "off"
290
+ };
291
+
292
+ // Rules - append "@typescript-eslint/" to rule names
293
+ module.exports.typescriptEslintRules = Object.entries(rules).reduce(
294
+ (aggr, [key, value]) => ({
295
+ ...aggr,
296
+ [`@typescript-eslint/${key}`]: value
297
+ }),
298
+ {}
299
+ );