You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.mdx
+16-3
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,27 @@ import TabItem from '@theme/TabItem';
9
9
>
10
10
> See **https://typescript-eslint.io/rules/no-confusing-non-null-assertion** for documentation.
11
11
12
-
Using a non-null assertion (`!`) next to an assign or equals check (`=` or `==` or `===`) creates code that is confusing as it looks similar to a not equals check (`!=``!==`).
12
+
Using a non-null assertion (`!`) next to an assignment or equality check (`=` or `==` or `===`) creates code that is confusing as it looks similar to an inequality check (`!=``!==`).
13
13
14
14
```typescript
15
-
a!==b; // a non-null assertions(`!`) and an equals test(`==`)
15
+
a!==b; // a non-null assertion(`!`) and an equals test(`==`)
16
16
a!==b; // not equals test(`!==`)
17
-
a!===b; // a non-null assertions(`!`) and an triple equals test(`===`)
17
+
a!===b; // a non-null assertion(`!`) and a triple equals test(`===`)
18
18
```
19
19
20
+
Using a non-null assertion (`!`) next to an in test (`in`) or an instanceof test (`instanceof`) creates code that is confusing since it may look like the operator is negated, but it is actually not.
21
+
22
+
{/* prettier-ignore */}
23
+
```typescript
24
+
a!inb; // a non-null assertion(`!`) and an in test(`in`)
25
+
a!inb; // also a non-null assertion(`!`) and an in test(`in`)
26
+
!(ainb); // a negated in test
27
+
28
+
a!instanceofb; // a non-null assertion(`!`) and an instanceof test(`instanceof`)
29
+
a!instanceofb; // also a non-null assertion(`!`) and an instanceof test(`instanceof`)
'Confusing combinations of non-null assertion and equal test like "a! == b", which looks very similar to not equal "a !== b".',
45
+
'Confusing combination of non-null assertion and equality test like `a! == b`, which looks very similar to `a !== b`.',
19
46
confusingAssign:
20
-
'Confusing combinations of non-null assertion and equal test like "a! = b", which looks very similar to not equal "a != b".',
21
-
notNeedInEqualTest: 'Unnecessary non-null assertion (!) in equal test.',
47
+
'Confusing combination of non-null assertion and assignment like `a! = b`, which looks very similar to `a != b`.',
48
+
confusingOperator:
49
+
'Confusing combination of non-null assertion and `{{operator}}` operator like `a! {{operator}} b`, which might be misinterpreted as `!(a {{operator}} b)`.',
50
+
51
+
notNeedInEqualTest:
52
+
'Remove unnecessary non-null assertion (!) in equality test.',
22
53
notNeedInAssign:
23
-
'Unnecessary non-null assertion (!) in assignment left hand.',
54
+
'Remove unnecessary non-null assertion (!) in assignment left-hand side.',
55
+
56
+
notNeedInOperator:
57
+
'Remove possibly unnecessary non-null assertion (!) in the left operand of the `{{operator}}` operator.',
58
+
24
59
wrapUpLeft:
25
-
'Wrap up lefthand to avoid putting non-null assertion "!" and "=" together.',
60
+
'Wrap the left-hand side in parentheses to avoid confusion with "{{operator}}" operator.',
0 commit comments