@typescript-eslint/eslint-plugin 8.31.2-alpha.7 → 8.31.2-alpha.8
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/eslintrc/all.d.ts +1 -0
- package/dist/configs/eslintrc/all.d.ts.map +1 -1
- package/dist/configs/eslintrc/all.js +1 -0
- package/dist/configs/eslintrc/disable-type-checked.d.ts +1 -0
- package/dist/configs/eslintrc/disable-type-checked.d.ts.map +1 -1
- package/dist/configs/eslintrc/disable-type-checked.js +1 -0
- package/dist/configs/flat/all.d.ts.map +1 -1
- package/dist/configs/flat/all.js +1 -0
- package/dist/configs/flat/disable-type-checked.d.ts.map +1 -1
- package/dist/configs/flat/disable-type-checked.js +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/raw-plugin.d.ts +3 -0
- package/dist/raw-plugin.d.ts.map +1 -1
- package/dist/rules/adjacent-overload-signatures.js +1 -1
- package/dist/rules/explicit-function-return-type.js +2 -2
- package/dist/rules/index.d.ts +1 -0
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +2 -0
- package/dist/rules/member-ordering.js +1 -1
- package/dist/rules/no-duplicate-enum-values.js +2 -2
- package/dist/rules/no-empty-interface.d.ts.map +1 -1
- package/dist/rules/no-empty-interface.js +2 -2
- package/dist/rules/no-redundant-type-constituents.js +1 -1
- package/dist/rules/no-unnecessary-template-expression.d.ts.map +1 -1
- package/dist/rules/no-unnecessary-template-expression.js +2 -2
- package/dist/rules/no-unnecessary-type-conversion.d.ts +4 -0
- package/dist/rules/no-unnecessary-type-conversion.d.ts.map +1 -0
- package/dist/rules/no-unnecessary-type-conversion.js +305 -0
- package/dist/rules/no-unsafe-assignment.js +1 -1
- package/dist/rules/prefer-return-this-type.js +1 -1
- package/dist/util/getWrappingFixer.d.ts +3 -3
- package/dist/util/getWrappingFixer.d.ts.map +1 -1
- package/dist/util/getWrappingFixer.js +5 -2
- package/docs/rules/no-unnecessary-type-conversion.mdx +79 -0
- package/package.json +7 -7
@@ -89,6 +89,7 @@ declare const _default: {
|
|
89
89
|
'@typescript-eslint/no-unnecessary-type-arguments': "error";
|
90
90
|
'@typescript-eslint/no-unnecessary-type-assertion': "error";
|
91
91
|
'@typescript-eslint/no-unnecessary-type-constraint': "error";
|
92
|
+
'@typescript-eslint/no-unnecessary-type-conversion': "error";
|
92
93
|
'@typescript-eslint/no-unnecessary-type-parameters': "error";
|
93
94
|
'@typescript-eslint/no-unsafe-argument': "error";
|
94
95
|
'@typescript-eslint/no-unsafe-assignment': "error";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../src/configs/eslintrc/all.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../src/configs/eslintrc/all.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,kBA0JiC"}
|
@@ -96,6 +96,7 @@ module.exports = {
|
|
96
96
|
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
|
97
97
|
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
|
98
98
|
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
|
99
|
+
'@typescript-eslint/no-unnecessary-type-conversion': 'error',
|
99
100
|
'@typescript-eslint/no-unnecessary-type-parameters': 'error',
|
100
101
|
'@typescript-eslint/no-unsafe-argument': 'error',
|
101
102
|
'@typescript-eslint/no-unsafe-assignment': 'error',
|
@@ -29,6 +29,7 @@ declare const _default: {
|
|
29
29
|
'@typescript-eslint/no-unnecessary-template-expression': "off";
|
30
30
|
'@typescript-eslint/no-unnecessary-type-arguments': "off";
|
31
31
|
'@typescript-eslint/no-unnecessary-type-assertion': "off";
|
32
|
+
'@typescript-eslint/no-unnecessary-type-conversion': "off";
|
32
33
|
'@typescript-eslint/no-unnecessary-type-parameters': "off";
|
33
34
|
'@typescript-eslint/no-unsafe-argument': "off";
|
34
35
|
'@typescript-eslint/no-unsafe-assignment': "off";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"disable-type-checked.d.ts","sourceRoot":"","sources":["../../../src/configs/eslintrc/disable-type-checked.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"disable-type-checked.d.ts","sourceRoot":"","sources":["../../../src/configs/eslintrc/disable-type-checked.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,kBA+DiC"}
|
@@ -32,6 +32,7 @@ module.exports = {
|
|
32
32
|
'@typescript-eslint/no-unnecessary-template-expression': 'off',
|
33
33
|
'@typescript-eslint/no-unnecessary-type-arguments': 'off',
|
34
34
|
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
|
35
|
+
'@typescript-eslint/no-unnecessary-type-conversion': 'off',
|
35
36
|
'@typescript-eslint/no-unnecessary-type-parameters': 'off',
|
36
37
|
'@typescript-eslint/no-unsafe-argument': 'off',
|
37
38
|
'@typescript-eslint/no-unsafe-assignment': 'off',
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../src/configs/flat/all.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAKrE;;;GAGG;yBAED,QAAQ,UAAU,CAAC,MAAM,EACzB,QAAQ,UAAU,CAAC,MAAM,KACxB,UAAU,CAAC,WAAW;AAHzB,
|
1
|
+
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../src/configs/flat/all.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAKrE;;;GAGG;yBAED,QAAQ,UAAU,CAAC,MAAM,EACzB,QAAQ,UAAU,CAAC,MAAM,KACxB,UAAU,CAAC,WAAW;AAHzB,wBAkKE"}
|
package/dist/configs/flat/all.js
CHANGED
@@ -109,6 +109,7 @@ exports.default = (plugin, parser) => [
|
|
109
109
|
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
|
110
110
|
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
|
111
111
|
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
|
112
|
+
'@typescript-eslint/no-unnecessary-type-conversion': 'error',
|
112
113
|
'@typescript-eslint/no-unnecessary-type-parameters': 'error',
|
113
114
|
'@typescript-eslint/no-unsafe-argument': 'error',
|
114
115
|
'@typescript-eslint/no-unsafe-assignment': 'error',
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"disable-type-checked.d.ts","sourceRoot":"","sources":["../../../src/configs/flat/disable-type-checked.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAErE;;;GAGG;yBAED,SAAS,UAAU,CAAC,MAAM,EAC1B,SAAS,UAAU,CAAC,MAAM,KACzB,UAAU,CAAC,MAAM;AAHpB,
|
1
|
+
{"version":3,"file":"disable-type-checked.d.ts","sourceRoot":"","sources":["../../../src/configs/flat/disable-type-checked.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAErE;;;GAGG;yBAED,SAAS,UAAU,CAAC,MAAM,EAC1B,SAAS,UAAU,CAAC,MAAM,KACzB,UAAU,CAAC,MAAM;AAHpB,wBAqEG"}
|
@@ -37,6 +37,7 @@ exports.default = (_plugin, _parser) => ({
|
|
37
37
|
'@typescript-eslint/no-unnecessary-template-expression': 'off',
|
38
38
|
'@typescript-eslint/no-unnecessary-type-arguments': 'off',
|
39
39
|
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
|
40
|
+
'@typescript-eslint/no-unnecessary-type-conversion': 'off',
|
40
41
|
'@typescript-eslint/no-unnecessary-type-parameters': 'off',
|
41
42
|
'@typescript-eslint/no-unsafe-argument': 'off',
|
42
43
|
'@typescript-eslint/no-unsafe-assignment': 'off',
|
package/dist/index.d.ts
CHANGED
@@ -91,6 +91,7 @@ declare const _default: {
|
|
91
91
|
'@typescript-eslint/no-unnecessary-type-arguments': "error";
|
92
92
|
'@typescript-eslint/no-unnecessary-type-assertion': "error";
|
93
93
|
'@typescript-eslint/no-unnecessary-type-constraint': "error";
|
94
|
+
'@typescript-eslint/no-unnecessary-type-conversion': "error";
|
94
95
|
'@typescript-eslint/no-unnecessary-type-parameters': "error";
|
95
96
|
'@typescript-eslint/no-unsafe-argument': "error";
|
96
97
|
'@typescript-eslint/no-unsafe-assignment': "error";
|
@@ -192,6 +193,7 @@ declare const _default: {
|
|
192
193
|
'@typescript-eslint/no-unnecessary-template-expression': "off";
|
193
194
|
'@typescript-eslint/no-unnecessary-type-arguments': "off";
|
194
195
|
'@typescript-eslint/no-unnecessary-type-assertion': "off";
|
196
|
+
'@typescript-eslint/no-unnecessary-type-conversion': "off";
|
195
197
|
'@typescript-eslint/no-unnecessary-type-parameters': "off";
|
196
198
|
'@typescript-eslint/no-unsafe-argument': "off";
|
197
199
|
'@typescript-eslint/no-unsafe-assignment': "off";
|
@@ -774,6 +776,7 @@ declare const _default: {
|
|
774
776
|
'no-unnecessary-type-arguments': import("@typescript-eslint/utils/ts-eslint").RuleModule<"unnecessaryTypeParameter", [], import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
775
777
|
'no-unnecessary-type-assertion': import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./rules/no-unnecessary-type-assertion").MessageIds, import("./rules/no-unnecessary-type-assertion").Options, import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
776
778
|
'no-unnecessary-type-constraint': import("@typescript-eslint/utils/ts-eslint").RuleModule<"removeUnnecessaryConstraint" | "unnecessaryConstraint", [], import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
779
|
+
'no-unnecessary-type-conversion': import("@typescript-eslint/utils/ts-eslint").RuleModule<"suggestRemove" | "suggestSatisfies" | "unnecessaryTypeConversion", [], import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
777
780
|
'no-unnecessary-type-parameters': import("@typescript-eslint/utils/ts-eslint").RuleModule<"replaceUsagesWithConstraint" | "sole", [], import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
778
781
|
'no-unsafe-argument': import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./rules/no-unsafe-argument").MessageIds, [], import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
779
782
|
'no-unsafe-assignment': import("@typescript-eslint/utils/ts-eslint").RuleModule<"unsafeArraySpread" | "anyAssignment" | "anyAssignmentThis" | "unsafeArrayPattern" | "unsafeArrayPatternFromTuple" | "unsafeAssignment", [], import("../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kBAA0B"}
|
package/dist/raw-plugin.d.ts
CHANGED
@@ -113,6 +113,7 @@ declare const _default: {
|
|
113
113
|
'@typescript-eslint/no-unnecessary-type-arguments': "error";
|
114
114
|
'@typescript-eslint/no-unnecessary-type-assertion': "error";
|
115
115
|
'@typescript-eslint/no-unnecessary-type-constraint': "error";
|
116
|
+
'@typescript-eslint/no-unnecessary-type-conversion': "error";
|
116
117
|
'@typescript-eslint/no-unnecessary-type-parameters': "error";
|
117
118
|
'@typescript-eslint/no-unsafe-argument': "error";
|
118
119
|
'@typescript-eslint/no-unsafe-assignment': "error";
|
@@ -214,6 +215,7 @@ declare const _default: {
|
|
214
215
|
'@typescript-eslint/no-unnecessary-template-expression': "off";
|
215
216
|
'@typescript-eslint/no-unnecessary-type-arguments': "off";
|
216
217
|
'@typescript-eslint/no-unnecessary-type-assertion': "off";
|
218
|
+
'@typescript-eslint/no-unnecessary-type-conversion': "off";
|
217
219
|
'@typescript-eslint/no-unnecessary-type-parameters': "off";
|
218
220
|
'@typescript-eslint/no-unsafe-argument': "off";
|
219
221
|
'@typescript-eslint/no-unsafe-assignment': "off";
|
@@ -797,6 +799,7 @@ declare const _default: {
|
|
797
799
|
'no-unnecessary-type-arguments': TSESLint.RuleModule<"unnecessaryTypeParameter", [], import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
798
800
|
'no-unnecessary-type-assertion': TSESLint.RuleModule<import("./rules/no-unnecessary-type-assertion").MessageIds, import("./rules/no-unnecessary-type-assertion").Options, import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
799
801
|
'no-unnecessary-type-constraint': TSESLint.RuleModule<"removeUnnecessaryConstraint" | "unnecessaryConstraint", [], import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
802
|
+
'no-unnecessary-type-conversion': TSESLint.RuleModule<"suggestRemove" | "suggestSatisfies" | "unnecessaryTypeConversion", [], import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
800
803
|
'no-unnecessary-type-parameters': TSESLint.RuleModule<"replaceUsagesWithConstraint" | "sole", [], import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
801
804
|
'no-unsafe-argument': TSESLint.RuleModule<import("./rules/no-unsafe-argument").MessageIds, [], import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
802
805
|
'no-unsafe-assignment': TSESLint.RuleModule<"unsafeArraySpread" | "anyAssignment" | "anyAssignmentThis" | "unsafeArrayPattern" | "unsafeArrayPatternFromTuple" | "unsafeAssignment", [], import("../rules").ESLintPluginDocs, TSESLint.RuleListener>;
|
package/dist/raw-plugin.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"raw-plugin.d.ts","sourceRoot":"","sources":["../src/raw-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAU,MAAM,oCAAoC,CAAC;;;;;;;;;;;;;;;;;;wDAetD,CAAC
|
1
|
+
{"version":3,"file":"raw-plugin.d.ts","sourceRoot":"","sources":["../src/raw-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAU,MAAM,oCAAoC,CAAC;;;;;;;;;;;;;;;;;;wDAetD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqCpB,mEAAmE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDvE,kBAIE"}
|
@@ -50,7 +50,7 @@ exports.default = (0, util_1.createRule)({
|
|
50
50
|
return {
|
51
51
|
...(0, util_1.getNameFromMember)(member, context.sourceCode),
|
52
52
|
callSignature: false,
|
53
|
-
static:
|
53
|
+
static: member.static,
|
54
54
|
};
|
55
55
|
case utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
|
56
56
|
return {
|
@@ -116,13 +116,13 @@ exports.default = (0, util_1.createRule)({
|
|
116
116
|
}
|
117
117
|
}
|
118
118
|
}
|
119
|
-
if (!!funcName &&
|
119
|
+
if (!!funcName && options.allowedNames.includes(funcName)) {
|
120
120
|
return true;
|
121
121
|
}
|
122
122
|
}
|
123
123
|
if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration &&
|
124
124
|
node.id &&
|
125
|
-
|
125
|
+
options.allowedNames.includes(node.id.name)) {
|
126
126
|
return true;
|
127
127
|
}
|
128
128
|
return false;
|
package/dist/rules/index.d.ts
CHANGED
@@ -107,6 +107,7 @@ declare const rules: {
|
|
107
107
|
'no-unnecessary-type-arguments': import("@typescript-eslint/utils/ts-eslint").RuleModule<"unnecessaryTypeParameter", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
108
108
|
'no-unnecessary-type-assertion': import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./no-unnecessary-type-assertion").MessageIds, import("./no-unnecessary-type-assertion").Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
109
109
|
'no-unnecessary-type-constraint': import("@typescript-eslint/utils/ts-eslint").RuleModule<"removeUnnecessaryConstraint" | "unnecessaryConstraint", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
110
|
+
'no-unnecessary-type-conversion': import("@typescript-eslint/utils/ts-eslint").RuleModule<"suggestRemove" | "suggestSatisfies" | "unnecessaryTypeConversion", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
110
111
|
'no-unnecessary-type-parameters': import("@typescript-eslint/utils/ts-eslint").RuleModule<"replaceUsagesWithConstraint" | "sole", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
111
112
|
'no-unsafe-argument': import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./no-unsafe-argument").MessageIds, [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
112
113
|
'no-unsafe-assignment': import("@typescript-eslint/utils/ts-eslint").RuleModule<"unsafeArraySpread" | "anyAssignment" | "anyAssignmentThis" | "unsafeArrayPattern" | "unsafeArrayPatternFromTuple" | "unsafeAssignment", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAsIA,QAAA,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqImB,CAAC;AAE/B,SAAS,KAAK,CAAC"}
|
package/dist/rules/index.js
CHANGED
@@ -77,6 +77,7 @@ const no_unnecessary_template_expression_1 = __importDefault(require("./no-unnec
|
|
77
77
|
const no_unnecessary_type_arguments_1 = __importDefault(require("./no-unnecessary-type-arguments"));
|
78
78
|
const no_unnecessary_type_assertion_1 = __importDefault(require("./no-unnecessary-type-assertion"));
|
79
79
|
const no_unnecessary_type_constraint_1 = __importDefault(require("./no-unnecessary-type-constraint"));
|
80
|
+
const no_unnecessary_type_conversion_1 = __importDefault(require("./no-unnecessary-type-conversion"));
|
80
81
|
const no_unnecessary_type_parameters_1 = __importDefault(require("./no-unnecessary-type-parameters"));
|
81
82
|
const no_unsafe_argument_1 = __importDefault(require("./no-unsafe-argument"));
|
82
83
|
const no_unsafe_assignment_1 = __importDefault(require("./no-unsafe-assignment"));
|
@@ -208,6 +209,7 @@ const rules = {
|
|
208
209
|
'no-unnecessary-type-arguments': no_unnecessary_type_arguments_1.default,
|
209
210
|
'no-unnecessary-type-assertion': no_unnecessary_type_assertion_1.default,
|
210
211
|
'no-unnecessary-type-constraint': no_unnecessary_type_constraint_1.default,
|
212
|
+
'no-unnecessary-type-conversion': no_unnecessary_type_conversion_1.default,
|
211
213
|
'no-unnecessary-type-parameters': no_unnecessary_type_parameters_1.default,
|
212
214
|
'no-unsafe-argument': no_unsafe_argument_1.default,
|
213
215
|
'no-unsafe-assignment': no_unsafe_assignment_1.default,
|
@@ -326,7 +326,7 @@ function isMemberOptional(node) {
|
|
326
326
|
case utils_1.AST_NODE_TYPES.PropertyDefinition:
|
327
327
|
case utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition:
|
328
328
|
case utils_1.AST_NODE_TYPES.MethodDefinition:
|
329
|
-
return
|
329
|
+
return node.optional;
|
330
330
|
}
|
331
331
|
return false;
|
332
332
|
}
|
@@ -39,10 +39,10 @@ exports.default = (0, util_1.createRule)({
|
|
39
39
|
}
|
40
40
|
let value;
|
41
41
|
if (isStringLiteral(member.initializer)) {
|
42
|
-
value =
|
42
|
+
value = member.initializer.value;
|
43
43
|
}
|
44
44
|
else if (isNumberLiteral(member.initializer)) {
|
45
|
-
value =
|
45
|
+
value = member.initializer.value;
|
46
46
|
}
|
47
47
|
else if (isStaticTemplateLiteral(member.initializer)) {
|
48
48
|
value = member.initializer.quasis[0].value.cooked;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"no-empty-interface.d.ts","sourceRoot":"","sources":["../../src/rules/no-empty-interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAOzD,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,kBAAkB,CAAC;;AAExD,
|
1
|
+
{"version":3,"file":"no-empty-interface.d.ts","sourceRoot":"","sources":["../../src/rules/no-empty-interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAOzD,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,kBAAkB,CAAC;;AAExD,wBAkHG"}
|
@@ -75,9 +75,9 @@ exports.default = (0, util_1.createRule)({
|
|
75
75
|
const mergedWithClassDeclaration = scope.set
|
76
76
|
.get(node.id.name)
|
77
77
|
?.defs.some(def => def.node.type === utils_1.AST_NODE_TYPES.ClassDeclaration);
|
78
|
-
const isInAmbientDeclaration =
|
78
|
+
const isInAmbientDeclaration = (0, util_1.isDefinitionFile)(context.filename) &&
|
79
79
|
scope.type === scope_manager_1.ScopeType.tsModule &&
|
80
|
-
scope.block.declare
|
80
|
+
scope.block.declare;
|
81
81
|
const useAutoFix = !(isInAmbientDeclaration || mergedWithClassDeclaration);
|
82
82
|
context.report({
|
83
83
|
node: node.id,
|
@@ -156,7 +156,7 @@ function describeLiteralTypeNode(typeNode) {
|
|
156
156
|
return 'literal type';
|
157
157
|
}
|
158
158
|
function isNodeInsideReturnType(node) {
|
159
|
-
return
|
159
|
+
return (node.parent.type === utils_1.AST_NODE_TYPES.TSTypeAnnotation &&
|
160
160
|
(0, util_1.isFunctionOrFunctionType)(node.parent.parent));
|
161
161
|
}
|
162
162
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"no-unnecessary-template-expression.d.ts","sourceRoot":"","sources":["../../src/rules/no-unnecessary-template-expression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAmBzD,MAAM,MAAM,SAAS,GAAG,iCAAiC,CAAC;;
|
1
|
+
{"version":3,"file":"no-unnecessary-template-expression.d.ts","sourceRoot":"","sources":["../../src/rules/no-unnecessary-template-expression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAmBzD,MAAM,MAAM,SAAS,GAAG,iCAAiC,CAAC;;AAqB1D,wBAgbG"}
|
@@ -43,7 +43,7 @@ const evenNumOfBackslashesRegExp = /(?<!(?:[^\\]|^)(?:\\\\)*\\)/;
|
|
43
43
|
// '\\\\$' <- true
|
44
44
|
// '\\\\\\$' <- false
|
45
45
|
function endsWithUnescapedDollarSign(str) {
|
46
|
-
return new RegExp(`${
|
46
|
+
return new RegExp(`${evenNumOfBackslashesRegExp.source}\\$$`).test(str);
|
47
47
|
}
|
48
48
|
exports.default = (0, util_1.createRule)({
|
49
49
|
name: 'no-unnecessary-template-expression',
|
@@ -233,7 +233,7 @@ exports.default = (0, util_1.createRule)({
|
|
233
233
|
// \\` -> \\\`
|
234
234
|
// \${ -> \${
|
235
235
|
// \\${ -> \\\${
|
236
|
-
.replaceAll(new RegExp(`${
|
236
|
+
.replaceAll(new RegExp(`${evenNumOfBackslashesRegExp.source}(\`|\\\${)`, 'g'), '\\$1');
|
237
237
|
// `...${'...$'}{...`
|
238
238
|
// ^^^^
|
239
239
|
if (nextCharacterIsOpeningCurlyBrace &&
|
@@ -0,0 +1,4 @@
|
|
1
|
+
type MessageIds = 'suggestRemove' | 'suggestSatisfies' | 'unnecessaryTypeConversion';
|
2
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
3
|
+
export default _default;
|
4
|
+
//# sourceMappingURL=no-unnecessary-type-conversion.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"no-unnecessary-type-conversion.d.ts","sourceRoot":"","sources":["../../src/rules/no-unnecessary-type-conversion.ts"],"names":[],"mappings":"AAgBA,KAAK,UAAU,GACX,eAAe,GACf,kBAAkB,GAClB,2BAA2B,CAAC;;AAEhC,wBAoVG"}
|
@@ -0,0 +1,305 @@
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
36
|
+
const utils_1 = require("@typescript-eslint/utils");
|
37
|
+
const ts_api_utils_1 = require("ts-api-utils");
|
38
|
+
const ts = __importStar(require("typescript"));
|
39
|
+
const util_1 = require("../util");
|
40
|
+
exports.default = (0, util_1.createRule)({
|
41
|
+
name: 'no-unnecessary-type-conversion',
|
42
|
+
meta: {
|
43
|
+
type: 'suggestion',
|
44
|
+
docs: {
|
45
|
+
description: 'Disallow conversion idioms when they do not change the type or value of the expression',
|
46
|
+
requiresTypeChecking: true,
|
47
|
+
},
|
48
|
+
fixable: 'code',
|
49
|
+
hasSuggestions: true,
|
50
|
+
messages: {
|
51
|
+
suggestRemove: 'Remove the type conversion.',
|
52
|
+
suggestSatisfies: 'Instead, assert that the value satisfies the {{type}} type.',
|
53
|
+
unnecessaryTypeConversion: '{{violation}} does not change the type or value of the {{type}}.',
|
54
|
+
},
|
55
|
+
schema: [],
|
56
|
+
},
|
57
|
+
defaultOptions: [],
|
58
|
+
create(context) {
|
59
|
+
function doesUnderlyingTypeMatchFlag(type, typeFlag) {
|
60
|
+
return (0, ts_api_utils_1.unionTypeParts)(type).every(t => (0, util_1.isTypeFlagSet)(t, typeFlag));
|
61
|
+
}
|
62
|
+
const services = (0, util_1.getParserServices)(context);
|
63
|
+
function handleUnaryOperator(node, typeFlag, typeString, violation, isDoubleOperator) {
|
64
|
+
const outerNode = isDoubleOperator ? node.parent : node;
|
65
|
+
const type = services.getTypeAtLocation(node.argument);
|
66
|
+
if (doesUnderlyingTypeMatchFlag(type, typeFlag)) {
|
67
|
+
const wrappingFixerParams = {
|
68
|
+
node: outerNode,
|
69
|
+
innerNode: [node.argument],
|
70
|
+
sourceCode: context.sourceCode,
|
71
|
+
};
|
72
|
+
context.report({
|
73
|
+
loc: {
|
74
|
+
start: outerNode.loc.start,
|
75
|
+
end: {
|
76
|
+
column: node.loc.start.column + 1,
|
77
|
+
line: node.loc.start.line,
|
78
|
+
},
|
79
|
+
},
|
80
|
+
messageId: 'unnecessaryTypeConversion',
|
81
|
+
data: { type: typeString, violation },
|
82
|
+
suggest: [
|
83
|
+
{
|
84
|
+
messageId: 'suggestRemove',
|
85
|
+
fix: (0, util_1.getWrappingFixer)(wrappingFixerParams),
|
86
|
+
},
|
87
|
+
{
|
88
|
+
messageId: 'suggestSatisfies',
|
89
|
+
data: { type: typeString },
|
90
|
+
fix: (0, util_1.getWrappingFixer)({
|
91
|
+
...wrappingFixerParams,
|
92
|
+
wrap: expr => `${expr} satisfies ${typeString}`,
|
93
|
+
}),
|
94
|
+
},
|
95
|
+
],
|
96
|
+
});
|
97
|
+
}
|
98
|
+
}
|
99
|
+
return {
|
100
|
+
'AssignmentExpression[operator = "+="]'(node) {
|
101
|
+
if (node.right.type === utils_1.AST_NODE_TYPES.Literal &&
|
102
|
+
node.right.value === '' &&
|
103
|
+
doesUnderlyingTypeMatchFlag(services.getTypeAtLocation(node.left), ts.TypeFlags.StringLike)) {
|
104
|
+
const wrappingFixerParams = {
|
105
|
+
node,
|
106
|
+
innerNode: [node.left],
|
107
|
+
sourceCode: context.sourceCode,
|
108
|
+
};
|
109
|
+
context.report({
|
110
|
+
node,
|
111
|
+
messageId: 'unnecessaryTypeConversion',
|
112
|
+
data: {
|
113
|
+
type: 'string',
|
114
|
+
violation: "Concatenating a string with ''",
|
115
|
+
},
|
116
|
+
suggest: [
|
117
|
+
{
|
118
|
+
messageId: 'suggestRemove',
|
119
|
+
fix: node.parent.type === utils_1.AST_NODE_TYPES.ExpressionStatement
|
120
|
+
? (fixer) => [
|
121
|
+
fixer.removeRange([
|
122
|
+
node.parent.range[0],
|
123
|
+
node.parent.range[1],
|
124
|
+
]),
|
125
|
+
]
|
126
|
+
: (0, util_1.getWrappingFixer)(wrappingFixerParams),
|
127
|
+
},
|
128
|
+
{
|
129
|
+
messageId: 'suggestSatisfies',
|
130
|
+
data: { type: 'string' },
|
131
|
+
fix: (0, util_1.getWrappingFixer)({
|
132
|
+
...wrappingFixerParams,
|
133
|
+
wrap: expr => `${expr} satisfies string`,
|
134
|
+
}),
|
135
|
+
},
|
136
|
+
],
|
137
|
+
});
|
138
|
+
}
|
139
|
+
},
|
140
|
+
'BinaryExpression[operator = "+"]'(node) {
|
141
|
+
if (node.right.type === utils_1.AST_NODE_TYPES.Literal &&
|
142
|
+
node.right.value === '' &&
|
143
|
+
doesUnderlyingTypeMatchFlag(services.getTypeAtLocation(node.left), ts.TypeFlags.StringLike)) {
|
144
|
+
const wrappingFixerParams = {
|
145
|
+
node,
|
146
|
+
innerNode: [node.left],
|
147
|
+
sourceCode: context.sourceCode,
|
148
|
+
};
|
149
|
+
context.report({
|
150
|
+
loc: {
|
151
|
+
start: node.left.loc.end,
|
152
|
+
end: node.loc.end,
|
153
|
+
},
|
154
|
+
messageId: 'unnecessaryTypeConversion',
|
155
|
+
data: {
|
156
|
+
type: 'string',
|
157
|
+
violation: "Concatenating a string with ''",
|
158
|
+
},
|
159
|
+
suggest: [
|
160
|
+
{
|
161
|
+
messageId: 'suggestRemove',
|
162
|
+
fix: (0, util_1.getWrappingFixer)(wrappingFixerParams),
|
163
|
+
},
|
164
|
+
{
|
165
|
+
messageId: 'suggestSatisfies',
|
166
|
+
data: { type: 'string' },
|
167
|
+
fix: (0, util_1.getWrappingFixer)({
|
168
|
+
...wrappingFixerParams,
|
169
|
+
wrap: expr => `${expr} satisfies string`,
|
170
|
+
}),
|
171
|
+
},
|
172
|
+
],
|
173
|
+
});
|
174
|
+
}
|
175
|
+
else if (node.left.type === utils_1.AST_NODE_TYPES.Literal &&
|
176
|
+
node.left.value === '' &&
|
177
|
+
doesUnderlyingTypeMatchFlag(services.getTypeAtLocation(node.right), ts.TypeFlags.StringLike)) {
|
178
|
+
const wrappingFixerParams = {
|
179
|
+
node,
|
180
|
+
innerNode: [node.right],
|
181
|
+
sourceCode: context.sourceCode,
|
182
|
+
};
|
183
|
+
context.report({
|
184
|
+
loc: {
|
185
|
+
start: node.loc.start,
|
186
|
+
end: node.right.loc.start,
|
187
|
+
},
|
188
|
+
messageId: 'unnecessaryTypeConversion',
|
189
|
+
data: {
|
190
|
+
type: 'string',
|
191
|
+
violation: "Concatenating '' with a string",
|
192
|
+
},
|
193
|
+
suggest: [
|
194
|
+
{
|
195
|
+
messageId: 'suggestRemove',
|
196
|
+
fix: (0, util_1.getWrappingFixer)(wrappingFixerParams),
|
197
|
+
},
|
198
|
+
{
|
199
|
+
messageId: 'suggestSatisfies',
|
200
|
+
data: { type: 'string' },
|
201
|
+
fix: (0, util_1.getWrappingFixer)({
|
202
|
+
...wrappingFixerParams,
|
203
|
+
wrap: expr => `${expr} satisfies string`,
|
204
|
+
}),
|
205
|
+
},
|
206
|
+
],
|
207
|
+
});
|
208
|
+
}
|
209
|
+
},
|
210
|
+
CallExpression(node) {
|
211
|
+
const nodeCallee = node.callee;
|
212
|
+
const builtInTypeFlags = {
|
213
|
+
BigInt: ts.TypeFlags.BigIntLike,
|
214
|
+
Boolean: ts.TypeFlags.BooleanLike,
|
215
|
+
Number: ts.TypeFlags.NumberLike,
|
216
|
+
String: ts.TypeFlags.StringLike,
|
217
|
+
};
|
218
|
+
if (nodeCallee.type !== utils_1.AST_NODE_TYPES.Identifier ||
|
219
|
+
!(nodeCallee.name in builtInTypeFlags)) {
|
220
|
+
return;
|
221
|
+
}
|
222
|
+
const typeFlag = builtInTypeFlags[nodeCallee.name];
|
223
|
+
const scope = context.sourceCode.getScope(node);
|
224
|
+
const variable = scope.set.get(nodeCallee.name);
|
225
|
+
if (!!variable?.defs.length ||
|
226
|
+
!doesUnderlyingTypeMatchFlag((0, util_1.getConstrainedTypeAtLocation)(services, node.arguments[0]), typeFlag)) {
|
227
|
+
return;
|
228
|
+
}
|
229
|
+
const wrappingFixerParams = {
|
230
|
+
node,
|
231
|
+
innerNode: [node.arguments[0]],
|
232
|
+
sourceCode: context.sourceCode,
|
233
|
+
};
|
234
|
+
const typeString = nodeCallee.name.toLowerCase();
|
235
|
+
context.report({
|
236
|
+
node: nodeCallee,
|
237
|
+
messageId: 'unnecessaryTypeConversion',
|
238
|
+
data: {
|
239
|
+
type: nodeCallee.name.toLowerCase(),
|
240
|
+
violation: `Passing a ${typeString} to ${nodeCallee.name}()`,
|
241
|
+
},
|
242
|
+
suggest: [
|
243
|
+
{
|
244
|
+
messageId: 'suggestRemove',
|
245
|
+
fix: (0, util_1.getWrappingFixer)(wrappingFixerParams),
|
246
|
+
},
|
247
|
+
{
|
248
|
+
messageId: 'suggestSatisfies',
|
249
|
+
data: { type: typeString },
|
250
|
+
fix: (0, util_1.getWrappingFixer)({
|
251
|
+
...wrappingFixerParams,
|
252
|
+
wrap: expr => `${expr} satisfies ${typeString}`,
|
253
|
+
}),
|
254
|
+
},
|
255
|
+
],
|
256
|
+
});
|
257
|
+
},
|
258
|
+
'CallExpression > MemberExpression.callee > Identifier[name = "toString"].property'(node) {
|
259
|
+
const memberExpr = node.parent;
|
260
|
+
const type = (0, util_1.getConstrainedTypeAtLocation)(services, memberExpr.object);
|
261
|
+
if (doesUnderlyingTypeMatchFlag(type, ts.TypeFlags.StringLike)) {
|
262
|
+
const wrappingFixerParams = {
|
263
|
+
node: memberExpr.parent,
|
264
|
+
innerNode: [memberExpr.object],
|
265
|
+
sourceCode: context.sourceCode,
|
266
|
+
};
|
267
|
+
context.report({
|
268
|
+
loc: {
|
269
|
+
start: memberExpr.property.loc.start,
|
270
|
+
end: memberExpr.parent.loc.end,
|
271
|
+
},
|
272
|
+
messageId: 'unnecessaryTypeConversion',
|
273
|
+
data: {
|
274
|
+
type: 'string',
|
275
|
+
violation: "Calling a string's .toString() method",
|
276
|
+
},
|
277
|
+
suggest: [
|
278
|
+
{
|
279
|
+
messageId: 'suggestRemove',
|
280
|
+
fix: (0, util_1.getWrappingFixer)(wrappingFixerParams),
|
281
|
+
},
|
282
|
+
{
|
283
|
+
messageId: 'suggestSatisfies',
|
284
|
+
data: { type: 'string' },
|
285
|
+
fix: (0, util_1.getWrappingFixer)({
|
286
|
+
...wrappingFixerParams,
|
287
|
+
wrap: expr => `${expr} satisfies string`,
|
288
|
+
}),
|
289
|
+
},
|
290
|
+
],
|
291
|
+
});
|
292
|
+
}
|
293
|
+
},
|
294
|
+
'UnaryExpression[operator = "!"] > UnaryExpression[operator = "!"]'(node) {
|
295
|
+
handleUnaryOperator(node, ts.TypeFlags.BooleanLike, 'boolean', 'Using !! on a boolean', true);
|
296
|
+
},
|
297
|
+
'UnaryExpression[operator = "+"]'(node) {
|
298
|
+
handleUnaryOperator(node, ts.TypeFlags.NumberLike, 'number', 'Using the unary + operator on a number', false);
|
299
|
+
},
|
300
|
+
'UnaryExpression[operator = "~"] > UnaryExpression[operator = "~"]'(node) {
|
301
|
+
handleUnaryOperator(node, ts.TypeFlags.NumberLike, 'number', 'Using ~~ on a number', true);
|
302
|
+
},
|
303
|
+
};
|
304
|
+
},
|
305
|
+
});
|
@@ -168,7 +168,7 @@ exports.default = (0, util_1.createRule)({
|
|
168
168
|
}
|
169
169
|
else if (receiverProperty.key.type === utils_1.AST_NODE_TYPES.TemplateLiteral &&
|
170
170
|
receiverProperty.key.quasis.length === 1) {
|
171
|
-
key =
|
171
|
+
key = receiverProperty.key.quasis[0].value.cooked;
|
172
172
|
}
|
173
173
|
else {
|
174
174
|
// can't figure out the name, so skip it
|
@@ -73,7 +73,7 @@ exports.default = (0, util_1.createRule)({
|
|
73
73
|
}
|
74
74
|
function isThisSpecifiedInParameters(originalFunc) {
|
75
75
|
const firstArg = originalFunc.params.at(0);
|
76
|
-
return
|
76
|
+
return (firstArg?.type === utils_1.AST_NODE_TYPES.Identifier && firstArg.name === 'this');
|
77
77
|
}
|
78
78
|
function isFunctionReturningThis(originalFunc, originalClass) {
|
79
79
|
if (isThisSpecifiedInParameters(originalFunc)) {
|
@@ -16,10 +16,10 @@ interface WrappingFixerParams {
|
|
16
16
|
* Receives multiple arguments if there are multiple innerNodes.
|
17
17
|
* E.g. ``code => `${code} != null` ``
|
18
18
|
*/
|
19
|
-
wrap
|
19
|
+
wrap?: (...code: string[]) => string;
|
20
20
|
}
|
21
21
|
/**
|
22
|
-
* Wraps node with some code. Adds
|
22
|
+
* Wraps node with some code. Adds parentheses as necessary.
|
23
23
|
* @returns Fixer which adds the specified code and parens if necessary.
|
24
24
|
*/
|
25
25
|
export declare function getWrappingFixer(params: WrappingFixerParams): (fixer: TSESLint.RuleFixer) => TSESLint.RuleFix;
|
@@ -36,7 +36,7 @@ export declare function getMovedNodeCode(params: {
|
|
36
36
|
sourceCode: Readonly<TSESLint.SourceCode>;
|
37
37
|
}): string;
|
38
38
|
/**
|
39
|
-
* Check if a node will always have the same precedence if
|
39
|
+
* Check if a node will always have the same precedence if its parent changes.
|
40
40
|
*/
|
41
41
|
export declare function isStrongPrecedenceNode(innerNode: TSESTree.Node): boolean;
|
42
42
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getWrappingFixer.d.ts","sourceRoot":"","sources":["../../src/util/getWrappingFixer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAQnE,UAAU,mBAAmB;IAC3B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC5C,kCAAkC;IAClC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;IACpB,mBAAmB;IACnB,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC1C;;;;OAIG;IACH,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;
|
1
|
+
{"version":3,"file":"getWrappingFixer.d.ts","sourceRoot":"","sources":["../../src/util/getWrappingFixer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAQnE,UAAU,mBAAmB;IAC3B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC5C,kCAAkC;IAClC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;IACpB,mBAAmB;IACnB,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC1C;;;;OAIG;IACH,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;CACtC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,mBAAmB,GAC1B,CAAC,KAAK,EAAE,QAAQ,CAAC,SAAS,KAAK,QAAQ,CAAC,OAAO,CA+CjD;AACD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACvC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC;IAC/B,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC;IAC1B,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;CAC3C,GAAG,MAAM,CAeT;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,GAAG,OAAO,CAcxE"}
|
@@ -5,7 +5,7 @@ exports.getMovedNodeCode = getMovedNodeCode;
|
|
5
5
|
exports.isStrongPrecedenceNode = isStrongPrecedenceNode;
|
6
6
|
const utils_1 = require("@typescript-eslint/utils");
|
7
7
|
/**
|
8
|
-
* Wraps node with some code. Adds
|
8
|
+
* Wraps node with some code. Adds parentheses as necessary.
|
9
9
|
* @returns Fixer which adds the specified code and parens if necessary.
|
10
10
|
*/
|
11
11
|
function getWrappingFixer(params) {
|
@@ -25,6 +25,9 @@ function getWrappingFixer(params) {
|
|
25
25
|
}
|
26
26
|
return code;
|
27
27
|
});
|
28
|
+
if (!wrap) {
|
29
|
+
return fixer.replaceText(node, innerCodes.join(''));
|
30
|
+
}
|
28
31
|
// do the wrapping
|
29
32
|
let code = wrap(...innerCodes);
|
30
33
|
// check the outer expression's precedence
|
@@ -63,7 +66,7 @@ function getMovedNodeCode(params) {
|
|
63
66
|
return `(${code})`;
|
64
67
|
}
|
65
68
|
/**
|
66
|
-
* Check if a node will always have the same precedence if
|
69
|
+
* Check if a node will always have the same precedence if its parent changes.
|
67
70
|
*/
|
68
71
|
function isStrongPrecedenceNode(innerNode) {
|
69
72
|
return (innerNode.type === utils_1.AST_NODE_TYPES.Literal ||
|
@@ -0,0 +1,79 @@
|
|
1
|
+
---
|
2
|
+
description: 'Disallow conversion idioms when they do not change the type or value of the expression.'
|
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-unnecessary-type-conversion** for documentation.
|
11
|
+
|
12
|
+
JavaScript provides several commonly used idioms to convert values to a specific type:
|
13
|
+
|
14
|
+
- Primitive coercion (e.g. `Boolean(value)`, `String(value)`): using a built-in primitive function
|
15
|
+
- String concatenation (e.g. `value + ''`): turning a value into a string
|
16
|
+
- Unary coercion (e.g. `+value`, `!!value`): using a built-in operator
|
17
|
+
- The `.toString()` method defined on many types
|
18
|
+
|
19
|
+
These conversions are unnecessary if the value is already of that type.
|
20
|
+
|
21
|
+
## Examples
|
22
|
+
|
23
|
+
<Tabs>
|
24
|
+
<TabItem value="❌ Incorrect">
|
25
|
+
|
26
|
+
```ts
|
27
|
+
String('123');
|
28
|
+
'123'.toString();
|
29
|
+
'' + '123';
|
30
|
+
'123' + '';
|
31
|
+
|
32
|
+
Number(123);
|
33
|
+
+123;
|
34
|
+
~~123;
|
35
|
+
|
36
|
+
Boolean(true);
|
37
|
+
!!true;
|
38
|
+
|
39
|
+
BigInt(BigInt(1));
|
40
|
+
|
41
|
+
let str = '123';
|
42
|
+
str += '';
|
43
|
+
```
|
44
|
+
|
45
|
+
</TabItem>
|
46
|
+
<TabItem value="✅ Correct">
|
47
|
+
|
48
|
+
```ts
|
49
|
+
function foo(bar: string | number) {
|
50
|
+
String(bar);
|
51
|
+
bar.toString();
|
52
|
+
'' + bar;
|
53
|
+
bar + '';
|
54
|
+
|
55
|
+
Number(bar);
|
56
|
+
+bar;
|
57
|
+
~~bar;
|
58
|
+
|
59
|
+
Boolean(bar);
|
60
|
+
!!bar;
|
61
|
+
|
62
|
+
BigInt(1);
|
63
|
+
|
64
|
+
bar += '';
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
68
|
+
</TabItem>
|
69
|
+
</Tabs>
|
70
|
+
|
71
|
+
## When Not To Use It
|
72
|
+
|
73
|
+
If you don't care about having no-op type conversions in your code, then you can turn off this rule.
|
74
|
+
If you have types which are not accurate, then this rule might cause you to remove conversions that you actually do need.
|
75
|
+
|
76
|
+
## Related To
|
77
|
+
|
78
|
+
- [no-unnecessary-type-assertion](./no-unnecessary-type-assertion.mdx)
|
79
|
+
- [no-useless-template-literals](./no-useless-template-literals.mdx)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.31.2-alpha.
|
3
|
+
"version": "8.31.2-alpha.8",
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
5
5
|
"files": [
|
6
6
|
"dist",
|
@@ -62,10 +62,10 @@
|
|
62
62
|
},
|
63
63
|
"dependencies": {
|
64
64
|
"@eslint-community/regexpp": "^4.10.0",
|
65
|
-
"@typescript-eslint/scope-manager": "8.31.2-alpha.
|
66
|
-
"@typescript-eslint/type-utils": "8.31.2-alpha.
|
67
|
-
"@typescript-eslint/utils": "8.31.2-alpha.
|
68
|
-
"@typescript-eslint/visitor-keys": "8.31.2-alpha.
|
65
|
+
"@typescript-eslint/scope-manager": "8.31.2-alpha.8",
|
66
|
+
"@typescript-eslint/type-utils": "8.31.2-alpha.8",
|
67
|
+
"@typescript-eslint/utils": "8.31.2-alpha.8",
|
68
|
+
"@typescript-eslint/visitor-keys": "8.31.2-alpha.8",
|
69
69
|
"graphemer": "^1.4.0",
|
70
70
|
"ignore": "^5.3.1",
|
71
71
|
"natural-compare": "^1.4.0",
|
@@ -75,8 +75,8 @@
|
|
75
75
|
"@types/marked": "^5.0.2",
|
76
76
|
"@types/mdast": "^4.0.3",
|
77
77
|
"@types/natural-compare": "*",
|
78
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.31.2-alpha.
|
79
|
-
"@typescript-eslint/rule-tester": "8.31.2-alpha.
|
78
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.31.2-alpha.8",
|
79
|
+
"@typescript-eslint/rule-tester": "8.31.2-alpha.8",
|
80
80
|
"@vitest/coverage-v8": "^3.1.1",
|
81
81
|
"ajv": "^6.12.6",
|
82
82
|
"cross-fetch": "*",
|