@typescript-eslint/eslint-plugin 8.67.0 → 8.68.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/CHANGELOG.md +5906 -0
- package/dist/configs/eslint-recommended-raw.js +1 -0
- package/dist/configs/eslintrc/all.js +1 -0
- package/dist/configs/eslintrc/base.js +1 -0
- package/dist/configs/eslintrc/disable-type-checked.js +1 -0
- package/dist/configs/eslintrc/eslint-recommended.js +1 -0
- package/dist/configs/eslintrc/recommended-type-checked-only.js +1 -0
- package/dist/configs/eslintrc/recommended-type-checked.js +1 -0
- package/dist/configs/eslintrc/recommended.js +1 -0
- package/dist/configs/eslintrc/strict-type-checked-only.js +1 -0
- package/dist/configs/eslintrc/strict-type-checked.js +1 -0
- package/dist/configs/eslintrc/strict.js +1 -0
- package/dist/configs/eslintrc/stylistic-type-checked-only.js +1 -0
- package/dist/configs/eslintrc/stylistic-type-checked.js +1 -0
- package/dist/configs/eslintrc/stylistic.js +1 -0
- package/dist/configs/flat/all.js +1 -0
- package/dist/configs/flat/base.js +1 -0
- package/dist/configs/flat/disable-type-checked.js +1 -0
- package/dist/configs/flat/eslint-recommended.js +1 -0
- package/dist/configs/flat/recommended-type-checked-only.js +1 -0
- package/dist/configs/flat/recommended-type-checked.js +1 -0
- package/dist/configs/flat/recommended.js +1 -0
- package/dist/configs/flat/strict-type-checked-only.js +1 -0
- package/dist/configs/flat/strict-type-checked.js +1 -0
- package/dist/configs/flat/strict.js +1 -0
- package/dist/configs/flat/stylistic-type-checked-only.js +1 -0
- package/dist/configs/flat/stylistic-type-checked.js +1 -0
- package/dist/configs/flat/stylistic.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -0
- package/dist/raw-plugin.d.ts +1 -1
- package/dist/raw-plugin.js +1 -0
- package/dist/rules/adjacent-overload-signatures.js +1 -0
- package/dist/rules/array-type.js +1 -0
- package/dist/rules/await-thenable.js +1 -0
- package/dist/rules/ban-ts-comment.js +1 -0
- package/dist/rules/ban-tslint-comment.js +1 -0
- package/dist/rules/class-literal-property-style.js +1 -0
- package/dist/rules/class-methods-use-this.js +1 -0
- package/dist/rules/consistent-generic-constructors.js +1 -0
- package/dist/rules/consistent-indexed-object-style.js +1 -0
- package/dist/rules/consistent-return.js +1 -0
- package/dist/rules/consistent-type-assertions.js +1 -0
- package/dist/rules/consistent-type-definitions.js +1 -0
- package/dist/rules/consistent-type-exports.js +1 -0
- package/dist/rules/consistent-type-imports.js +1 -0
- package/dist/rules/default-param-last.js +1 -0
- package/dist/rules/dot-notation.js +1 -0
- package/dist/rules/enum-utils/shared.d.ts +5 -0
- package/dist/rules/enum-utils/shared.js +68 -0
- package/dist/rules/explicit-function-return-type.js +1 -0
- package/dist/rules/explicit-member-accessibility.js +1 -0
- package/dist/rules/explicit-module-boundary-types.js +1 -0
- package/dist/rules/index.d.ts +1 -1
- package/dist/rules/index.js +1 -0
- package/dist/rules/init-declarations.js +1 -0
- package/dist/rules/max-params.js +1 -0
- package/dist/rules/member-ordering.js +1 -0
- package/dist/rules/method-signature-style.js +1 -0
- package/dist/rules/naming-convention-utils/enums.js +1 -0
- package/dist/rules/naming-convention-utils/format.js +1 -0
- package/dist/rules/naming-convention-utils/index.js +1 -0
- package/dist/rules/naming-convention-utils/parse-options.js +1 -0
- package/dist/rules/naming-convention-utils/schema.js +1 -0
- package/dist/rules/naming-convention-utils/shared.js +1 -0
- package/dist/rules/naming-convention-utils/types.js +1 -0
- package/dist/rules/naming-convention-utils/validator.js +1 -0
- package/dist/rules/naming-convention.js +1 -0
- package/dist/rules/no-array-constructor.js +1 -0
- package/dist/rules/no-array-delete.js +1 -0
- package/dist/rules/no-base-to-string.js +1 -0
- package/dist/rules/no-confusing-non-null-assertion.js +1 -0
- package/dist/rules/no-confusing-void-expression.js +8 -9
- package/dist/rules/no-deprecated.js +1 -0
- package/dist/rules/no-dupe-class-members.js +1 -0
- package/dist/rules/no-duplicate-enum-values.js +1 -0
- package/dist/rules/no-duplicate-type-constituents.js +1 -0
- package/dist/rules/no-dynamic-delete.js +1 -0
- package/dist/rules/no-empty-function.js +1 -0
- package/dist/rules/no-empty-interface.js +1 -0
- package/dist/rules/no-empty-object-type.js +9 -4
- package/dist/rules/no-explicit-any.js +1 -0
- package/dist/rules/no-extra-non-null-assertion.js +1 -0
- package/dist/rules/no-extraneous-class.js +1 -0
- package/dist/rules/no-floating-promises.js +64 -55
- package/dist/rules/no-for-in-array.js +1 -0
- package/dist/rules/no-implied-eval.js +1 -0
- package/dist/rules/no-import-type-side-effects.js +1 -0
- package/dist/rules/no-inferrable-types.js +1 -0
- package/dist/rules/no-invalid-this.js +1 -0
- package/dist/rules/no-invalid-void-type.js +1 -0
- package/dist/rules/no-loop-func.js +1 -0
- package/dist/rules/no-loss-of-precision.js +1 -0
- package/dist/rules/no-magic-numbers.js +1 -0
- package/dist/rules/no-meaningless-void-operator.js +1 -0
- package/dist/rules/no-misused-new.js +1 -0
- package/dist/rules/no-misused-promises.js +1 -0
- package/dist/rules/no-misused-spread.js +1 -0
- package/dist/rules/no-mixed-enums.js +1 -0
- package/dist/rules/no-namespace.js +1 -0
- package/dist/rules/no-non-null-asserted-nullish-coalescing.js +1 -0
- package/dist/rules/no-non-null-asserted-optional-chain.js +1 -0
- package/dist/rules/no-non-null-assertion.js +1 -0
- package/dist/rules/no-redeclare.js +1 -0
- package/dist/rules/no-redundant-type-constituents.js +1 -0
- package/dist/rules/no-require-imports.js +1 -0
- package/dist/rules/no-restricted-imports.js +1 -0
- package/dist/rules/no-restricted-types.js +1 -0
- package/dist/rules/no-shadow.js +1 -0
- package/dist/rules/no-this-alias.js +1 -0
- package/dist/rules/no-type-alias.js +1 -0
- package/dist/rules/no-unnecessary-boolean-literal-compare.js +1 -0
- package/dist/rules/no-unnecessary-condition.js +1 -0
- package/dist/rules/no-unnecessary-parameter-property-assignment.js +1 -0
- package/dist/rules/no-unnecessary-qualifier.js +1 -0
- package/dist/rules/no-unnecessary-template-expression.js +3 -14
- package/dist/rules/no-unnecessary-type-arguments.js +1 -0
- package/dist/rules/no-unnecessary-type-assertion.d.ts +1 -2
- package/dist/rules/no-unnecessary-type-assertion.js +14 -39
- package/dist/rules/no-unnecessary-type-constraint.js +1 -0
- package/dist/rules/no-unnecessary-type-conversion.js +1 -0
- package/dist/rules/no-unnecessary-type-parameters.js +1 -0
- package/dist/rules/no-unsafe-argument.js +2 -91
- package/dist/rules/no-unsafe-assignment.js +1 -0
- package/dist/rules/no-unsafe-call.js +1 -0
- package/dist/rules/no-unsafe-declaration-merging.js +1 -0
- package/dist/rules/no-unsafe-enum-comparison.js +3 -113
- package/dist/rules/no-unsafe-function-type.js +1 -0
- package/dist/rules/no-unsafe-member-access.js +1 -0
- package/dist/rules/no-unsafe-return.js +1 -0
- package/dist/rules/no-unsafe-type-assertion.js +1 -0
- package/dist/rules/no-unsafe-unary-minus.js +1 -0
- package/dist/rules/no-unused-expressions.js +1 -0
- package/dist/rules/no-unused-private-class-members.js +1 -0
- package/dist/rules/no-unused-vars.js +1 -0
- package/dist/rules/no-use-before-define.js +1 -0
- package/dist/rules/no-useless-constructor.js +1 -0
- package/dist/rules/no-useless-default-assignment.js +1 -0
- package/dist/rules/no-useless-empty-export.js +1 -0
- package/dist/rules/no-var-requires.js +1 -0
- package/dist/rules/no-wrapper-object-types.js +1 -0
- package/dist/rules/non-nullable-type-assertion-style.js +1 -0
- package/dist/rules/only-throw-error.js +1 -0
- package/dist/rules/parameter-properties.js +1 -0
- package/dist/rules/prefer-as-const.js +1 -0
- package/dist/rules/prefer-destructuring.js +1 -0
- package/dist/rules/prefer-enum-initializers.js +1 -0
- package/dist/rules/prefer-find.js +1 -0
- package/dist/rules/prefer-for-of.js +1 -0
- package/dist/rules/prefer-function-type.js +1 -0
- package/dist/rules/prefer-includes.js +1 -0
- package/dist/rules/prefer-literal-enum-member.js +1 -0
- package/dist/rules/prefer-namespace-keyword.js +1 -0
- package/dist/rules/prefer-nullish-coalescing.js +1 -0
- package/dist/rules/prefer-optional-chain-utils/PreferOptionalChainOptions.js +1 -0
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +1 -0
- package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js +1 -0
- package/dist/rules/prefer-optional-chain-utils/compareNodes.js +1 -0
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +1 -0
- package/dist/rules/prefer-optional-chain.js +1 -0
- package/dist/rules/prefer-promise-reject-errors.js +1 -0
- package/dist/rules/prefer-readonly-parameter-types.js +1 -0
- package/dist/rules/prefer-readonly.js +1 -0
- package/dist/rules/prefer-reduce-type-parameter.js +1 -0
- package/dist/rules/prefer-regexp-exec.js +1 -0
- package/dist/rules/prefer-return-this-type.js +1 -0
- package/dist/rules/prefer-string-starts-ends-with.js +1 -0
- package/dist/rules/prefer-ts-expect-error.js +1 -0
- package/dist/rules/promise-function-async.js +1 -0
- package/dist/rules/related-getter-setter-pairs.js +1 -0
- package/dist/rules/require-array-sort-compare.js +1 -0
- package/dist/rules/require-await.js +1 -0
- package/dist/rules/restrict-plus-operands.js +1 -0
- package/dist/rules/restrict-template-expressions.js +1 -0
- package/dist/rules/return-await.js +13 -1
- package/dist/rules/sort-type-constituents.js +1 -0
- package/dist/rules/strict-boolean-expressions.js +1 -0
- package/dist/rules/strict-void-return.d.ts +3 -2
- package/dist/rules/strict-void-return.js +97 -5
- package/dist/rules/switch-exhaustiveness-check.js +1 -0
- package/dist/rules/triple-slash-reference.js +1 -0
- package/dist/rules/typedef.js +1 -0
- package/dist/rules/unbound-method.js +1 -0
- package/dist/rules/unified-signatures.d.ts +1 -1
- package/dist/rules/unified-signatures.js +73 -32
- package/dist/rules/use-unknown-in-catch-callback-variable.js +1 -0
- package/dist/util/FunctionSignature.d.ts +15 -0
- package/dist/util/FunctionSignature.js +123 -0
- package/dist/util/assertionFunctionUtils.js +1 -0
- package/dist/util/astUtils.js +1 -0
- package/dist/util/baseTypeUtils.d.ts +2 -0
- package/dist/util/baseTypeUtils.js +17 -0
- package/dist/util/class-scope-analyzer/classScopeAnalyzer.js +1 -0
- package/dist/util/class-scope-analyzer/extractComputedName.js +1 -0
- package/dist/util/class-scope-analyzer/types.js +1 -0
- package/dist/util/collectUnusedVariables.js +1 -0
- package/dist/util/createRule.js +1 -0
- package/dist/util/escapeRegExp.js +1 -0
- package/dist/util/explicitReturnTypeUtils.js +1 -0
- package/dist/util/getBaseTypesOfClassMember.js +1 -0
- package/dist/util/getConstraintInfo.js +1 -0
- package/dist/util/getESLintCoreRule.js +1 -0
- package/dist/util/getFixOrSuggest.js +1 -0
- package/dist/util/getForStatementHeadLoc.js +1 -0
- package/dist/util/getFunctionHeadLoc.js +1 -0
- package/dist/util/getMemberHeadLoc.js +1 -0
- package/dist/util/getOperatorPrecedence.js +1 -0
- package/dist/util/getParentFunctionNode.js +1 -0
- package/dist/util/getStaticStringValue.js +1 -0
- package/dist/util/getStringLength.js +1 -0
- package/dist/util/getTextWithParentheses.js +1 -0
- package/dist/util/getThisExpression.js +1 -0
- package/dist/util/getValueOfLiteralType.js +1 -0
- package/dist/util/getWrappedCode.js +1 -0
- package/dist/util/getWrappingFixer.js +1 -0
- package/dist/util/hasOverloadSignatures.js +1 -0
- package/dist/util/index.d.ts +2 -0
- package/dist/util/index.js +3 -0
- package/dist/util/isArrayMethodCallWithPredicate.js +1 -0
- package/dist/util/isAssignee.js +1 -0
- package/dist/util/isConditionalTest.js +1 -0
- package/dist/util/isHigherPrecedenceThanAwait.js +1 -0
- package/dist/util/isNodeEqual.js +1 -0
- package/dist/util/isNullLiteral.js +1 -0
- package/dist/util/isPromiseAggregatorMethod.js +1 -0
- package/dist/util/isStartOfArrowFunctionBody.d.ts +2 -0
- package/dist/util/isStartOfArrowFunctionBody.js +26 -0
- package/dist/util/isStartOfExpressionStatement.js +1 -0
- package/dist/util/isTypeImport.js +1 -0
- package/dist/util/isUndefinedIdentifier.js +1 -0
- package/dist/util/misc.js +1 -0
- package/dist/util/needsPrecedingSemiColon.js +1 -0
- package/dist/util/needsToBeAwaited.js +1 -0
- package/dist/util/objectIterators.js +1 -0
- package/dist/util/promiseUtils.js +1 -0
- package/dist/util/rangeToLoc.js +1 -0
- package/dist/util/referenceContainsTypePredicate.js +1 -0
- package/dist/util/referenceContainsTypeQuery.js +1 -0
- package/dist/util/scopeUtils.js +1 -0
- package/dist/util/skipChainExpression.js +1 -0
- package/dist/util/truthinessUtils.js +1 -0
- package/dist/util/types.js +1 -0
- package/dist/util/walkStatements.js +1 -0
- package/package.json +12 -11
|
@@ -37,96 +37,6 @@ 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
|
-
var RestTypeKind;
|
|
41
|
-
(function (RestTypeKind) {
|
|
42
|
-
RestTypeKind[RestTypeKind["Array"] = 0] = "Array";
|
|
43
|
-
RestTypeKind[RestTypeKind["Tuple"] = 1] = "Tuple";
|
|
44
|
-
RestTypeKind[RestTypeKind["Other"] = 2] = "Other";
|
|
45
|
-
})(RestTypeKind || (RestTypeKind = {}));
|
|
46
|
-
class FunctionSignature {
|
|
47
|
-
paramTypes;
|
|
48
|
-
restType;
|
|
49
|
-
hasConsumedArguments = false;
|
|
50
|
-
parameterTypeIndex = 0;
|
|
51
|
-
constructor(paramTypes, restType) {
|
|
52
|
-
this.paramTypes = paramTypes;
|
|
53
|
-
this.restType = restType;
|
|
54
|
-
}
|
|
55
|
-
static create(checker, tsNode) {
|
|
56
|
-
const signature = checker.getResolvedSignature(tsNode);
|
|
57
|
-
if (!signature) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const paramTypes = [];
|
|
61
|
-
let restType = null;
|
|
62
|
-
const parameters = signature.getParameters();
|
|
63
|
-
for (let i = 0; i < parameters.length; i += 1) {
|
|
64
|
-
const param = parameters[i];
|
|
65
|
-
const type = checker.getTypeOfSymbolAtLocation(param, tsNode);
|
|
66
|
-
const decl = param.getDeclarations()?.[0];
|
|
67
|
-
if (decl && (0, util_1.isRestParameterDeclaration)(decl)) {
|
|
68
|
-
// is a rest param
|
|
69
|
-
if (checker.isArrayType(type)) {
|
|
70
|
-
restType = {
|
|
71
|
-
type: checker.getTypeArguments(type)[0],
|
|
72
|
-
index: i,
|
|
73
|
-
kind: RestTypeKind.Array,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
else if (checker.isTupleType(type)) {
|
|
77
|
-
restType = {
|
|
78
|
-
index: i,
|
|
79
|
-
kind: RestTypeKind.Tuple,
|
|
80
|
-
typeArguments: checker.getTypeArguments(type),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
restType = {
|
|
85
|
-
type,
|
|
86
|
-
index: i,
|
|
87
|
-
kind: RestTypeKind.Other,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
paramTypes.push(type);
|
|
93
|
-
}
|
|
94
|
-
return new this(paramTypes, restType);
|
|
95
|
-
}
|
|
96
|
-
consumeRemainingArguments() {
|
|
97
|
-
this.hasConsumedArguments = true;
|
|
98
|
-
}
|
|
99
|
-
getNextParameterType() {
|
|
100
|
-
const index = this.parameterTypeIndex;
|
|
101
|
-
this.parameterTypeIndex += 1;
|
|
102
|
-
if (index >= this.paramTypes.length || this.hasConsumedArguments) {
|
|
103
|
-
if (this.restType == null) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
switch (this.restType.kind) {
|
|
107
|
-
case RestTypeKind.Tuple: {
|
|
108
|
-
const typeArguments = this.restType.typeArguments;
|
|
109
|
-
if (this.hasConsumedArguments) {
|
|
110
|
-
// all types consumed by a rest - just assume it's the last type
|
|
111
|
-
// there is one edge case where this is wrong, but we ignore it because
|
|
112
|
-
// it's rare and really complicated to handle
|
|
113
|
-
// eg: function foo(...a: [number, ...string[], number])
|
|
114
|
-
return typeArguments[typeArguments.length - 1];
|
|
115
|
-
}
|
|
116
|
-
const typeIndex = index - this.restType.index;
|
|
117
|
-
if (typeIndex >= typeArguments.length) {
|
|
118
|
-
return typeArguments[typeArguments.length - 1];
|
|
119
|
-
}
|
|
120
|
-
return typeArguments[typeIndex];
|
|
121
|
-
}
|
|
122
|
-
case RestTypeKind.Array:
|
|
123
|
-
case RestTypeKind.Other:
|
|
124
|
-
return this.restType.type;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return this.paramTypes[index];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
40
|
exports.default = (0, util_1.createRule)({
|
|
131
41
|
name: 'no-unsafe-argument',
|
|
132
42
|
meta: {
|
|
@@ -176,7 +86,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
176
86
|
return;
|
|
177
87
|
}
|
|
178
88
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
179
|
-
const signature =
|
|
89
|
+
const signature = util_1.FunctionSignature.create(checker, tsNode);
|
|
180
90
|
if (node.type === utils_1.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
181
91
|
// Consumes the first parameter (TemplateStringsArray) of the function called with TaggedTemplateExpression.
|
|
182
92
|
signature.getNextParameterType();
|
|
@@ -270,3 +180,4 @@ exports.default = (0, util_1.createRule)({
|
|
|
270
180
|
};
|
|
271
181
|
},
|
|
272
182
|
});
|
|
183
|
+
//# sourceMappingURL=no-unsafe-argument.js.map
|
|
@@ -1,74 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const tsutils = __importStar(require("ts-api-utils"));
|
|
37
|
-
const ts = __importStar(require("typescript"));
|
|
38
3
|
const util_1 = require("../util");
|
|
39
4
|
const shared_1 = require("./enum-utils/shared");
|
|
40
|
-
/**
|
|
41
|
-
* @returns Whether the right type is an unsafe comparison against any left type.
|
|
42
|
-
*/
|
|
43
|
-
function typeViolates(leftTypeParts, rightType) {
|
|
44
|
-
const leftEnumValueTypes = new Set(leftTypeParts.map(getEnumValueType));
|
|
45
|
-
return ((leftEnumValueTypes.has(ts.TypeFlags.Number) && isNumberLike(rightType)) ||
|
|
46
|
-
(leftEnumValueTypes.has(ts.TypeFlags.String) && isStringLike(rightType)));
|
|
47
|
-
}
|
|
48
|
-
function isNumberLike(type) {
|
|
49
|
-
return tsutils
|
|
50
|
-
.unionConstituents(type)
|
|
51
|
-
.every(unionPart => tsutils
|
|
52
|
-
.intersectionConstituents(unionPart)
|
|
53
|
-
.some(intersectionPart => tsutils.isTypeFlagSet(intersectionPart, ts.TypeFlags.Number | ts.TypeFlags.NumberLike)));
|
|
54
|
-
}
|
|
55
|
-
function isStringLike(type) {
|
|
56
|
-
return tsutils
|
|
57
|
-
.unionConstituents(type)
|
|
58
|
-
.every(unionPart => tsutils
|
|
59
|
-
.intersectionConstituents(unionPart)
|
|
60
|
-
.some(intersectionPart => tsutils.isTypeFlagSet(intersectionPart, ts.TypeFlags.String | ts.TypeFlags.StringLike)));
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* @returns What type a type's enum value is (number or string), if either.
|
|
64
|
-
*/
|
|
65
|
-
function getEnumValueType(type) {
|
|
66
|
-
return tsutils.isTypeFlagSet(type, ts.TypeFlags.EnumLike)
|
|
67
|
-
? tsutils.isTypeFlagSet(type, ts.TypeFlags.NumberLiteral)
|
|
68
|
-
? ts.TypeFlags.Number
|
|
69
|
-
: ts.TypeFlags.String
|
|
70
|
-
: undefined;
|
|
71
|
-
}
|
|
72
5
|
exports.default = (0, util_1.createRule)({
|
|
73
6
|
name: 'no-unsafe-enum-comparison',
|
|
74
7
|
meta: {
|
|
@@ -90,55 +23,11 @@ exports.default = (0, util_1.createRule)({
|
|
|
90
23
|
create(context) {
|
|
91
24
|
const parserServices = (0, util_1.getParserServices)(context);
|
|
92
25
|
const typeChecker = parserServices.program.getTypeChecker();
|
|
93
|
-
function isMismatchedComparison(leftType, rightType) {
|
|
94
|
-
// Allow comparisons that don't have anything to do with enums:
|
|
95
|
-
//
|
|
96
|
-
// ```ts
|
|
97
|
-
// 1 === 2;
|
|
98
|
-
// ```
|
|
99
|
-
const leftEnumTypes = (0, shared_1.getEnumTypes)(typeChecker, leftType);
|
|
100
|
-
const rightEnumTypes = new Set((0, shared_1.getEnumTypes)(typeChecker, rightType));
|
|
101
|
-
if (leftEnumTypes.length === 0 && rightEnumTypes.size === 0) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
// Allow comparisons that share an enum type:
|
|
105
|
-
//
|
|
106
|
-
// ```ts
|
|
107
|
-
// Fruit.Apple === Fruit.Banana;
|
|
108
|
-
// ```
|
|
109
|
-
for (const leftEnumType of leftEnumTypes) {
|
|
110
|
-
if (rightEnumTypes.has(leftEnumType)) {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// We need to split the type into the union type parts in order to find
|
|
115
|
-
// valid enum comparisons like:
|
|
116
|
-
//
|
|
117
|
-
// ```ts
|
|
118
|
-
// declare const something: Fruit | Vegetable;
|
|
119
|
-
// something === Fruit.Apple;
|
|
120
|
-
// ```
|
|
121
|
-
const leftTypeParts = tsutils.unionConstituents(leftType);
|
|
122
|
-
const rightTypeParts = tsutils.unionConstituents(rightType);
|
|
123
|
-
// If a type exists in both sides, we consider this comparison safe:
|
|
124
|
-
//
|
|
125
|
-
// ```ts
|
|
126
|
-
// declare const fruit: Fruit.Apple | 0;
|
|
127
|
-
// fruit === 0;
|
|
128
|
-
// ```
|
|
129
|
-
for (const leftTypePart of leftTypeParts) {
|
|
130
|
-
if (rightTypeParts.includes(leftTypePart)) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return (typeViolates(leftTypeParts, rightType) ||
|
|
135
|
-
typeViolates(rightTypeParts, leftType));
|
|
136
|
-
}
|
|
137
26
|
return {
|
|
138
27
|
'BinaryExpression[operator=/^[<>!=]?={0,2}$/]'(node) {
|
|
139
28
|
const leftType = parserServices.getTypeAtLocation(node.left);
|
|
140
29
|
const rightType = parserServices.getTypeAtLocation(node.right);
|
|
141
|
-
if (
|
|
30
|
+
if ((0, shared_1.isMismatchedEnumComparisonTypes)(typeChecker, leftType, rightType)) {
|
|
142
31
|
context.report({
|
|
143
32
|
node,
|
|
144
33
|
messageId: 'mismatchedCondition',
|
|
@@ -180,7 +69,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
180
69
|
const { parent } = node;
|
|
181
70
|
const leftType = parserServices.getTypeAtLocation(parent.discriminant);
|
|
182
71
|
const rightType = parserServices.getTypeAtLocation(node.test);
|
|
183
|
-
if (
|
|
72
|
+
if ((0, shared_1.isMismatchedEnumComparisonTypes)(typeChecker, leftType, rightType)) {
|
|
184
73
|
context.report({
|
|
185
74
|
node,
|
|
186
75
|
messageId: 'mismatchedCase',
|
|
@@ -190,3 +79,4 @@ exports.default = (0, util_1.createRule)({
|
|
|
190
79
|
};
|
|
191
80
|
},
|
|
192
81
|
});
|
|
82
|
+
//# sourceMappingURL=no-unsafe-enum-comparison.js.map
|
|
@@ -220,7 +220,18 @@ exports.default = (0, util_1.createRule)({
|
|
|
220
220
|
if (nextToken) {
|
|
221
221
|
endAt = nextToken.range[0];
|
|
222
222
|
}
|
|
223
|
-
|
|
223
|
+
const awaitRemovalFix = fixer.removeRange([startAt, endAt]);
|
|
224
|
+
const firstOperandToken = (0, util_1.nullThrows)(context.sourceCode.getTokenAfter(awaitToken), util_1.NullThrowsReasons.MissingToken('operand', 'await expression'));
|
|
225
|
+
const shouldWrapInParentheses = (0, util_1.isOpeningBraceToken)(firstOperandToken) &&
|
|
226
|
+
(0, util_1.isStartOfArrowFunctionBody)(node, context.sourceCode);
|
|
227
|
+
if (shouldWrapInParentheses) {
|
|
228
|
+
return [
|
|
229
|
+
awaitRemovalFix,
|
|
230
|
+
fixer.insertTextBefore(node.argument, '('),
|
|
231
|
+
fixer.insertTextAfter(node.argument, ')'),
|
|
232
|
+
];
|
|
233
|
+
}
|
|
234
|
+
return awaitRemovalFix;
|
|
224
235
|
}
|
|
225
236
|
function insertAwait(fixer, node, isHighPrecedence) {
|
|
226
237
|
if (isHighPrecedence) {
|
|
@@ -361,3 +372,4 @@ function getConfiguration(option) {
|
|
|
361
372
|
};
|
|
362
373
|
}
|
|
363
374
|
}
|
|
375
|
+
//# sourceMappingURL=return-await.js.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
1
2
|
type Options = [
|
|
2
3
|
{
|
|
3
4
|
allowReturnAny?: boolean;
|
|
4
5
|
}
|
|
5
6
|
];
|
|
6
|
-
type MessageId = `asyncFunc` | `nonVoidFunc` | `nonVoidReturn`;
|
|
7
|
-
declare const _default:
|
|
7
|
+
type MessageId = `asyncFunc` | `nonVoidFunc` | `nonVoidReturn` | `suggestAddVoidOp` | `suggestWrapInAsyncIIFE`;
|
|
8
|
+
declare const _default: TSESLint.RuleModule<MessageId, Options, import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
|
|
8
9
|
name: string;
|
|
9
10
|
};
|
|
10
11
|
export default _default;
|