@typescript-eslint/eslint-plugin 8.31.2-alpha.4 → 8.31.2-alpha.6
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.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"prefer-nullish-coalescing.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-nullish-coalescing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"prefer-nullish-coalescing.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-nullish-coalescing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,0BAA0B,CAAC;AAyCnE,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,sDAAsD,CAAC,EAAE,OAAO,CAAC;QACjE,qBAAqB,CAAC,EAAE,OAAO,CAAC;QAChC,sBAAsB,CAAC,EAAE,OAAO,CAAC;QACjC,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,6BAA6B,CAAC,EAAE,OAAO,CAAC;QACxC,gBAAgB,CAAC,EACb;YACE,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,OAAO,CAAC,EAAE,OAAO,CAAC;YAClB,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,MAAM,CAAC,EAAE,OAAO,CAAC;SAClB,GACD,IAAI,CAAC;QACT,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B;CACF,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB,mBAAmB,GACnB,6BAA6B,GAC7B,qBAAqB,GACrB,0BAA0B,GAC1B,gBAAgB,CAAC;;AAErB,wBA+kBG"}
|
@@ -37,6 +37,7 @@ const utils_1 = require("@typescript-eslint/utils");
|
|
37
37
|
const tsutils = __importStar(require("ts-api-utils"));
|
38
38
|
const ts = __importStar(require("typescript"));
|
39
39
|
const util_1 = require("../util");
|
40
|
+
const getWrappedCode_1 = require("../util/getWrappedCode");
|
40
41
|
const isMemberAccessLike = (0, util_1.isNodeOfTypes)([
|
41
42
|
utils_1.AST_NODE_TYPES.ChainExpression,
|
42
43
|
utils_1.AST_NODE_TYPES.Identifier,
|
@@ -354,7 +355,8 @@ exports.default = (0, util_1.createRule)({
|
|
354
355
|
if (operator == null) {
|
355
356
|
return;
|
356
357
|
}
|
357
|
-
const
|
358
|
+
const { nonNullishBranch, nullishBranch } = getBranchNodes(node, operator);
|
359
|
+
const nullishCoalescingParams = getNullishCoalescingParams(node, nonNullishBranch, nodesInsideTestExpression, operator);
|
358
360
|
if (nullishCoalescingParams.isFixable) {
|
359
361
|
context.report({
|
360
362
|
node,
|
@@ -366,7 +368,11 @@ exports.default = (0, util_1.createRule)({
|
|
366
368
|
messageId: 'suggestNullish',
|
367
369
|
data: { equals: '' },
|
368
370
|
fix(fixer) {
|
369
|
-
|
371
|
+
const nullishBranchText = (0, util_1.getTextWithParentheses)(context.sourceCode, nullishBranch);
|
372
|
+
const rightOperandReplacement = (0, util_1.isParenthesized)(nullishBranch, context.sourceCode)
|
373
|
+
? nullishBranchText
|
374
|
+
: (0, getWrappedCode_1.getWrappedCode)(nullishBranchText, (0, util_1.getOperatorPrecedenceForNode)(nullishBranch), util_1.OperatorPrecedence.Coalesce);
|
375
|
+
return fixer.replaceText(node, `${(0, util_1.getTextWithParentheses)(context.sourceCode, nullishCoalescingParams.nullishCoalescingLeftNode)} ?? ${rightOperandReplacement}`);
|
370
376
|
},
|
371
377
|
},
|
372
378
|
],
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"unified-signatures.d.ts","sourceRoot":"","sources":["../../src/rules/unified-signatures.ts"],"names":[],"mappings":"AAuDA,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,gCAAgC,CAAC,EAAE,OAAO,CAAC;QAC3C,iCAAiC,CAAC,EAAE,OAAO,CAAC;KAC7C;CACF,CAAC;;AAEF,
|
1
|
+
{"version":3,"file":"unified-signatures.d.ts","sourceRoot":"","sources":["../../src/rules/unified-signatures.ts"],"names":[],"mappings":"AAuDA,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,gCAAgC,CAAC,EAAE,OAAO,CAAC;QAC3C,iCAAiC,CAAC,EAAE,OAAO,CAAC;KAC7C;CACF,CAAC;;AAEF,wBA8kBG"}
|
@@ -147,6 +147,12 @@ exports.default = (0, util_1.createRule)({
|
|
147
147
|
}
|
148
148
|
/** Detect `a(x: number, y: number, z: number)` and `a(x: number, y: string, z: number)`. */
|
149
149
|
function signaturesDifferBySingleParameter(types1, types2) {
|
150
|
+
const firstParam1 = types1[0];
|
151
|
+
const firstParam2 = types2[0];
|
152
|
+
// exempt signatures with `this: void` from the rule
|
153
|
+
if (isThisVoidParam(firstParam1) || isThisVoidParam(firstParam2)) {
|
154
|
+
return undefined;
|
155
|
+
}
|
150
156
|
const index = getIndexOfFirstDifference(types1, types2, parametersAreEqual);
|
151
157
|
if (index == null) {
|
152
158
|
return undefined;
|
@@ -164,6 +170,16 @@ exports.default = (0, util_1.createRule)({
|
|
164
170
|
? { kind: 'single-parameter-difference', p0: a, p1: b }
|
165
171
|
: undefined;
|
166
172
|
}
|
173
|
+
function isThisParam(param) {
|
174
|
+
return (param != null &&
|
175
|
+
param.type === utils_1.AST_NODE_TYPES.Identifier &&
|
176
|
+
param.name === 'this');
|
177
|
+
}
|
178
|
+
function isThisVoidParam(param) {
|
179
|
+
return (isThisParam(param) &&
|
180
|
+
param.typeAnnotation?.typeAnnotation.type ===
|
181
|
+
utils_1.AST_NODE_TYPES.TSVoidKeyword);
|
182
|
+
}
|
167
183
|
/**
|
168
184
|
* Detect `a(): void` and `a(x: number): void`.
|
169
185
|
* Returns the parameter declaration (`x: number` in this example) that should be optional/rest, and overload it's a part of.
|
@@ -175,6 +191,17 @@ exports.default = (0, util_1.createRule)({
|
|
175
191
|
const longer = sig1.length < sig2.length ? sig2 : sig1;
|
176
192
|
const shorter = sig1.length < sig2.length ? sig1 : sig2;
|
177
193
|
const shorterSig = sig1.length < sig2.length ? a : b;
|
194
|
+
const firstParam1 = sig1.at(0);
|
195
|
+
const firstParam2 = sig2.at(0);
|
196
|
+
// If one signature has explicit this type and another doesn't, they can't
|
197
|
+
// be unified.
|
198
|
+
if (isThisParam(firstParam1) !== isThisParam(firstParam2)) {
|
199
|
+
return undefined;
|
200
|
+
}
|
201
|
+
// exempt signatures with `this: void` from the rule
|
202
|
+
if (isThisVoidParam(firstParam1) || isThisVoidParam(firstParam2)) {
|
203
|
+
return undefined;
|
204
|
+
}
|
178
205
|
// If one is has 2+ parameters more than the other, they must all be optional/rest.
|
179
206
|
// Differ by optional parameters: f() and f(x), f() and f(x, ?y, ...z)
|
180
207
|
// Not allowed: f() and f(x, y)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.31.2-alpha.
|
3
|
+
"version": "8.31.2-alpha.6",
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
5
5
|
"files": [
|
6
6
|
"dist",
|
@@ -62,10 +62,10 @@
|
|
62
62
|
},
|
63
63
|
"dependencies": {
|
64
64
|
"@eslint-community/regexpp": "^4.10.0",
|
65
|
-
"@typescript-eslint/scope-manager": "8.31.2-alpha.
|
66
|
-
"@typescript-eslint/type-utils": "8.31.2-alpha.
|
67
|
-
"@typescript-eslint/utils": "8.31.2-alpha.
|
68
|
-
"@typescript-eslint/visitor-keys": "8.31.2-alpha.
|
65
|
+
"@typescript-eslint/scope-manager": "8.31.2-alpha.6",
|
66
|
+
"@typescript-eslint/type-utils": "8.31.2-alpha.6",
|
67
|
+
"@typescript-eslint/utils": "8.31.2-alpha.6",
|
68
|
+
"@typescript-eslint/visitor-keys": "8.31.2-alpha.6",
|
69
69
|
"graphemer": "^1.4.0",
|
70
70
|
"ignore": "^5.3.1",
|
71
71
|
"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.31.2-alpha.
|
79
|
-
"@typescript-eslint/rule-tester": "8.31.2-alpha.
|
78
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.31.2-alpha.6",
|
79
|
+
"@typescript-eslint/rule-tester": "8.31.2-alpha.6",
|
80
80
|
"@vitest/coverage-v8": "^3.1.1",
|
81
81
|
"ajv": "^6.12.6",
|
82
82
|
"cross-fetch": "*",
|