@typescript-eslint/eslint-plugin 8.0.0-alpha.6 → 8.0.0-alpha.60
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/configs/all.js +7 -6
- package/dist/configs/all.js.map +1 -1
- package/dist/configs/disable-type-checked.js +3 -3
- package/dist/configs/disable-type-checked.js.map +1 -1
- package/dist/configs/recommended-type-checked-only.js +6 -0
- package/dist/configs/recommended-type-checked-only.js.map +1 -1
- package/dist/configs/recommended-type-checked.js +13 -2
- package/dist/configs/recommended-type-checked.js.map +1 -1
- package/dist/configs/recommended.js +7 -2
- package/dist/configs/recommended.js.map +1 -1
- package/dist/configs/strict-type-checked-only.js +8 -2
- package/dist/configs/strict-type-checked-only.js.map +1 -1
- package/dist/configs/strict-type-checked.js +15 -5
- package/dist/configs/strict-type-checked.js.map +1 -1
- package/dist/configs/strict.js +7 -3
- package/dist/configs/strict.js.map +1 -1
- package/dist/configs/stylistic-type-checked-only.js +3 -0
- package/dist/configs/stylistic-type-checked-only.js.map +1 -1
- package/dist/configs/stylistic-type-checked.js +3 -2
- package/dist/configs/stylistic-type-checked.js.map +1 -1
- package/dist/configs/stylistic.js +0 -2
- package/dist/configs/stylistic.js.map +1 -1
- package/dist/rules/adjacent-overload-signatures.js +2 -6
- package/dist/rules/adjacent-overload-signatures.js.map +1 -1
- package/dist/rules/array-type.js +14 -5
- package/dist/rules/array-type.js.map +1 -1
- package/dist/rules/class-literal-property-style.js +16 -16
- package/dist/rules/class-literal-property-style.js.map +1 -1
- package/dist/rules/class-methods-use-this.js.map +1 -1
- package/dist/rules/consistent-type-assertions.js +5 -19
- package/dist/rules/consistent-type-assertions.js.map +1 -1
- package/dist/rules/consistent-type-definitions.js +1 -1
- package/dist/rules/consistent-type-definitions.js.map +1 -1
- package/dist/rules/consistent-type-imports.js +13 -13
- package/dist/rules/consistent-type-imports.js.map +1 -1
- package/dist/rules/default-param-last.js +6 -1
- package/dist/rules/default-param-last.js.map +1 -1
- package/dist/rules/dot-notation.js +8 -1
- package/dist/rules/dot-notation.js.map +1 -1
- package/dist/rules/enum-utils/shared.js +3 -4
- package/dist/rules/enum-utils/shared.js.map +1 -1
- package/dist/rules/explicit-member-accessibility.js +49 -37
- package/dist/rules/explicit-member-accessibility.js.map +1 -1
- package/dist/rules/index.js +14 -6
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/init-declarations.js +57 -1
- package/dist/rules/init-declarations.js.map +1 -1
- package/dist/rules/member-ordering.js +8 -2
- package/dist/rules/member-ordering.js.map +1 -1
- package/dist/rules/method-signature-style.js +1 -3
- package/dist/rules/method-signature-style.js.map +1 -1
- package/dist/rules/naming-convention-utils/parse-options.js +2 -5
- package/dist/rules/naming-convention-utils/parse-options.js.map +1 -1
- package/dist/rules/naming-convention-utils/shared.js +3 -4
- package/dist/rules/naming-convention-utils/shared.js.map +1 -1
- package/dist/rules/naming-convention-utils/validator.js +1 -2
- package/dist/rules/naming-convention-utils/validator.js.map +1 -1
- package/dist/rules/naming-convention.js +3 -1
- package/dist/rules/naming-convention.js.map +1 -1
- package/dist/rules/no-array-delete.js +1 -1
- package/dist/rules/no-array-delete.js.map +1 -1
- package/dist/rules/no-base-to-string.js +1 -1
- package/dist/rules/no-base-to-string.js.map +1 -1
- package/dist/rules/no-duplicate-type-constituents.js +29 -3
- package/dist/rules/no-duplicate-type-constituents.js.map +1 -1
- package/dist/rules/no-dynamic-delete.js +8 -40
- package/dist/rules/no-dynamic-delete.js.map +1 -1
- package/dist/rules/no-empty-interface.js +2 -1
- package/dist/rules/no-empty-interface.js.map +1 -1
- package/dist/rules/no-empty-object-type.js +141 -0
- package/dist/rules/no-empty-object-type.js.map +1 -0
- package/dist/rules/no-extraneous-class.js +11 -3
- package/dist/rules/no-extraneous-class.js.map +1 -1
- package/dist/rules/no-floating-promises.js +91 -55
- package/dist/rules/no-floating-promises.js.map +1 -1
- package/dist/rules/no-implied-eval.js +6 -24
- package/dist/rules/no-implied-eval.js.map +1 -1
- package/dist/rules/no-inferrable-types.js +1 -2
- package/dist/rules/no-inferrable-types.js.map +1 -1
- package/dist/rules/no-invalid-this.js +6 -0
- package/dist/rules/no-invalid-this.js.map +1 -1
- package/dist/rules/no-magic-numbers.js +32 -1
- package/dist/rules/no-magic-numbers.js.map +1 -1
- package/dist/rules/no-misused-new.js +4 -3
- package/dist/rules/no-misused-new.js.map +1 -1
- package/dist/rules/no-misused-promises.js +76 -1
- package/dist/rules/no-misused-promises.js.map +1 -1
- package/dist/rules/no-mixed-enums.js +6 -9
- package/dist/rules/no-mixed-enums.js.map +1 -1
- package/dist/rules/no-non-null-assertion.js +12 -14
- package/dist/rules/no-non-null-assertion.js.map +1 -1
- package/dist/rules/no-require-imports.js +13 -3
- package/dist/rules/no-require-imports.js.map +1 -1
- package/dist/rules/no-restricted-imports.js +5 -6
- package/dist/rules/no-restricted-imports.js.map +1 -1
- package/dist/rules/{ban-types.js → no-restricted-types.js} +17 -91
- package/dist/rules/no-restricted-types.js.map +1 -0
- package/dist/rules/no-shadow.js +4 -9
- package/dist/rules/no-shadow.js.map +1 -1
- package/dist/rules/no-unnecessary-condition.js +8 -6
- package/dist/rules/no-unnecessary-condition.js.map +1 -1
- package/dist/rules/no-unnecessary-parameter-property-assignment.js +151 -0
- package/dist/rules/no-unnecessary-parameter-property-assignment.js.map +1 -0
- package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
- package/dist/rules/no-unnecessary-template-expression.js +223 -0
- package/dist/rules/no-unnecessary-template-expression.js.map +1 -0
- package/dist/rules/no-unnecessary-type-assertion.js +16 -13
- package/dist/rules/no-unnecessary-type-assertion.js.map +1 -1
- package/dist/rules/no-unnecessary-type-parameters.js +309 -0
- package/dist/rules/no-unnecessary-type-parameters.js.map +1 -0
- package/dist/rules/no-unsafe-argument.js +4 -2
- package/dist/rules/no-unsafe-argument.js.map +1 -1
- package/dist/rules/no-unsafe-assignment.js +24 -9
- package/dist/rules/no-unsafe-assignment.js.map +1 -1
- package/dist/rules/no-unsafe-call.js +5 -1
- package/dist/rules/no-unsafe-call.js.map +1 -1
- package/dist/rules/no-unsafe-enum-comparison.js +1 -5
- package/dist/rules/no-unsafe-enum-comparison.js.map +1 -1
- package/dist/rules/no-unsafe-function-type.js +47 -0
- package/dist/rules/no-unsafe-function-type.js.map +1 -0
- package/dist/rules/no-unsafe-member-access.js +10 -4
- package/dist/rules/no-unsafe-member-access.js.map +1 -1
- package/dist/rules/no-unsafe-return.js +9 -3
- package/dist/rules/no-unsafe-return.js.map +1 -1
- package/dist/rules/no-unsafe-unary-minus.js +1 -0
- package/dist/rules/no-unsafe-unary-minus.js.map +1 -1
- package/dist/rules/no-unused-expressions.js +1 -0
- package/dist/rules/no-unused-expressions.js.map +1 -1
- package/dist/rules/no-unused-vars.js +198 -79
- package/dist/rules/no-unused-vars.js.map +1 -1
- package/dist/rules/no-use-before-define.js +2 -16
- package/dist/rules/no-use-before-define.js.map +1 -1
- package/dist/rules/no-useless-constructor.js +1 -3
- package/dist/rules/no-useless-constructor.js.map +1 -1
- package/dist/rules/no-var-requires.js +2 -1
- package/dist/rules/no-var-requires.js.map +1 -1
- package/dist/rules/no-wrapper-object-types.js +61 -0
- package/dist/rules/no-wrapper-object-types.js.map +1 -0
- package/dist/rules/only-throw-error.js +1 -1
- package/dist/rules/only-throw-error.js.map +1 -1
- package/dist/rules/prefer-as-const.js +1 -1
- package/dist/rules/prefer-as-const.js.map +1 -1
- package/dist/rules/prefer-destructuring.js +3 -1
- package/dist/rules/prefer-destructuring.js.map +1 -1
- package/dist/rules/prefer-find.js +2 -1
- package/dist/rules/prefer-find.js.map +1 -1
- package/dist/rules/prefer-includes.js +1 -1
- package/dist/rules/prefer-includes.js.map +1 -1
- package/dist/rules/prefer-literal-enum-member.js +43 -2
- package/dist/rules/prefer-literal-enum-member.js.map +1 -1
- package/dist/rules/prefer-namespace-keyword.js +1 -1
- package/dist/rules/prefer-namespace-keyword.js.map +1 -1
- package/dist/rules/prefer-nullish-coalescing.js +8 -6
- package/dist/rules/prefer-nullish-coalescing.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +32 -37
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js +1 -2
- package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/compareNodes.js +1 -2
- package/dist/rules/prefer-optional-chain-utils/compareNodes.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +6 -11
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js.map +1 -1
- package/dist/rules/prefer-promise-reject-errors.js +1 -1
- package/dist/rules/prefer-promise-reject-errors.js.map +1 -1
- package/dist/rules/prefer-readonly.js +24 -12
- package/dist/rules/prefer-readonly.js.map +1 -1
- package/dist/rules/prefer-regexp-exec.js +15 -6
- package/dist/rules/prefer-regexp-exec.js.map +1 -1
- package/dist/rules/prefer-string-starts-ends-with.js.map +1 -1
- package/dist/rules/prefer-ts-expect-error.js +2 -1
- package/dist/rules/prefer-ts-expect-error.js.map +1 -1
- package/dist/rules/require-await.js +1 -1
- package/dist/rules/require-await.js.map +1 -1
- package/dist/rules/restrict-template-expressions.js +3 -3
- package/dist/rules/restrict-template-expressions.js.map +1 -1
- package/dist/rules/return-await.js +167 -86
- package/dist/rules/return-await.js.map +1 -1
- package/dist/rules/sort-type-constituents.js +23 -1
- package/dist/rules/sort-type-constituents.js.map +1 -1
- package/dist/rules/strict-boolean-expressions.js +112 -5
- package/dist/rules/strict-boolean-expressions.js.map +1 -1
- package/dist/rules/switch-exhaustiveness-check.js +7 -9
- package/dist/rules/switch-exhaustiveness-check.js.map +1 -1
- package/dist/rules/unbound-method.js +96 -27
- package/dist/rules/unbound-method.js.map +1 -1
- package/dist/rules/unified-signatures.js +3 -1
- package/dist/rules/unified-signatures.js.map +1 -1
- package/dist/util/astUtils.js +2 -3
- package/dist/util/astUtils.js.map +1 -1
- package/dist/util/collectUnusedVariables.js +110 -73
- package/dist/util/collectUnusedVariables.js.map +1 -1
- package/dist/util/createRule.js.map +1 -1
- package/dist/util/escapeRegExp.js +1 -2
- package/dist/util/escapeRegExp.js.map +1 -1
- package/dist/util/explicitReturnTypeUtils.js +11 -7
- package/dist/util/explicitReturnTypeUtils.js.map +1 -1
- package/dist/util/getESLintCoreRule.js +2 -2
- package/dist/util/getESLintCoreRule.js.map +1 -1
- package/dist/util/getForStatementHeadLoc.js +1 -2
- package/dist/util/getForStatementHeadLoc.js.map +1 -1
- package/dist/util/getFunctionHeadLoc.js +3 -4
- package/dist/util/getFunctionHeadLoc.js.map +1 -1
- package/dist/util/getMemberHeadLoc.js +80 -0
- package/dist/util/getMemberHeadLoc.js.map +1 -0
- package/dist/util/getOperatorPrecedence.js +5 -5
- package/dist/util/getOperatorPrecedence.js.map +1 -1
- package/dist/util/getStaticStringValue.js +1 -2
- package/dist/util/getStaticStringValue.js.map +1 -1
- package/dist/util/getStringLength.js +1 -2
- package/dist/util/getStringLength.js.map +1 -1
- package/dist/util/getTextWithParentheses.js +17 -0
- package/dist/util/getTextWithParentheses.js.map +1 -0
- package/dist/util/getThisExpression.js +1 -2
- package/dist/util/getThisExpression.js.map +1 -1
- package/dist/util/getWrappedCode.js +1 -2
- package/dist/util/getWrappedCode.js.map +1 -1
- package/dist/util/getWrappingFixer.js +2 -3
- package/dist/util/getWrappingFixer.js.map +1 -1
- package/dist/util/index.js +2 -0
- package/dist/util/index.js.map +1 -1
- package/dist/util/isAssignee.js +1 -2
- package/dist/util/isAssignee.js.map +1 -1
- package/dist/util/isNodeEqual.js +1 -2
- package/dist/util/isNodeEqual.js.map +1 -1
- package/dist/util/isNullLiteral.js +1 -2
- package/dist/util/isNullLiteral.js.map +1 -1
- package/dist/util/isTypeImport.js +22 -0
- package/dist/util/isTypeImport.js.map +1 -0
- package/dist/util/isUndefinedIdentifier.js +1 -2
- package/dist/util/isUndefinedIdentifier.js.map +1 -1
- package/dist/util/misc.js +15 -15
- package/dist/util/misc.js.map +1 -1
- package/dist/util/objectIterators.js +3 -4
- package/dist/util/objectIterators.js.map +1 -1
- package/dist/util/referenceContainsTypeQuery.js +20 -0
- package/dist/util/referenceContainsTypeQuery.js.map +1 -0
- package/dist/util/scopeUtils.js +11 -0
- package/dist/util/scopeUtils.js.map +1 -0
- package/docs/rules/array-type.mdx +4 -1
- package/docs/rules/ban-types.md +22 -0
- package/docs/rules/class-methods-use-this.mdx +1 -1
- package/docs/rules/consistent-indexed-object-style.mdx +1 -1
- package/docs/rules/consistent-type-imports.mdx +1 -1
- package/docs/rules/naming-convention.mdx +16 -0
- package/docs/rules/no-base-to-string.mdx +1 -1
- package/docs/rules/no-duplicate-imports.mdx +1 -1
- package/docs/rules/no-duplicate-type-constituents.mdx +6 -2
- package/docs/rules/no-dynamic-delete.mdx +12 -7
- package/docs/rules/no-empty-interface.mdx +10 -0
- package/docs/rules/no-empty-object-type.mdx +145 -0
- package/docs/rules/no-extraneous-class.mdx +6 -0
- package/docs/rules/no-floating-promises.mdx +148 -4
- package/docs/rules/no-import-type-side-effects.mdx +1 -1
- package/docs/rules/no-misused-promises.mdx +18 -20
- package/docs/rules/no-redundant-type-constituents.mdx +4 -0
- package/docs/rules/no-require-imports.mdx +28 -1
- package/docs/rules/no-restricted-types.mdx +71 -0
- package/docs/rules/no-type-alias.mdx +1 -1
- package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +12 -12
- package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +42 -0
- package/docs/rules/no-unnecessary-template-expression.mdx +85 -0
- package/docs/rules/no-unnecessary-type-parameters.mdx +109 -0
- package/docs/rules/no-unsafe-function-type.mdx +63 -0
- package/docs/rules/no-unused-expressions.mdx +41 -1
- package/docs/rules/no-unused-vars.mdx +5 -0
- package/docs/rules/no-useless-template-literals.mdx +3 -59
- package/docs/rules/no-var-requires.mdx +6 -0
- package/docs/rules/no-wrapper-object-types.mdx +75 -0
- package/docs/rules/only-throw-error.mdx +7 -0
- package/docs/rules/prefer-readonly-parameter-types.mdx +10 -4
- package/docs/rules/prefer-ts-expect-error.mdx +10 -0
- package/docs/rules/require-await.mdx +2 -2
- package/docs/rules/restrict-template-expressions.mdx +1 -1
- package/docs/rules/return-await.mdx +119 -23
- package/docs/rules/sort-type-constituents.mdx +29 -9
- package/docs/rules/sort-type-union-intersection-members.mdx +12 -0
- package/docs/rules/strict-boolean-expressions.mdx +6 -0
- package/docs/rules/unbound-method.mdx +3 -2
- package/package.json +15 -20
- package/rules.d.ts +34 -3
- package/dist/rules/ban-types.js.map +0 -1
- package/dist/rules/no-throw-literal.js +0 -97
- package/dist/rules/no-throw-literal.js.map +0 -1
- package/dist/rules/no-useless-template-literals.js +0 -153
- package/dist/rules/no-useless-template-literals.js.map +0 -1
- package/docs/rules/ban-types.mdx +0 -138
- package/docs/rules/no-throw-literal.mdx +0 -25
package/dist/util/misc.js
CHANGED
@@ -26,7 +26,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
26
|
return result;
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.
|
29
|
+
exports.MemberNameType = void 0;
|
30
|
+
exports.arrayGroupByToMap = arrayGroupByToMap;
|
31
|
+
exports.arraysAreEqual = arraysAreEqual;
|
32
|
+
exports.findFirstResult = findFirstResult;
|
33
|
+
exports.formatWordList = formatWordList;
|
34
|
+
exports.getEnumNames = getEnumNames;
|
35
|
+
exports.getNameFromIndexSignature = getNameFromIndexSignature;
|
36
|
+
exports.getNameFromMember = getNameFromMember;
|
37
|
+
exports.isDefinitionFile = isDefinitionFile;
|
38
|
+
exports.isRestParameterDeclaration = isRestParameterDeclaration;
|
39
|
+
exports.isParenlessArrowFunction = isParenlessArrowFunction;
|
40
|
+
exports.typeNodeRequiresParentheses = typeNodeRequiresParentheses;
|
41
|
+
exports.upperCaseFirst = upperCaseFirst;
|
42
|
+
exports.findLastIndex = findLastIndex;
|
30
43
|
const type_utils_1 = require("@typescript-eslint/type-utils");
|
31
44
|
const utils_1 = require("@typescript-eslint/utils");
|
32
45
|
const ts = __importStar(require("typescript"));
|
@@ -48,14 +61,12 @@ function isDefinitionFile(fileName) {
|
|
48
61
|
}
|
49
62
|
return false;
|
50
63
|
}
|
51
|
-
exports.isDefinitionFile = isDefinitionFile;
|
52
64
|
/**
|
53
65
|
* Upper cases the first character or the string
|
54
66
|
*/
|
55
67
|
function upperCaseFirst(str) {
|
56
68
|
return str[0].toUpperCase() + str.slice(1);
|
57
69
|
}
|
58
|
-
exports.upperCaseFirst = upperCaseFirst;
|
59
70
|
function arrayGroupByToMap(array, getKey) {
|
60
71
|
const groups = new Map();
|
61
72
|
for (const item of array) {
|
@@ -70,7 +81,6 @@ function arrayGroupByToMap(array, getKey) {
|
|
70
81
|
}
|
71
82
|
return groups;
|
72
83
|
}
|
73
|
-
exports.arrayGroupByToMap = arrayGroupByToMap;
|
74
84
|
function arraysAreEqual(a, b, eq) {
|
75
85
|
return (a === b ||
|
76
86
|
(a !== undefined &&
|
@@ -78,7 +88,6 @@ function arraysAreEqual(a, b, eq) {
|
|
78
88
|
a.length === b.length &&
|
79
89
|
a.every((x, idx) => eq(x, b[idx]))));
|
80
90
|
}
|
81
|
-
exports.arraysAreEqual = arraysAreEqual;
|
82
91
|
/** Returns the first non-`undefined` result. */
|
83
92
|
function findFirstResult(inputs, getResult) {
|
84
93
|
for (const element of inputs) {
|
@@ -89,7 +98,6 @@ function findFirstResult(inputs, getResult) {
|
|
89
98
|
}
|
90
99
|
return undefined;
|
91
100
|
}
|
92
|
-
exports.findFirstResult = findFirstResult;
|
93
101
|
/**
|
94
102
|
* Gets a string representation of the name of the index signature.
|
95
103
|
*/
|
@@ -97,7 +105,6 @@ function getNameFromIndexSignature(node) {
|
|
97
105
|
const propName = node.parameters.find((parameter) => parameter.type === utils_1.AST_NODE_TYPES.Identifier);
|
98
106
|
return propName ? propName.name : '(index signature)';
|
99
107
|
}
|
100
|
-
exports.getNameFromIndexSignature = getNameFromIndexSignature;
|
101
108
|
var MemberNameType;
|
102
109
|
(function (MemberNameType) {
|
103
110
|
MemberNameType[MemberNameType["Private"] = 1] = "Private";
|
@@ -140,11 +147,9 @@ function getNameFromMember(member, sourceCode) {
|
|
140
147
|
name: sourceCode.text.slice(...member.key.range),
|
141
148
|
};
|
142
149
|
}
|
143
|
-
exports.getNameFromMember = getNameFromMember;
|
144
150
|
function getEnumNames(myEnum) {
|
145
|
-
return Object.keys(myEnum).filter(x => isNaN(
|
151
|
+
return Object.keys(myEnum).filter(x => isNaN(Number(x)));
|
146
152
|
}
|
147
|
-
exports.getEnumNames = getEnumNames;
|
148
153
|
/**
|
149
154
|
* Given an array of words, returns an English-friendly concatenation, separated with commas, with
|
150
155
|
* the `and` clause inserted before the last item.
|
@@ -160,7 +165,6 @@ function formatWordList(words) {
|
|
160
165
|
}
|
161
166
|
return [words.slice(0, -1).join(', '), words.slice(-1)[0]].join(' and ');
|
162
167
|
}
|
163
|
-
exports.formatWordList = formatWordList;
|
164
168
|
/**
|
165
169
|
* Iterates the array in reverse and returns the index of the first element it
|
166
170
|
* finds which passes the predicate function.
|
@@ -178,7 +182,6 @@ function findLastIndex(members, predicate) {
|
|
178
182
|
}
|
179
183
|
return -1;
|
180
184
|
}
|
181
|
-
exports.findLastIndex = findLastIndex;
|
182
185
|
function typeNodeRequiresParentheses(node, text) {
|
183
186
|
return (node.type === utils_1.AST_NODE_TYPES.TSFunctionType ||
|
184
187
|
node.type === utils_1.AST_NODE_TYPES.TSConstructorType ||
|
@@ -186,13 +189,10 @@ function typeNodeRequiresParentheses(node, text) {
|
|
186
189
|
(node.type === utils_1.AST_NODE_TYPES.TSUnionType && text.startsWith('|')) ||
|
187
190
|
(node.type === utils_1.AST_NODE_TYPES.TSIntersectionType && text.startsWith('&')));
|
188
191
|
}
|
189
|
-
exports.typeNodeRequiresParentheses = typeNodeRequiresParentheses;
|
190
192
|
function isRestParameterDeclaration(decl) {
|
191
193
|
return ts.isParameter(decl) && decl.dotDotDotToken != null;
|
192
194
|
}
|
193
|
-
exports.isRestParameterDeclaration = isRestParameterDeclaration;
|
194
195
|
function isParenlessArrowFunction(node, sourceCode) {
|
195
196
|
return (node.params.length === 1 && !(0, astUtils_1.isParenthesized)(node.params[0], sourceCode));
|
196
197
|
}
|
197
|
-
exports.isParenlessArrowFunction = isParenlessArrowFunction;
|
198
198
|
//# sourceMappingURL=misc.js.map
|
package/dist/util/misc.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/util/misc.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/util/misc.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;AAuOD,8CAAiB;AACjB,wCAAc;AAGd,0CAAe;AACf,wCAAc;AACd,oCAAY;AACZ,8DAAyB;AACzB,8CAAiB;AACjB,4CAAgB;AAChB,gEAA0B;AAC1B,4DAAwB;AAGxB,kEAA2B;AAC3B,wCAAc;AACd,sCAAa;AArPf,8DAAgE;AAEhE,oDAA0D;AAC1D,+CAAiC;AAEjC,yCAA6C;AAE7C,MAAM,qBAAqB,GAAG;IAC5B,EAAE,CAAC,SAAS,CAAC,GAAG;IAChB,EAAE,CAAC,SAAS,CAAC,IAAI;IACjB,EAAE,CAAC,SAAS,CAAC,IAAI;CACT,CAAC;AACX;;GAEG;AACH,SAAS,gBAAgB,CAAC,QAAgB;IACxC,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC7C,KAAK,MAAM,aAAa,IAAI,qBAAqB,EAAE,CAAC;QAClD,IAAI,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,O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,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,GAAG,CAAC;QACb,CAAC;QACD,GAAG,EAAE,CAAC;IACR,CAAC;IAED,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC;AAED,SAAS,2BAA2B,CAClC,IAAuB,EACvB,IAAY;IAEZ,OAAO,CACL,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,cAAc;QAC3C,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,iBAAiB;QAC9C,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,iBAAiB;QAC9C,CAAC,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAClE,CAAC,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,kBAAkB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAC1E,CAAC;AACJ,CAAC;AAED,SAAS,0BAA0B,CAAC,IAAoB;IACtD,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC;AAC7D,CAAC;AAED,SAAS,wBAAwB,CAC/B,IAAsC,EACtC,UAA+B;IAE/B,OAAO,CACL,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAA,0BAAe,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CACzE,CAAC;AACJ,CAAC"}
|
@@ -1,13 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.objectForEachKey = objectForEachKey;
|
4
|
+
exports.objectMapKey = objectMapKey;
|
5
|
+
exports.objectReduceKey = objectReduceKey;
|
4
6
|
function objectForEachKey(obj, callback) {
|
5
7
|
const keys = Object.keys(obj);
|
6
8
|
for (const key of keys) {
|
7
9
|
callback(key);
|
8
10
|
}
|
9
11
|
}
|
10
|
-
exports.objectForEachKey = objectForEachKey;
|
11
12
|
function objectMapKey(obj, callback) {
|
12
13
|
const values = [];
|
13
14
|
objectForEachKey(obj, key => {
|
@@ -15,7 +16,6 @@ function objectMapKey(obj, callback) {
|
|
15
16
|
});
|
16
17
|
return values;
|
17
18
|
}
|
18
|
-
exports.objectMapKey = objectMapKey;
|
19
19
|
function objectReduceKey(obj, callback, initial) {
|
20
20
|
let accumulator = initial;
|
21
21
|
objectForEachKey(obj, key => {
|
@@ -23,5 +23,4 @@ function objectReduceKey(obj, callback, initial) {
|
|
23
23
|
});
|
24
24
|
return accumulator;
|
25
25
|
}
|
26
|
-
exports.objectReduceKey = objectReduceKey;
|
27
26
|
//# sourceMappingURL=objectIterators.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"objectIterators.js","sourceRoot":"","sources":["../../src/util/objectIterators.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"objectIterators.js","sourceRoot":"","sources":["../../src/util/objectIterators.ts"],"names":[],"mappings":";;AAiCS,4CAAgB;AAAE,oCAAY;AAAE,0CAAe;AAjCxD,SAAS,gBAAgB,CACvB,GAAM,EACN,QAAgC;IAEhC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,QAAQ,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CACnB,GAAM,EACN,QAAkC;IAElC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;QAC1B,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,eAAe,CACtB,GAAM,EACN,QAAyD,EACzD,OAAoB;IAEpB,IAAI,WAAW,GAAG,OAAO,CAAC;IAC1B,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;QAC1B,WAAW,GAAG,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.referenceContainsTypeQuery = referenceContainsTypeQuery;
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
5
|
+
/**
|
6
|
+
* Recursively checks whether a given reference has a type query declaration among its parents
|
7
|
+
*/
|
8
|
+
function referenceContainsTypeQuery(node) {
|
9
|
+
switch (node.type) {
|
10
|
+
case utils_1.AST_NODE_TYPES.TSTypeQuery:
|
11
|
+
return true;
|
12
|
+
case utils_1.AST_NODE_TYPES.TSQualifiedName:
|
13
|
+
case utils_1.AST_NODE_TYPES.Identifier:
|
14
|
+
return referenceContainsTypeQuery(node.parent);
|
15
|
+
default:
|
16
|
+
// if we find a different node, there's no chance that we're in a TSTypeQuery
|
17
|
+
return false;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
//# sourceMappingURL=referenceContainsTypeQuery.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"referenceContainsTypeQuery.js","sourceRoot":"","sources":["../../src/util/referenceContainsTypeQuery.ts"],"names":[],"mappings":";;AAMA,gEAaC;AAlBD,oDAA0D;AAE1D;;GAEG;AACH,SAAgB,0BAA0B,CAAC,IAAmB;IAC5D,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,sBAAc,CAAC,WAAW;YAC7B,OAAO,IAAI,CAAC;QAEd,KAAK,sBAAc,CAAC,eAAe,CAAC;QACpC,KAAK,sBAAc,CAAC,UAAU;YAC5B,OAAO,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEjD;YACE,6EAA6E;YAC7E,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isReferenceToGlobalFunction = isReferenceToGlobalFunction;
|
4
|
+
function isReferenceToGlobalFunction(calleeName, node, sourceCode) {
|
5
|
+
const ref = sourceCode
|
6
|
+
.getScope(node)
|
7
|
+
.references.find(ref => ref.identifier.name === calleeName);
|
8
|
+
// ensure it's the "global" version
|
9
|
+
return !ref?.resolved?.defs.length;
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=scopeUtils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"scopeUtils.js","sourceRoot":"","sources":["../../src/util/scopeUtils.ts"],"names":[],"mappings":";;AAGA,kEAWC;AAXD,SAAgB,2BAA2B,CACzC,UAAkB,EAClB,IAAmB,EACnB,UAAsB;IAEtB,MAAM,GAAG,GAAG,UAAU;SACnB,QAAQ,CAAC,IAAI,CAAC;SACd,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;IAE9D,mCAAmC;IACnC,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC;AACrC,CAAC"}
|
@@ -42,7 +42,8 @@ const y: readonly string[] = ['a', 'b'];
|
|
42
42
|
|
43
43
|
### `"generic"`
|
44
44
|
|
45
|
-
Always use `Array<T
|
45
|
+
Always use `Array<T>`, `ReadonlyArray<T>`, or `Readonly<Array<T>>` for all array types.
|
46
|
+
`readonly T[]` will be modified to `ReadonlyArray<T>` and `Readonly<T[]>` will be modified to `Readonly<Array<T>`.
|
46
47
|
|
47
48
|
<Tabs>
|
48
49
|
<TabItem value="❌ Incorrect">
|
@@ -50,6 +51,7 @@ Always use `Array<T>` or `ReadonlyArray<T>` for all array types.
|
|
50
51
|
```ts option='{ "default": "generic" }'
|
51
52
|
const x: string[] = ['a', 'b'];
|
52
53
|
const y: readonly string[] = ['a', 'b'];
|
54
|
+
const z: Readonly<string[]> = ['a', 'b'];
|
53
55
|
```
|
54
56
|
|
55
57
|
</TabItem>
|
@@ -58,6 +60,7 @@ const y: readonly string[] = ['a', 'b'];
|
|
58
60
|
```ts option='{ "default": "generic" }'
|
59
61
|
const x: Array<string> = ['a', 'b'];
|
60
62
|
const y: ReadonlyArray<string> = ['a', 'b'];
|
63
|
+
const z: Readonly<Array<string>> = ['a', 'b'];
|
61
64
|
```
|
62
65
|
|
63
66
|
</TabItem>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
:::danger Deprecated
|
2
|
+
|
3
|
+
The old `ban-types` rule encompassed multiple areas of functionality, and so has been split into several rules.
|
4
|
+
|
5
|
+
**[`no-restricted-types`](./no-restricted-types.mdx)** is the new rule for banning a configurable list of type names.
|
6
|
+
It has no options enabled by default and is akin to rules like [`no-restricted-globals`](https://eslint.org/docs/latest/rules/no-restricted-globals), [`no-restricted-properties`](https://eslint.org/docs/latest/rules/no-restricted-properties), and [`no-restricted-syntax`](https://eslint.org/docs/latest/rules/no-restricted-syntax).
|
7
|
+
|
8
|
+
The default options from `ban-types` are now covered by:
|
9
|
+
|
10
|
+
- **[`no-empty-object-type`](./no-empty-object-type.mdx)**: banning the built-in `{}` type in confusing locations
|
11
|
+
- **[`no-unsafe-function-type`](./no-unsafe-function-type.mdx)**: banning the built-in `Function`
|
12
|
+
- **[`no-wrapper-object-types`](./no-wrapper-object-types.mdx)**: banning `Object` and built-in class wrappers such as `Number`
|
13
|
+
|
14
|
+
`ban-types` itself is removed in typescript-eslint v8.
|
15
|
+
See [Announcing typescript-eslint v8 Beta](/blog/announcing-typescript-eslint-v8-beta) for more details.
|
16
|
+
:::
|
17
|
+
|
18
|
+
<!-- This doc file has been left on purpose because `ban-types` is a well-known
|
19
|
+
rule. This exists to help direct people to the replacement rules.
|
20
|
+
|
21
|
+
Note that there is no actual way to get to this page in the normal navigation,
|
22
|
+
so end-users will only be able to get to this page from the search bar. -->
|
@@ -31,7 +31,7 @@ const defaultOptions: Options = {
|
|
31
31
|
|
32
32
|
### `ignoreOverrideMethods`
|
33
33
|
|
34
|
-
Makes the rule
|
34
|
+
Makes the rule ignore any class member explicitly marked with `override`.
|
35
35
|
|
36
36
|
Example of a correct code when `ignoreOverrideMethods` is set to `true`:
|
37
37
|
|
@@ -132,5 +132,5 @@ We recommend picking a single option for this rule that works best for your proj
|
|
132
132
|
## Related To
|
133
133
|
|
134
134
|
- [`no-import-type-side-effects`](./no-import-type-side-effects.mdx)
|
135
|
-
- [`import/consistent-type-specifier-style`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/consistent-type-specifier-style.
|
135
|
+
- [`import/consistent-type-specifier-style`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/consistent-type-specifier-style.md)
|
136
136
|
- [`import/no-duplicates` with `{"prefer-inline": true}`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-duplicates.md#inline-type-imports)
|
@@ -583,6 +583,22 @@ This allows you to emulate the old `interface-name-prefix` rule.
|
|
583
583
|
}
|
584
584
|
```
|
585
585
|
|
586
|
+
### Enforce that function names are either in camelCase or PascalCase
|
587
|
+
|
588
|
+
Function names are typically camelCase, but UI library components (especially JSX, such as React and Solid) use PascalCase to distinguish them from intrinsic elements. If you are writing function components, consider allowing both camelCase and PascalCase for functions.
|
589
|
+
|
590
|
+
```json
|
591
|
+
{
|
592
|
+
"@typescript-eslint/naming-convention": [
|
593
|
+
"error",
|
594
|
+
{
|
595
|
+
"selector": "function",
|
596
|
+
"format": ["camelCase", "PascalCase"]
|
597
|
+
}
|
598
|
+
]
|
599
|
+
}
|
600
|
+
```
|
601
|
+
|
586
602
|
### Enforce that variable and function names are in camelCase
|
587
603
|
|
588
604
|
This allows you to lint multiple type with same pattern.
|
@@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
|
|
10
10
|
> See **https://typescript-eslint.io/rules/no-base-to-string** for documentation.
|
11
11
|
|
12
12
|
JavaScript will call `toString()` on an object when it is converted to a string, such as when `+` adding to a string or in `${}` template literals.
|
13
|
-
The default Object `.toString()`
|
13
|
+
The default Object `.toString()` uses the format `"[object Object]"`, which is often not what was intended.
|
14
14
|
This rule reports on stringified values that aren't primitives and don't define a more useful `.toString()` method.
|
15
15
|
|
16
16
|
> Note that `Function` provides its own `.toString()` that returns the function's code.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
:::danger Deprecated
|
2
2
|
|
3
|
-
This rule has been deprecated in favour of the [`import/no-duplicates`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-duplicates.
|
3
|
+
This rule has been deprecated in favour of the [`import/no-duplicates`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-duplicates.md) rule.
|
4
4
|
|
5
5
|
:::
|
6
6
|
|
@@ -23,7 +23,7 @@ For example, given `type A = string` and `type T = string | A`, this rule would
|
|
23
23
|
```ts
|
24
24
|
type T1 = 'A' | 'A';
|
25
25
|
|
26
|
-
type T2 =
|
26
|
+
type T2 = string | string | number;
|
27
27
|
|
28
28
|
type T3 = { a: string } & { a: string };
|
29
29
|
|
@@ -40,7 +40,7 @@ type T5 = StringA | StringB;
|
|
40
40
|
```ts
|
41
41
|
type T1 = 'A' | 'B';
|
42
42
|
|
43
|
-
type T2 =
|
43
|
+
type T2 = string | number | boolean;
|
44
44
|
|
45
45
|
type T3 = { a: string } & { b: string };
|
46
46
|
|
@@ -70,3 +70,7 @@ It can sometimes be useful for the sake of documentation to include aliases for
|
|
70
70
|
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
|
71
71
|
|
72
72
|
> In some of those cases, [branded types](https://basarat.gitbook.io/typescript/main-1/nominaltyping#using-interfaces) might be a type-safe way to represent the underlying data types.
|
73
|
+
|
74
|
+
## Related To
|
75
|
+
|
76
|
+
- [no-redundant-type-constituents](./no-redundant-type-constituents.mdx)
|
@@ -11,9 +11,13 @@ import TabItem from '@theme/TabItem';
|
|
11
11
|
|
12
12
|
Deleting dynamically computed keys can be dangerous and in some cases not well optimized.
|
13
13
|
Using the `delete` operator on keys that aren't runtime constants could be a sign that you're using the wrong data structures.
|
14
|
-
|
14
|
+
Consider using a `Map` or `Set` if you’re using an object as a key-value collection.
|
15
15
|
|
16
|
-
|
16
|
+
Dynamically adding and removing keys from objects can cause occasional edge case bugs. For example, some objects use "hidden properties" (such as `__data`) for private storage, and deleting them can break the object's internal state. Furthermore, [`delete`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete) cannot remove inherited properties or non-configurable properties. This makes it interact badly with anything more complicated than a plain object:
|
17
|
+
|
18
|
+
- The [`length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) of an array is non-configurable, and deleting it is a runtime error.
|
19
|
+
- You can't remove properties on the prototype of an object, such as deleting methods from class instances.
|
20
|
+
- Sometimes, `delete` only removes the own property, leaving the inherited property intact. For example, deleting the [`name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) property of a function only removes the own property, but there's also a `Function.prototype.name` property that remains.
|
17
21
|
|
18
22
|
## Examples
|
19
23
|
|
@@ -21,10 +25,6 @@ Using `Object`s with added and removed keys can cause occasional edge case bugs,
|
|
21
25
|
<TabItem value="❌ Incorrect">
|
22
26
|
|
23
27
|
```ts
|
24
|
-
// Can be replaced with the constant equivalents, such as container.aaa
|
25
|
-
delete container['aaa'];
|
26
|
-
delete container['Infinity'];
|
27
|
-
|
28
28
|
// Dynamic, difficult-to-reason-about lookups
|
29
29
|
const name = 'name';
|
30
30
|
delete container[name];
|
@@ -44,7 +44,12 @@ delete container.aaa;
|
|
44
44
|
|
45
45
|
// Constants that must be accessed by []
|
46
46
|
delete container[7];
|
47
|
-
delete container[
|
47
|
+
delete container[-1];
|
48
|
+
|
49
|
+
// All strings are allowed, to be compatible with the noPropertyAccessFromIndexSignature
|
50
|
+
// TS compiler option
|
51
|
+
delete container['aaa'];
|
52
|
+
delete container['Infinity'];
|
48
53
|
```
|
49
54
|
|
50
55
|
</TabItem>
|
@@ -9,6 +9,12 @@ import TabItem from '@theme/TabItem';
|
|
9
9
|
>
|
10
10
|
> See **https://typescript-eslint.io/rules/no-empty-interface** for documentation.
|
11
11
|
|
12
|
+
:::danger Deprecated
|
13
|
+
|
14
|
+
This rule has been deprecated in favour of the more comprehensive [`@typescript-eslint/no-empty-object-type`](./no-empty-object-type.mdx) rule.
|
15
|
+
|
16
|
+
:::
|
17
|
+
|
12
18
|
An empty interface in TypeScript does very little: any non-nullable value is assignable to `{}`.
|
13
19
|
Using an empty interface is often a sign of programmer error, such as misunderstanding the concept of `{}` or forgetting to fill in fields.
|
14
20
|
|
@@ -61,3 +67,7 @@ interface Baz extends Foo, Bar {}
|
|
61
67
|
## When Not To Use It
|
62
68
|
|
63
69
|
If you don't care about having empty/meaningless interfaces, then you will not need this rule.
|
70
|
+
|
71
|
+
## Related To
|
72
|
+
|
73
|
+
- [`no-empty-object-type`](./no-empty-object-type.mdx)
|
@@ -0,0 +1,145 @@
|
|
1
|
+
---
|
2
|
+
description: 'Disallow accidentally using the "empty object" type.'
|
3
|
+
---
|
4
|
+
|
5
|
+
import Tabs from '@theme/Tabs';
|
6
|
+
import TabItem from '@theme/TabItem';
|
7
|
+
|
8
|
+
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
+
>
|
10
|
+
> See **https://typescript-eslint.io/rules/no-empty-object-type** for documentation.
|
11
|
+
|
12
|
+
The `{}`, or "empty object" type in TypeScript is a common source of confusion for developers unfamiliar with TypeScript's structural typing.
|
13
|
+
`{}` represents any _non-nullish value_, including literals like `0` and `""`:
|
14
|
+
|
15
|
+
```ts
|
16
|
+
let anyNonNullishValue: {} = 'Intentionally allowed by TypeScript.';
|
17
|
+
```
|
18
|
+
|
19
|
+
Often, developers writing `{}` actually mean either:
|
20
|
+
|
21
|
+
- `object`: representing any _object_ value
|
22
|
+
- `unknown`: representing any value at all, including `null` and `undefined`
|
23
|
+
|
24
|
+
In other words, the "empty object" type `{}` really means _"any value that is defined"_.
|
25
|
+
That includes arrays, class instances, functions, and primitives such as `string` and `symbol`.
|
26
|
+
|
27
|
+
To avoid confusion around the `{}` type allowing any _non-nullish value_, this rule bans usage of the `{}` type.
|
28
|
+
That includes interfaces and object type aliases with no fields.
|
29
|
+
|
30
|
+
:::tip
|
31
|
+
If you do have a use case for an API allowing `{}`, you can always configure the [rule's options](#options), use an [ESLint disable comment](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1), or [disable the rule in your ESLint config](https://eslint.org/docs/latest/use/configure/rules#using-configuration-files-1).
|
32
|
+
:::
|
33
|
+
|
34
|
+
Note that this rule does not report on:
|
35
|
+
|
36
|
+
- `{}` as a type constituent in an intersection type (e.g. types like TypeScript's built-in `type NonNullable<T> = T & {}`), as this can be useful in type system operations.
|
37
|
+
- Interfaces that extend from multiple other interfaces.
|
38
|
+
|
39
|
+
## Examples
|
40
|
+
|
41
|
+
<Tabs>
|
42
|
+
<TabItem value="❌ Incorrect">
|
43
|
+
|
44
|
+
```ts
|
45
|
+
let anyObject: {};
|
46
|
+
let anyValue: {};
|
47
|
+
|
48
|
+
interface AnyObjectA {}
|
49
|
+
interface AnyValueA {}
|
50
|
+
|
51
|
+
type AnyObjectB = {};
|
52
|
+
type AnyValueB = {};
|
53
|
+
```
|
54
|
+
|
55
|
+
</TabItem>
|
56
|
+
<TabItem value="✅ Correct">
|
57
|
+
|
58
|
+
```ts
|
59
|
+
let anyObject: object;
|
60
|
+
let anyValue: unknown;
|
61
|
+
|
62
|
+
type AnyObjectA = object;
|
63
|
+
type AnyValueA = unknown;
|
64
|
+
|
65
|
+
type AnyObjectB = object;
|
66
|
+
type AnyValueB = unknown;
|
67
|
+
|
68
|
+
let objectWith: { property: boolean };
|
69
|
+
|
70
|
+
interface InterfaceWith {
|
71
|
+
property: boolean;
|
72
|
+
}
|
73
|
+
|
74
|
+
type TypeWith = { property: boolean };
|
75
|
+
```
|
76
|
+
|
77
|
+
</TabItem>
|
78
|
+
</Tabs>
|
79
|
+
|
80
|
+
## Options
|
81
|
+
|
82
|
+
By default, this rule flags both interfaces and object types.
|
83
|
+
|
84
|
+
### `allowInterfaces`
|
85
|
+
|
86
|
+
Whether to allow empty interfaces, as one of:
|
87
|
+
|
88
|
+
- `'always'`: to always allow interfaces with no fields
|
89
|
+
- `'never'` _(default)_: to never allow interfaces with no fields
|
90
|
+
- `'with-single-extends'`: to allow empty interfaces that `extend` from a single base interface
|
91
|
+
|
92
|
+
Examples of **correct** code for this rule with `{ allowInterfaces: 'with-single-extends' }`:
|
93
|
+
|
94
|
+
```ts option='{ "allowInterfaces": "with-single-extends" }' showPlaygroundButton
|
95
|
+
interface Base {
|
96
|
+
value: boolean;
|
97
|
+
}
|
98
|
+
|
99
|
+
interface Derived extends Base {}
|
100
|
+
```
|
101
|
+
|
102
|
+
### `allowObjectTypes`
|
103
|
+
|
104
|
+
Whether to allow empty object type literals, as one of:
|
105
|
+
|
106
|
+
- `'always'`: to always allow object type literals with no fields
|
107
|
+
- `'never'` _(default)_: to never allow object type literals with no fields
|
108
|
+
|
109
|
+
### `allowWithName`
|
110
|
+
|
111
|
+
A stringified regular expression to allow interfaces and object type aliases with the configured name.
|
112
|
+
This can be useful if your existing code style includes a pattern of declaring empty types with `{}` instead of `object`.
|
113
|
+
|
114
|
+
Examples of code for this rule with `{ allowWithName: 'Props$' }`:
|
115
|
+
|
116
|
+
<Tabs>
|
117
|
+
<TabItem value="❌ Incorrect">
|
118
|
+
|
119
|
+
```ts option='{ "allowWithName": "Props$" }' showPlaygroundButton
|
120
|
+
interface InterfaceValue {}
|
121
|
+
|
122
|
+
type TypeValue = {};
|
123
|
+
```
|
124
|
+
|
125
|
+
</TabItem>
|
126
|
+
<TabItem value="✅ Correct">
|
127
|
+
|
128
|
+
```ts option='{ "allowWithName": "Props$" }' showPlaygroundButton
|
129
|
+
interface InterfaceProps {}
|
130
|
+
|
131
|
+
type TypeProps = {};
|
132
|
+
```
|
133
|
+
|
134
|
+
</TabItem>
|
135
|
+
</Tabs>
|
136
|
+
|
137
|
+
## When Not To Use It
|
138
|
+
|
139
|
+
If your code commonly needs to represent the _"any non-nullish value"_ type, this rule may not be for you.
|
140
|
+
Projects that extensively use type operations such as conditional types and mapped types oftentimes benefit from disabling this rule.
|
141
|
+
|
142
|
+
## Further Reading
|
143
|
+
|
144
|
+
- [Enhancement: [ban-types] Split the {} ban into a separate, better-phrased rule](https://github.com/typescript-eslint/typescript-eslint/issues/8700)
|
145
|
+
- [The Empty Object Type in TypeScript](https://www.totaltypescript.com/the-empty-object-type-in-typescript)
|
@@ -42,6 +42,8 @@ class HelloWorldLogger {
|
|
42
42
|
console.log('Hello, world!');
|
43
43
|
}
|
44
44
|
}
|
45
|
+
|
46
|
+
abstract class Foo {}
|
45
47
|
```
|
46
48
|
|
47
49
|
</TabItem>
|
@@ -57,6 +59,10 @@ export function isProduction() {
|
|
57
59
|
function logHelloWorld() {
|
58
60
|
console.log('Hello, world!');
|
59
61
|
}
|
62
|
+
|
63
|
+
abstract class Foo {
|
64
|
+
abstract prop: string;
|
65
|
+
}
|
60
66
|
```
|
61
67
|
|
62
68
|
</TabItem>
|