@typescript-eslint/eslint-plugin 8.29.2-alpha.3 → 8.29.2-alpha.5
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/index.d.ts +1 -1
- package/dist/raw-plugin.d.ts +1 -1
- package/dist/rules/index.d.ts +1 -1
- package/dist/rules/no-explicit-any.d.ts +1 -1
- package/dist/rules/no-explicit-any.d.ts.map +1 -1
- package/dist/rules/no-explicit-any.js +41 -13
- package/dist/rules/promise-function-async.d.ts +2 -2
- package/dist/rules/promise-function-async.d.ts.map +1 -1
- package/dist/rules/promise-function-async.js +6 -1
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
@@ -820,7 +820,7 @@ declare const _default: {
|
|
820
820
|
'prefer-return-this-type': import("@typescript-eslint/utils/ts-eslint").RuleModule<"useThisType", [], import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
821
821
|
'prefer-string-starts-ends-with': import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./rules/prefer-string-starts-ends-with").MessageIds, import("./rules/prefer-string-starts-ends-with").Options, import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
822
822
|
'prefer-ts-expect-error': import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferExpectErrorComment", [], import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
823
|
-
'promise-function-async': import("@typescript-eslint/utils/ts-eslint").RuleModule<"
|
823
|
+
'promise-function-async': import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./rules/promise-function-async").MessageIds, import("./rules/promise-function-async").Options, import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
824
824
|
'related-getter-setter-pairs': import("@typescript-eslint/utils/ts-eslint").RuleModule<"mismatch", [], import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
825
825
|
'require-array-sort-compare': import("@typescript-eslint/utils/ts-eslint").RuleModule<"requireCompare", import("./rules/require-array-sort-compare").Options, import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
826
826
|
'require-await': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingAwait" | "removeAsync", [], import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
package/dist/raw-plugin.d.ts
CHANGED
@@ -843,7 +843,7 @@ declare const _default: {
|
|
843
843
|
'prefer-return-this-type': TSESLint.RuleModule<"useThisType", [], import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
844
844
|
'prefer-string-starts-ends-with': TSESLint.RuleModule<import("./rules/prefer-string-starts-ends-with").MessageIds, import("./rules/prefer-string-starts-ends-with").Options, import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
845
845
|
'prefer-ts-expect-error': TSESLint.RuleModule<"preferExpectErrorComment", [], import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
846
|
-
'promise-function-async': TSESLint.RuleModule<"
|
846
|
+
'promise-function-async': TSESLint.RuleModule<import("./rules/promise-function-async").MessageIds, import("./rules/promise-function-async").Options, import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
847
847
|
'related-getter-setter-pairs': TSESLint.RuleModule<"mismatch", [], import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
848
848
|
'require-array-sort-compare': TSESLint.RuleModule<"requireCompare", import("./rules/require-array-sort-compare").Options, import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
849
849
|
'require-await': TSESLint.RuleModule<"missingAwait" | "removeAsync", [], import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
package/dist/rules/index.d.ts
CHANGED
@@ -153,7 +153,7 @@ declare const rules: {
|
|
153
153
|
'prefer-return-this-type': import("@typescript-eslint/utils/ts-eslint").RuleModule<"useThisType", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
154
154
|
'prefer-string-starts-ends-with': import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./prefer-string-starts-ends-with").MessageIds, import("./prefer-string-starts-ends-with").Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
155
155
|
'prefer-ts-expect-error': import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferExpectErrorComment", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
156
|
-
'promise-function-async': import("@typescript-eslint/utils/ts-eslint").RuleModule<"
|
156
|
+
'promise-function-async': import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./promise-function-async").MessageIds, import("./promise-function-async").Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
157
157
|
'related-getter-setter-pairs': import("@typescript-eslint/utils/ts-eslint").RuleModule<"mismatch", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
158
158
|
'require-array-sort-compare': import("@typescript-eslint/utils/ts-eslint").RuleModule<"requireCompare", import("./require-array-sort-compare").Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
159
159
|
'require-await': import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingAwait" | "removeAsync", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
@@ -5,7 +5,7 @@ export type Options = [
|
|
5
5
|
ignoreRestArgs?: boolean;
|
6
6
|
}
|
7
7
|
];
|
8
|
-
export type MessageIds = 'suggestNever' | 'suggestUnknown' | 'unexpectedAny';
|
8
|
+
export type MessageIds = 'suggestNever' | 'suggestPropertyKey' | 'suggestUnknown' | 'unexpectedAny';
|
9
9
|
declare const _default: TSESLint.RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
10
10
|
export default _default;
|
11
11
|
//# sourceMappingURL=no-explicit-any.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"no-explicit-any.d.ts","sourceRoot":"","sources":["../../src/rules/no-explicit-any.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,0BAA0B,CAAC;AAMnE,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B;CACF,CAAC;AACF,MAAM,MAAM,UAAU,
|
1
|
+
{"version":3,"file":"no-explicit-any.d.ts","sourceRoot":"","sources":["../../src/rules/no-explicit-any.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,0BAA0B,CAAC;AAMnE,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAClB,cAAc,GACd,oBAAoB,GACpB,gBAAgB,GAChB,eAAe,CAAC;;AAEpB,wBAuOG"}
|
@@ -14,6 +14,7 @@ exports.default = (0, util_1.createRule)({
|
|
14
14
|
hasSuggestions: true,
|
15
15
|
messages: {
|
16
16
|
suggestNever: "Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of.",
|
17
|
+
suggestPropertyKey: 'Use `PropertyKey` instead, this is more explicit than `keyof any`.',
|
17
18
|
suggestUnknown: 'Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct.',
|
18
19
|
unexpectedAny: 'Unexpected any. Specify a different type.',
|
19
20
|
},
|
@@ -133,30 +134,57 @@ exports.default = (0, util_1.createRule)({
|
|
133
134
|
return (isGreatGrandparentRestElement(node) ||
|
134
135
|
isGreatGreatGrandparentRestElement(node));
|
135
136
|
}
|
137
|
+
/**
|
138
|
+
* Checks if the node is within a keyof any expression
|
139
|
+
* @param node the node to be validated.
|
140
|
+
* @returns true if the node is within a keyof any expression, false otherwise
|
141
|
+
* @private
|
142
|
+
*/
|
143
|
+
function isNodeWithinKeyofAny(node) {
|
144
|
+
return (node.parent.type === utils_1.AST_NODE_TYPES.TSTypeOperator &&
|
145
|
+
node.parent.operator === 'keyof');
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* Creates a fixer that replaces a keyof any with PropertyKey
|
149
|
+
* @param node the node to be fixed.
|
150
|
+
* @returns a function that will fix the node.
|
151
|
+
* @private
|
152
|
+
*/
|
153
|
+
function createPropertyKeyFixer(node) {
|
154
|
+
return (fixer) => {
|
155
|
+
return fixer.replaceText(node.parent, 'PropertyKey');
|
156
|
+
};
|
157
|
+
}
|
136
158
|
return {
|
137
159
|
TSAnyKeyword(node) {
|
160
|
+
const isKeyofAny = isNodeWithinKeyofAny(node);
|
138
161
|
if (ignoreRestArgs && isNodeDescendantOfRestElementInFunction(node)) {
|
139
162
|
return;
|
140
163
|
}
|
141
164
|
const fixOrSuggest = {
|
142
165
|
fix: null,
|
143
|
-
suggest:
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
166
|
+
suggest: isKeyofAny
|
167
|
+
? [
|
168
|
+
{
|
169
|
+
messageId: 'suggestPropertyKey',
|
170
|
+
fix: createPropertyKeyFixer(node),
|
171
|
+
},
|
172
|
+
]
|
173
|
+
: [
|
174
|
+
{
|
175
|
+
messageId: 'suggestUnknown',
|
176
|
+
fix: fixer => fixer.replaceText(node, 'unknown'),
|
148
177
|
},
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
fix(fixer) {
|
153
|
-
return fixer.replaceText(node, 'never');
|
178
|
+
{
|
179
|
+
messageId: 'suggestNever',
|
180
|
+
fix: fixer => fixer.replaceText(node, 'never'),
|
154
181
|
},
|
155
|
-
|
156
|
-
],
|
182
|
+
],
|
157
183
|
};
|
158
184
|
if (fixToUnknown) {
|
159
|
-
fixOrSuggest.fix =
|
185
|
+
fixOrSuggest.fix = isKeyofAny
|
186
|
+
? createPropertyKeyFixer(node)
|
187
|
+
: fixer => fixer.replaceText(node, 'unknown');
|
160
188
|
}
|
161
189
|
context.report({
|
162
190
|
node,
|
@@ -8,7 +8,7 @@ export type Options = [
|
|
8
8
|
checkMethodDeclarations?: boolean;
|
9
9
|
}
|
10
10
|
];
|
11
|
-
export type MessageIds = 'missingAsync';
|
12
|
-
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<
|
11
|
+
export type MessageIds = 'missingAsync' | 'missingAsyncHybridReturn';
|
12
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
13
13
|
export default _default;
|
14
14
|
//# sourceMappingURL=promise-function-async.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"promise-function-async.d.ts","sourceRoot":"","sources":["../../src/rules/promise-function-async.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;QAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,yBAAyB,CAAC,EAAE,OAAO,CAAC;QACpC,wBAAwB,CAAC,EAAE,OAAO,CAAC;QACnC,uBAAuB,CAAC,EAAE,OAAO,CAAC;KACnC;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,cAAc,CAAC;;
|
1
|
+
{"version":3,"file":"promise-function-async.d.ts","sourceRoot":"","sources":["../../src/rules/promise-function-async.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;QAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,yBAAyB,CAAC,EAAE,OAAO,CAAC;QACpC,wBAAwB,CAAC,EAAE,OAAO,CAAC;QACnC,uBAAuB,CAAC,EAAE,OAAO,CAAC;KACnC;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,0BAA0B,CAAC;;AAErE,wBAyPG"}
|
@@ -47,6 +47,7 @@ exports.default = (0, util_1.createRule)({
|
|
47
47
|
fixable: 'code',
|
48
48
|
messages: {
|
49
49
|
missingAsync: 'Functions that return promises must be async.',
|
50
|
+
missingAsyncHybridReturn: 'Functions that return promises must be async. Consider adding an explicit return type annotation if the function is intended to return a union of promise and non-promise types.',
|
50
51
|
},
|
51
52
|
schema: [
|
52
53
|
{
|
@@ -133,10 +134,14 @@ exports.default = (0, util_1.createRule)({
|
|
133
134
|
returnTypes.every(type => (0, util_1.containsAllTypesByName)(type, true, allAllowedPromiseNames,
|
134
135
|
// If no return type is explicitly set, we check if any parts of the return type match a Promise (instead of requiring all to match).
|
135
136
|
node.returnType == null))) {
|
137
|
+
const isHybridReturnType = returnTypes.some(type => type.isUnion() &&
|
138
|
+
!type.types.every(part => (0, util_1.containsAllTypesByName)(part, true, allAllowedPromiseNames)));
|
136
139
|
context.report({
|
137
140
|
loc: (0, util_1.getFunctionHeadLoc)(node, context.sourceCode),
|
138
141
|
node,
|
139
|
-
messageId:
|
142
|
+
messageId: isHybridReturnType
|
143
|
+
? 'missingAsyncHybridReturn'
|
144
|
+
: 'missingAsync',
|
140
145
|
fix: fixer => {
|
141
146
|
if (node.parent.type === utils_1.AST_NODE_TYPES.MethodDefinition ||
|
142
147
|
(node.parent.type === utils_1.AST_NODE_TYPES.Property &&
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.29.2-alpha.
|
3
|
+
"version": "8.29.2-alpha.5",
|
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.29.2-alpha.
|
66
|
-
"@typescript-eslint/type-utils": "8.29.2-alpha.
|
67
|
-
"@typescript-eslint/utils": "8.29.2-alpha.
|
68
|
-
"@typescript-eslint/visitor-keys": "8.29.2-alpha.
|
65
|
+
"@typescript-eslint/scope-manager": "8.29.2-alpha.5",
|
66
|
+
"@typescript-eslint/type-utils": "8.29.2-alpha.5",
|
67
|
+
"@typescript-eslint/utils": "8.29.2-alpha.5",
|
68
|
+
"@typescript-eslint/visitor-keys": "8.29.2-alpha.5",
|
69
69
|
"graphemer": "^1.4.0",
|
70
70
|
"ignore": "^5.3.1",
|
71
71
|
"natural-compare": "^1.4.0",
|
@@ -76,8 +76,8 @@
|
|
76
76
|
"@types/marked": "^5.0.2",
|
77
77
|
"@types/mdast": "^4.0.3",
|
78
78
|
"@types/natural-compare": "*",
|
79
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.29.2-alpha.
|
80
|
-
"@typescript-eslint/rule-tester": "8.29.2-alpha.
|
79
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.29.2-alpha.5",
|
80
|
+
"@typescript-eslint/rule-tester": "8.29.2-alpha.5",
|
81
81
|
"ajv": "^6.12.6",
|
82
82
|
"cross-env": "^7.0.3",
|
83
83
|
"cross-fetch": "*",
|