@typescript-eslint/eslint-plugin 6.7.1-alpha.3 → 6.7.2-alpha.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.
- package/dist/rules/no-unsafe-enum-comparison.js +2 -5
- package/dist/rules/no-unsafe-enum-comparison.js.map +1 -1
- package/docs/rules/no-dupe-class-members.md +4 -0
- package/docs/rules/no-invalid-this.md +4 -0
- package/docs/rules/no-redeclare.md +4 -0
- package/docs/rules/prefer-nullish-coalescing.md +5 -5
- package/package.json +9 -9
|
@@ -65,13 +65,10 @@ exports.default = util.createRule({
|
|
|
65
65
|
create(context) {
|
|
66
66
|
const parserServices = util.getParserServices(context);
|
|
67
67
|
const typeChecker = parserServices.program.getTypeChecker();
|
|
68
|
-
function getTypeFromNode(node) {
|
|
69
|
-
return typeChecker.getTypeAtLocation(parserServices.esTreeNodeToTSNodeMap.get(node));
|
|
70
|
-
}
|
|
71
68
|
return {
|
|
72
69
|
'BinaryExpression[operator=/^[<>!=]?={0,2}$/]'(node) {
|
|
73
|
-
const left =
|
|
74
|
-
const right =
|
|
70
|
+
const left = parserServices.getTypeAtLocation(node.left);
|
|
71
|
+
const right = parserServices.getTypeAtLocation(node.right);
|
|
75
72
|
// Allow comparisons that don't have anything to do with enums:
|
|
76
73
|
//
|
|
77
74
|
// ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-unsafe-enum-comparison.js","sourceRoot":"","sources":["../../src/rules/no-unsafe-enum-comparison.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAAwC;AACxC,+CAAiC;AAEjC,8CAAgC;AAChC,gDAAmD;AAEnD;;GAEG;AACH,SAAS,YAAY,CAAC,aAAwB,EAAE,KAAc;IAC5D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEpE,OAAO,CACL,CAAC,cAAc,CAA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gBACpE,EAAE;gBACF,QAAQ;gBACR,wCAAwC;gBACxC,eAAe;gBACf,MAAM;gBACN,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;oBACxC,IAAI,cAAc,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;wBACzC,OAAO;qBACR;iBACF;gBAED,IACE,YAAY,CAAC,aAAa,EAAE,KAAK,CAAC;oBAClC,YAAY,CAAC,cAAc,EAAE,IAAI,CAAC,EAClC;oBACA,OAAO,CAAC,MAAM,CAAC;wBACb,SAAS,EAAE,YAAY;wBACvB,IAAI;qBACL,CAAC,CAAC;iBACJ;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -6,5 +6,9 @@ description: 'Disallow duplicate class members.'
|
|
|
6
6
|
>
|
|
7
7
|
> See **https://typescript-eslint.io/rules/no-dupe-class-members** for documentation.
|
|
8
8
|
|
|
9
|
+
import TypeScriptOverlap from "@site/src/components/TypeScriptOverlap";
|
|
10
|
+
|
|
11
|
+
<TypeScriptOverlap />
|
|
12
|
+
|
|
9
13
|
This rule extends the base [`eslint/no-dupe-class-members`](https://eslint.org/docs/rules/no-dupe-class-members) rule.
|
|
10
14
|
It adds support for TypeScript's method overload definitions.
|
|
@@ -6,5 +6,9 @@ description: 'Disallow `this` keywords outside of classes or class-like objects.
|
|
|
6
6
|
>
|
|
7
7
|
> See **https://typescript-eslint.io/rules/no-invalid-this** for documentation.
|
|
8
8
|
|
|
9
|
+
import TypeScriptOverlap from "@site/src/components/TypeScriptOverlap";
|
|
10
|
+
|
|
11
|
+
<TypeScriptOverlap strict />
|
|
12
|
+
|
|
9
13
|
This rule extends the base [`eslint/no-invalid-this`](https://eslint.org/docs/rules/no-invalid-this) rule.
|
|
10
14
|
It adds support for TypeScript's `this` parameters.
|
|
@@ -6,6 +6,10 @@ description: 'Disallow variable redeclaration.'
|
|
|
6
6
|
>
|
|
7
7
|
> See **https://typescript-eslint.io/rules/no-redeclare** for documentation.
|
|
8
8
|
|
|
9
|
+
import TypeScriptOverlap from "@site/src/components/TypeScriptOverlap";
|
|
10
|
+
|
|
11
|
+
<TypeScriptOverlap />
|
|
12
|
+
|
|
9
13
|
This rule extends the base [`eslint/no-redeclare`](https://eslint.org/docs/rules/no-redeclare) rule.
|
|
10
14
|
It adds support for TypeScript function overloads, and declaration merging.
|
|
11
15
|
|
|
@@ -9,7 +9,7 @@ description: 'Enforce using the nullish coalescing operator instead of logical a
|
|
|
9
9
|
The `??` nullish coalescing runtime operator allows providing a default value when dealing with `null` or `undefined`.
|
|
10
10
|
Because the nullish coalescing operator _only_ coalesces when the original value is `null` or `undefined`, it is much safer than relying upon logical OR operator chaining `||`, which coalesces on any _falsy_ value.
|
|
11
11
|
|
|
12
|
-
This rule reports when you
|
|
12
|
+
This rule reports when you may consider replacing:
|
|
13
13
|
|
|
14
14
|
- An `||` operator with `??`
|
|
15
15
|
- An `||=` operator with `??=`
|
|
@@ -144,28 +144,28 @@ a ?? (b && c && d);
|
|
|
144
144
|
|
|
145
145
|
### `ignorePrimitives`
|
|
146
146
|
|
|
147
|
-
If you would like to ignore certain primitive types that can be falsy then you may pass an object containing a boolean value for each primitive:
|
|
147
|
+
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:
|
|
148
148
|
|
|
149
149
|
- `string: true`, ignores `null` or `undefined` unions with `string` (default: false).
|
|
150
150
|
- `number: true`, ignores `null` or `undefined` unions with `number` (default: false).
|
|
151
151
|
- `bigint: true`, ignores `null` or `undefined` unions with `bigint` (default: false).
|
|
152
152
|
- `boolean: true`, ignores `null` or `undefined` unions with `boolean` (default: false).
|
|
153
153
|
|
|
154
|
-
Incorrect code for `ignorePrimitives: { string:
|
|
154
|
+
Incorrect code for `ignorePrimitives: { string: false }`, and correct code for `ignorePrimitives: { string: true }`:
|
|
155
155
|
|
|
156
156
|
```ts
|
|
157
157
|
const foo: string | undefined = 'bar';
|
|
158
158
|
foo || 'a string';
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
-
Correct code for `ignorePrimitives: { string: true }`:
|
|
161
|
+
Correct code for both `ignorePrimitives: { string: false }` and `ignorePrimitives: { string: true }`:
|
|
162
162
|
|
|
163
163
|
```ts
|
|
164
164
|
const foo: string | undefined = 'bar';
|
|
165
165
|
foo ?? 'a string';
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
-
Also, if you would like to ignore all primitives types, you can set `ignorePrimitives: true`. It
|
|
168
|
+
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 }`.
|
|
169
169
|
|
|
170
170
|
## When Not To Use It
|
|
171
171
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.2-alpha.0+aefb2686a",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@eslint-community/regexpp": "^4.5.1",
|
|
60
|
-
"@typescript-eslint/scope-manager": "6.7.
|
|
61
|
-
"@typescript-eslint/type-utils": "6.7.
|
|
62
|
-
"@typescript-eslint/utils": "6.7.
|
|
63
|
-
"@typescript-eslint/visitor-keys": "6.7.
|
|
60
|
+
"@typescript-eslint/scope-manager": "6.7.2-alpha.0+aefb2686a",
|
|
61
|
+
"@typescript-eslint/type-utils": "6.7.2-alpha.0+aefb2686a",
|
|
62
|
+
"@typescript-eslint/utils": "6.7.2-alpha.0+aefb2686a",
|
|
63
|
+
"@typescript-eslint/visitor-keys": "6.7.2-alpha.0+aefb2686a",
|
|
64
64
|
"debug": "^4.3.4",
|
|
65
65
|
"graphemer": "^1.4.0",
|
|
66
66
|
"ignore": "^5.2.4",
|
|
@@ -73,13 +73,13 @@
|
|
|
73
73
|
"@types/marked": "*",
|
|
74
74
|
"@types/natural-compare": "*",
|
|
75
75
|
"@types/prettier": "*",
|
|
76
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "6.7.
|
|
77
|
-
"@typescript-eslint/rule-tester": "6.7.
|
|
76
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "6.7.1",
|
|
77
|
+
"@typescript-eslint/rule-tester": "6.7.2-alpha.0+aefb2686a",
|
|
78
78
|
"ajv": "^6.12.6",
|
|
79
79
|
"chalk": "^5.3.0",
|
|
80
80
|
"cross-fetch": "*",
|
|
81
81
|
"grapheme-splitter": "^1.0.4",
|
|
82
|
-
"jest": "29.
|
|
82
|
+
"jest": "29.7.0",
|
|
83
83
|
"jest-specific-snapshot": "^8.0.0",
|
|
84
84
|
"json-schema": "*",
|
|
85
85
|
"markdown-table": "^3.0.3",
|
|
@@ -103,5 +103,5 @@
|
|
|
103
103
|
"type": "opencollective",
|
|
104
104
|
"url": "https://opencollective.com/typescript-eslint"
|
|
105
105
|
},
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "aefb2686a58b73a81b400c516d02b8e6194cbed4"
|
|
107
107
|
}
|