@typescript-eslint/eslint-plugin 8.70.1-alpha.0 → 8.70.1-alpha.10
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-explicit-any.js +10 -2
- package/dist/rules/no-generated-empty-object-type.js +6 -2
- package/dist/rules/no-misused-spread.js +4 -1
- package/dist/rules/no-unnecessary-type-assertion.js +1 -1
- package/dist/rules/no-unnecessary-type-parameters.js +16 -18
- package/dist/rules/no-useless-default-assignment.js +8 -2
- package/dist/util/getWrappingFixer.js +0 -1
- package/package.json +8 -8
|
@@ -155,6 +155,14 @@ exports.default = (0, util_1.createRule)({
|
|
|
155
155
|
return fixer.replaceText(node.parent, 'PropertyKey');
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
|
+
function createUnknownFixer(node) {
|
|
159
|
+
return (fixer) => {
|
|
160
|
+
return fixer.replaceText(node, node.parent.type === utils_1.AST_NODE_TYPES.TSTypeAnnotation &&
|
|
161
|
+
isNodeRestElementInFunction(node.parent.parent)
|
|
162
|
+
? 'unknown[]'
|
|
163
|
+
: 'unknown');
|
|
164
|
+
};
|
|
165
|
+
}
|
|
158
166
|
return {
|
|
159
167
|
TSAnyKeyword(node) {
|
|
160
168
|
const isKeyofAny = isNodeWithinKeyofAny(node);
|
|
@@ -173,7 +181,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
173
181
|
: [
|
|
174
182
|
{
|
|
175
183
|
messageId: 'suggestUnknown',
|
|
176
|
-
fix:
|
|
184
|
+
fix: createUnknownFixer(node),
|
|
177
185
|
},
|
|
178
186
|
{
|
|
179
187
|
messageId: 'suggestNever',
|
|
@@ -184,7 +192,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
184
192
|
if (fixToUnknown) {
|
|
185
193
|
fixOrSuggest.fix = isKeyofAny
|
|
186
194
|
? createPropertyKeyFixer(node)
|
|
187
|
-
:
|
|
195
|
+
: createUnknownFixer(node);
|
|
188
196
|
}
|
|
189
197
|
context.report({
|
|
190
198
|
node,
|
|
@@ -63,8 +63,12 @@ exports.default = (0, util_1.createRule)({
|
|
|
63
63
|
type.getCallSignatures().length === 0 &&
|
|
64
64
|
type.getConstructSignatures().length === 0 &&
|
|
65
65
|
// Types still awaiting type arguments, such as `Record<T, unknown>`
|
|
66
|
-
// inside a generic declaration, also have no members yet.
|
|
67
|
-
|
|
66
|
+
// inside a generic declaration, also have no members yet. Every
|
|
67
|
+
// primitive is assignable to `{}`, so probing with more than one of
|
|
68
|
+
// them rules those out: a mapped type whose keys are not resolved yet,
|
|
69
|
+
// such as `{ [K in Keys<T>]: K }`, accepts `number` but not `string`.
|
|
70
|
+
checker.isTypeAssignableTo(checker.getNumberType(), type) &&
|
|
71
|
+
checker.isTypeAssignableTo(checker.getStringType(), type));
|
|
68
72
|
}
|
|
69
73
|
function containsEmptyObjectType(type) {
|
|
70
74
|
return (isEmptyObjectType(type) ||
|
|
@@ -98,7 +98,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
98
98
|
}
|
|
99
99
|
function getMapSpreadSuggestions(node, type) {
|
|
100
100
|
const types = tsutils.unionConstituents(type);
|
|
101
|
-
if (types.some(t => !
|
|
101
|
+
if (types.some(t => !isIterableMap(services.program, t))) {
|
|
102
102
|
return null;
|
|
103
103
|
}
|
|
104
104
|
if (node.parent.type === utils_1.AST_NODE_TYPES.ObjectExpression &&
|
|
@@ -252,6 +252,9 @@ function isClassDeclaration(type) {
|
|
|
252
252
|
function isMap(program, type) {
|
|
253
253
|
return isTypeRecurser(type, t => (0, util_1.isBuiltinSymbolLike)(program, t, ['Map', 'ReadonlyMap', 'WeakMap']));
|
|
254
254
|
}
|
|
255
|
+
function isIterableMap(program, type) {
|
|
256
|
+
return isTypeRecurser(type, t => (0, util_1.isBuiltinSymbolLike)(program, t, ['Map', 'ReadonlyMap']));
|
|
257
|
+
}
|
|
255
258
|
function isTypeRecurser(type, predicate) {
|
|
256
259
|
if (type.isUnionOrIntersection()) {
|
|
257
260
|
return type.types.some(t => isTypeRecurser(t, predicate));
|
|
@@ -178,7 +178,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
178
178
|
}
|
|
179
179
|
if (((0, util_1.isTypeFlagSet)(uncast, ts.TypeFlags.NonPrimitive) &&
|
|
180
180
|
!(0, util_1.isTypeFlagSet)(cast, ts.TypeFlags.NonPrimitive)) ||
|
|
181
|
-
|
|
181
|
+
hasIndexSignature(uncast) !== hasIndexSignature(cast) ||
|
|
182
182
|
containsAny(uncast) ||
|
|
183
183
|
containsAny(cast) ||
|
|
184
184
|
(containsTypeVariable(cast) && !containsTypeVariable(uncast))) {
|
|
@@ -101,27 +101,25 @@ exports.default = (0, util_1.createRule)({
|
|
|
101
101
|
for (const reference of smTypeParameterVariable.references) {
|
|
102
102
|
if (reference.isTypeReference) {
|
|
103
103
|
const referenceNode = reference.identifier;
|
|
104
|
-
const
|
|
104
|
+
const isWeakPrecedenceConstraint = constraint?.type === utils_1.AST_NODE_TYPES.TSUnionType ||
|
|
105
105
|
constraint?.type === utils_1.AST_NODE_TYPES.TSIntersectionType ||
|
|
106
|
-
constraint?.type === utils_1.AST_NODE_TYPES.TSConditionalType
|
|
107
|
-
|
|
108
|
-
utils_1.AST_NODE_TYPES.
|
|
109
|
-
utils_1.AST_NODE_TYPES.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
})(fixer);
|
|
121
|
-
yield fixResult;
|
|
106
|
+
constraint?.type === utils_1.AST_NODE_TYPES.TSConditionalType ||
|
|
107
|
+
constraint?.type === utils_1.AST_NODE_TYPES.TSTypeOperator ||
|
|
108
|
+
constraint?.type === utils_1.AST_NODE_TYPES.TSFunctionType ||
|
|
109
|
+
constraint?.type === utils_1.AST_NODE_TYPES.TSConstructorType;
|
|
110
|
+
const grandparent = (0, util_1.nullThrows)(referenceNode.parent.parent, util_1.NullThrowsReasons.MissingParent);
|
|
111
|
+
const isWeakPrecedenceTypeParent = grandparent.type === utils_1.AST_NODE_TYPES.TSArrayType ||
|
|
112
|
+
grandparent.type === utils_1.AST_NODE_TYPES.TSIndexedAccessType ||
|
|
113
|
+
grandparent.type === utils_1.AST_NODE_TYPES.TSIntersectionType ||
|
|
114
|
+
grandparent.type === utils_1.AST_NODE_TYPES.TSUnionType ||
|
|
115
|
+
grandparent.type === utils_1.AST_NODE_TYPES.TSConditionalType ||
|
|
116
|
+
grandparent.type === utils_1.AST_NODE_TYPES.TSTypeOperator;
|
|
117
|
+
if (isWeakPrecedenceConstraint &&
|
|
118
|
+
isWeakPrecedenceTypeParent) {
|
|
119
|
+
yield fixer.replaceText(referenceNode.parent, `(${constraintText})`);
|
|
122
120
|
}
|
|
123
121
|
else {
|
|
124
|
-
yield fixer.replaceText(referenceNode, constraintText);
|
|
122
|
+
yield fixer.replaceText(referenceNode.parent, constraintText);
|
|
125
123
|
}
|
|
126
124
|
}
|
|
127
125
|
}
|
|
@@ -183,8 +183,14 @@ exports.default = (0, util_1.createRule)({
|
|
|
183
183
|
if (elementIndex < 0 || elementIndex >= tupleArgs.length) {
|
|
184
184
|
return;
|
|
185
185
|
}
|
|
186
|
-
const
|
|
187
|
-
if (
|
|
186
|
+
const { fixedLength, minLength } = sourceType.target;
|
|
187
|
+
if (elementIndex >= minLength) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const elementTypes = elementIndex < fixedLength
|
|
191
|
+
? [tupleArgs[elementIndex]]
|
|
192
|
+
: tupleArgs.slice(fixedLength);
|
|
193
|
+
if (!elementTypes.some(canBeUndefined)) {
|
|
188
194
|
reportUselessDefaultAssignment(node, 'property');
|
|
189
195
|
}
|
|
190
196
|
}
|
|
@@ -73,7 +73,6 @@ function isStrongPrecedenceNode(innerNode) {
|
|
|
73
73
|
return (innerNode.type === utils_1.AST_NODE_TYPES.Literal ||
|
|
74
74
|
innerNode.type === utils_1.AST_NODE_TYPES.Identifier ||
|
|
75
75
|
innerNode.type === utils_1.AST_NODE_TYPES.TSTypeReference ||
|
|
76
|
-
innerNode.type === utils_1.AST_NODE_TYPES.TSTypeOperator ||
|
|
77
76
|
innerNode.type === utils_1.AST_NODE_TYPES.ArrayExpression ||
|
|
78
77
|
innerNode.type === utils_1.AST_NODE_TYPES.ObjectExpression ||
|
|
79
78
|
innerNode.type === utils_1.AST_NODE_TYPES.MemberExpression ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
|
3
|
-
"version": "8.70.1-alpha.
|
|
3
|
+
"version": "8.70.1-alpha.10",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@eslint-community/regexpp": "^4.12.2",
|
|
50
|
-
"@typescript-eslint/scope-manager": "8.70.1-alpha.
|
|
51
|
-
"@typescript-eslint/type-utils": "8.70.1-alpha.
|
|
52
|
-
"@typescript-eslint/utils": "8.70.1-alpha.
|
|
53
|
-
"@typescript-eslint/visitor-keys": "8.70.1-alpha.
|
|
50
|
+
"@typescript-eslint/scope-manager": "8.70.1-alpha.10",
|
|
51
|
+
"@typescript-eslint/type-utils": "8.70.1-alpha.10",
|
|
52
|
+
"@typescript-eslint/utils": "8.70.1-alpha.10",
|
|
53
|
+
"@typescript-eslint/visitor-keys": "8.70.1-alpha.10",
|
|
54
54
|
"ignore": "^7.0.5",
|
|
55
55
|
"natural-compare": "^1.4.0",
|
|
56
56
|
"ts-api-utils": "^2.5.0"
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"@types/mdast": "^4.0.4",
|
|
61
61
|
"@types/natural-compare": "^1.4.3",
|
|
62
62
|
"@types/react": "^18.3.21",
|
|
63
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.70.1-alpha.
|
|
64
|
-
"@typescript-eslint/rule-tester": "8.70.1-alpha.
|
|
63
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.70.1-alpha.10",
|
|
64
|
+
"@typescript-eslint/rule-tester": "8.70.1-alpha.10",
|
|
65
65
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
66
66
|
"@vitest/coverage-v8": "^4.0.18",
|
|
67
67
|
"ajv": "^6.12.6",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"vitest": "^4.0.18"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
|
-
"@typescript-eslint/parser": "^8.70.1-alpha.
|
|
84
|
+
"@typescript-eslint/parser": "^8.70.1-alpha.10",
|
|
85
85
|
"eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
|
|
86
86
|
"typescript": ">=4.8.4 <6.1.0"
|
|
87
87
|
},
|