@typescript-eslint/eslint-plugin 8.23.1-alpha.0 → 8.23.1-alpha.2
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.
@@ -28,46 +28,48 @@ This rule will not work as expected if [`strictNullChecks`](https://www.typescri
|
|
28
28
|
|
29
29
|
{/* insert option description */}
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
31
|
+
Examples of code for this rule with `{ ignoreTernaryTests: false }`:
|
32
|
+
|
33
|
+
<Tabs>
|
34
|
+
<TabItem value="❌ Incorrect">
|
35
|
+
|
36
|
+
```ts option='{ "ignoreTernaryTests": false }'
|
37
|
+
declare const a: any;
|
38
|
+
a !== undefined && a !== null ? a : 'a string';
|
39
|
+
a === undefined || a === null ? 'a string' : a;
|
40
|
+
a == undefined ? 'a string' : a;
|
41
|
+
a == null ? 'a string' : a;
|
42
|
+
|
43
|
+
declare const b: string | undefined;
|
44
|
+
b !== undefined ? b : 'a string';
|
45
|
+
b === undefined ? 'a string' : b;
|
46
|
+
b ? b : 'a string';
|
47
|
+
!b ? 'a string' : b;
|
48
|
+
|
49
|
+
declare const c: string | null;
|
50
|
+
c !== null ? c : 'a string';
|
51
|
+
c === null ? 'a string' : c;
|
52
|
+
c ? c : 'a string';
|
53
|
+
!c ? 'a string' : c;
|
49
54
|
```
|
50
55
|
|
51
|
-
|
56
|
+
</TabItem>
|
57
|
+
<TabItem value="✅ Correct">
|
52
58
|
|
53
|
-
```ts option='{ "ignoreTernaryTests": false }'
|
54
|
-
const
|
55
|
-
|
56
|
-
foo ?? 'a string';
|
57
|
-
foo ?? 'a string';
|
58
|
-
foo ?? 'a string';
|
59
|
+
```ts option='{ "ignoreTernaryTests": false }'
|
60
|
+
declare const a: any;
|
61
|
+
a ?? 'a string';
|
59
62
|
|
60
|
-
const
|
61
|
-
|
62
|
-
foo ?? 'a string';
|
63
|
+
declare const b: string | undefined;
|
64
|
+
b ?? 'a string';
|
63
65
|
|
64
|
-
const
|
65
|
-
|
66
|
-
foo ?? 'a string';
|
67
|
-
foo ?? 'a string';
|
68
|
-
foo ?? 'a string';
|
66
|
+
declare const c: string | null;
|
67
|
+
c ?? 'a string';
|
69
68
|
```
|
70
69
|
|
70
|
+
</TabItem>
|
71
|
+
</Tabs>
|
72
|
+
|
71
73
|
### `ignoreConditionalTests`
|
72
74
|
|
73
75
|
{/* insert option description */}
|
@@ -76,9 +78,12 @@ Generally expressions within conditional tests intentionally use the falsy fallt
|
|
76
78
|
|
77
79
|
If you're looking to enforce stricter conditional tests, you should consider using the `strict-boolean-expressions` rule.
|
78
80
|
|
79
|
-
|
81
|
+
Examples of code for this rule with `{ ignoreConditionalTests: false }`:
|
82
|
+
|
83
|
+
<Tabs>
|
84
|
+
<TabItem value="❌ Incorrect">
|
80
85
|
|
81
|
-
```ts option='{ "ignoreConditionalTests": false }'
|
86
|
+
```ts option='{ "ignoreConditionalTests": false }'
|
82
87
|
declare const a: string | null;
|
83
88
|
declare const b: string | null;
|
84
89
|
|
@@ -93,9 +98,10 @@ for (let i = 0; a || b; i += 1) {}
|
|
93
98
|
a || b ? true : false;
|
94
99
|
```
|
95
100
|
|
96
|
-
|
101
|
+
</TabItem>
|
102
|
+
<TabItem value="✅ Correct">
|
97
103
|
|
98
|
-
```ts option='{ "ignoreConditionalTests": false }'
|
104
|
+
```ts option='{ "ignoreConditionalTests": false }'
|
99
105
|
declare const a: string | null;
|
100
106
|
declare const b: string | null;
|
101
107
|
|
@@ -110,6 +116,9 @@ for (let i = 0; a ?? b; i += 1) {}
|
|
110
116
|
(a ?? b) ? true : false;
|
111
117
|
```
|
112
118
|
|
119
|
+
</TabItem>
|
120
|
+
</Tabs>
|
121
|
+
|
113
122
|
### `ignoreMixedLogicalExpressions`
|
114
123
|
|
115
124
|
{/* insert option description */}
|
@@ -118,9 +127,12 @@ Generally expressions within mixed logical expressions intentionally use the fal
|
|
118
127
|
|
119
128
|
If you're looking to enforce stricter conditional tests, you should consider using the `strict-boolean-expressions` rule.
|
120
129
|
|
121
|
-
|
130
|
+
Examples of code for this rule with `{ ignoreMixedLogicalExpressions: false }`:
|
131
|
+
|
132
|
+
<Tabs>
|
133
|
+
<TabItem value="❌ Incorrect">
|
122
134
|
|
123
|
-
```ts option='{ "ignoreMixedLogicalExpressions": false }'
|
135
|
+
```ts option='{ "ignoreMixedLogicalExpressions": false }'
|
124
136
|
declare const a: string | null;
|
125
137
|
declare const b: string | null;
|
126
138
|
declare const c: string | null;
|
@@ -133,9 +145,10 @@ a || (b && c) || d;
|
|
133
145
|
a || (b && c && d);
|
134
146
|
```
|
135
147
|
|
136
|
-
|
148
|
+
</TabItem>
|
149
|
+
<TabItem value="✅ Correct">
|
137
150
|
|
138
|
-
```ts option='{ "ignoreMixedLogicalExpressions": false }'
|
151
|
+
```ts option='{ "ignoreMixedLogicalExpressions": false }'
|
139
152
|
declare const a: string | null;
|
140
153
|
declare const b: string | null;
|
141
154
|
declare const c: string | null;
|
@@ -148,6 +161,9 @@ a ?? (b && c) ?? d;
|
|
148
161
|
a ?? (b && c && d);
|
149
162
|
```
|
150
163
|
|
164
|
+
</TabItem>
|
165
|
+
</Tabs>
|
166
|
+
|
151
167
|
**_NOTE:_** Errors for this specific case will be presented as suggestions (see below), instead of fixes. This is because it is not always safe to automatically convert `||` to `??` within a mixed logical expression, as we cannot tell the intended precedence of the operator. Note that by design, `??` requires parentheses when used with `&&` or `||` in the same expression.
|
152
168
|
|
153
169
|
### `ignorePrimitives`
|
@@ -156,49 +172,65 @@ a ?? (b && c && d);
|
|
156
172
|
|
157
173
|
If you would like to ignore expressions containing operands of certain primitive types that can be falsy then you may pass an object containing a boolean value for each primitive:
|
158
174
|
|
159
|
-
- `string: true`, ignores `null` or `undefined` unions with `string` (default: false).
|
160
|
-
- `number: true`, ignores `null` or `undefined` unions with `number` (default: false).
|
161
|
-
- `bigint: true`, ignores `null` or `undefined` unions with `bigint` (default: false).
|
162
|
-
- `boolean: true`, ignores `null` or `undefined` unions with `boolean` (default: false).
|
175
|
+
- `string: true`, ignores `null` or `undefined` unions with `string` (default: `false`).
|
176
|
+
- `number: true`, ignores `null` or `undefined` unions with `number` (default: `false`).
|
177
|
+
- `bigint: true`, ignores `null` or `undefined` unions with `bigint` (default: `false`).
|
178
|
+
- `boolean: true`, ignores `null` or `undefined` unions with `boolean` (default: `false`).
|
163
179
|
|
164
|
-
|
180
|
+
Examples of code for this rule with `{ ignorePrimitives: { string: false } }`:
|
181
|
+
|
182
|
+
<Tabs>
|
183
|
+
<TabItem value="❌ Incorrect">
|
184
|
+
|
185
|
+
```ts option='{ "ignorePrimitives": { "string": false } }'
|
186
|
+
declare const foo: string | undefined;
|
165
187
|
|
166
|
-
```ts option='{ "ignorePrimitives": { "string": true } }' showPlaygroundButton
|
167
|
-
const foo: string | undefined = 'bar';
|
168
188
|
foo || 'a string';
|
169
189
|
```
|
170
190
|
|
171
|
-
|
191
|
+
</TabItem>
|
192
|
+
<TabItem value="✅ Correct">
|
193
|
+
|
194
|
+
```ts option='{ "ignorePrimitives": { "string": false } }'
|
195
|
+
declare const foo: string | undefined;
|
172
196
|
|
173
|
-
```ts option='{ "ignorePrimitives": { "string": true } }' showPlaygroundButton
|
174
|
-
const foo: string | undefined = 'bar';
|
175
197
|
foo ?? 'a string';
|
176
198
|
```
|
177
199
|
|
200
|
+
</TabItem>
|
201
|
+
</Tabs>
|
202
|
+
|
178
203
|
Also, if you would like to ignore all primitives types, you can set `ignorePrimitives: true`. It is equivalent to `ignorePrimitives: { string: true, number: true, bigint: true, boolean: true }`.
|
179
204
|
|
180
205
|
### `ignoreBooleanCoercion`
|
181
206
|
|
182
207
|
{/* insert option description */}
|
183
208
|
|
184
|
-
|
209
|
+
Examples of code for this rule with `{ ignoreBooleanCoercion: false }`:
|
210
|
+
|
211
|
+
<Tabs>
|
212
|
+
<TabItem value="❌ Incorrect">
|
185
213
|
|
186
|
-
```ts option='{ "ignoreBooleanCoercion":
|
187
|
-
|
188
|
-
|
214
|
+
```ts option='{ "ignoreBooleanCoercion": false }'
|
215
|
+
declare const a: string | true | undefined;
|
216
|
+
declare const b: string | boolean | undefined;
|
189
217
|
|
190
218
|
const x = Boolean(a || b);
|
191
219
|
```
|
192
220
|
|
193
|
-
|
221
|
+
</TabItem>
|
222
|
+
<TabItem value="✅ Correct">
|
194
223
|
|
195
|
-
```ts option='{ "ignoreBooleanCoercion": false }'
|
196
|
-
|
197
|
-
|
224
|
+
```ts option='{ "ignoreBooleanCoercion": false }'
|
225
|
+
declare const a: string | true | undefined;
|
226
|
+
declare const b: string | boolean | undefined;
|
198
227
|
|
199
228
|
const x = Boolean(a ?? b);
|
200
229
|
```
|
201
230
|
|
231
|
+
</TabItem>
|
232
|
+
</Tabs>
|
233
|
+
|
202
234
|
### `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing`
|
203
235
|
|
204
236
|
:::danger Deprecated
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.23.1-alpha.
|
3
|
+
"version": "8.23.1-alpha.2",
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
5
5
|
"files": [
|
6
6
|
"dist",
|
@@ -61,10 +61,10 @@
|
|
61
61
|
},
|
62
62
|
"dependencies": {
|
63
63
|
"@eslint-community/regexpp": "^4.10.0",
|
64
|
-
"@typescript-eslint/scope-manager": "8.23.1-alpha.
|
65
|
-
"@typescript-eslint/type-utils": "8.23.1-alpha.
|
66
|
-
"@typescript-eslint/utils": "8.23.1-alpha.
|
67
|
-
"@typescript-eslint/visitor-keys": "8.23.1-alpha.
|
64
|
+
"@typescript-eslint/scope-manager": "8.23.1-alpha.2",
|
65
|
+
"@typescript-eslint/type-utils": "8.23.1-alpha.2",
|
66
|
+
"@typescript-eslint/utils": "8.23.1-alpha.2",
|
67
|
+
"@typescript-eslint/visitor-keys": "8.23.1-alpha.2",
|
68
68
|
"graphemer": "^1.4.0",
|
69
69
|
"ignore": "^5.3.1",
|
70
70
|
"natural-compare": "^1.4.0",
|
@@ -75,8 +75,8 @@
|
|
75
75
|
"@types/marked": "^5.0.2",
|
76
76
|
"@types/mdast": "^4.0.3",
|
77
77
|
"@types/natural-compare": "*",
|
78
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.23.1-alpha.
|
79
|
-
"@typescript-eslint/rule-tester": "8.23.1-alpha.
|
78
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.23.1-alpha.2",
|
79
|
+
"@typescript-eslint/rule-tester": "8.23.1-alpha.2",
|
80
80
|
"ajv": "^6.12.6",
|
81
81
|
"cross-env": "^7.0.3",
|
82
82
|
"cross-fetch": "*",
|