@typescript-eslint/eslint-plugin 8.31.2-alpha.7 → 8.32.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.
Files changed (72) hide show
  1. package/dist/configs/eslintrc/all.d.ts +1 -0
  2. package/dist/configs/eslintrc/all.d.ts.map +1 -1
  3. package/dist/configs/eslintrc/all.js +1 -0
  4. package/dist/configs/eslintrc/disable-type-checked.d.ts +1 -0
  5. package/dist/configs/eslintrc/disable-type-checked.d.ts.map +1 -1
  6. package/dist/configs/eslintrc/disable-type-checked.js +1 -0
  7. package/dist/configs/flat/all.d.ts.map +1 -1
  8. package/dist/configs/flat/all.js +1 -0
  9. package/dist/configs/flat/disable-type-checked.d.ts.map +1 -1
  10. package/dist/configs/flat/disable-type-checked.js +1 -0
  11. package/dist/index.d.ts +3 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/raw-plugin.d.ts +3 -0
  14. package/dist/raw-plugin.d.ts.map +1 -1
  15. package/dist/rules/adjacent-overload-signatures.js +1 -1
  16. package/dist/rules/await-thenable.js +2 -2
  17. package/dist/rules/enum-utils/shared.js +1 -1
  18. package/dist/rules/explicit-function-return-type.js +2 -2
  19. package/dist/rules/index.d.ts +1 -0
  20. package/dist/rules/index.d.ts.map +1 -1
  21. package/dist/rules/index.js +2 -0
  22. package/dist/rules/member-ordering.js +1 -1
  23. package/dist/rules/no-confusing-void-expression.js +3 -3
  24. package/dist/rules/no-duplicate-enum-values.js +2 -2
  25. package/dist/rules/no-empty-interface.d.ts.map +1 -1
  26. package/dist/rules/no-empty-interface.js +2 -2
  27. package/dist/rules/no-floating-promises.d.ts.map +1 -1
  28. package/dist/rules/no-floating-promises.js +15 -27
  29. package/dist/rules/no-meaningless-void-operator.js +1 -1
  30. package/dist/rules/no-misused-promises.js +8 -8
  31. package/dist/rules/no-misused-spread.js +2 -2
  32. package/dist/rules/no-redundant-type-constituents.js +2 -2
  33. package/dist/rules/no-unnecessary-condition.js +5 -5
  34. package/dist/rules/no-unnecessary-template-expression.d.ts.map +1 -1
  35. package/dist/rules/no-unnecessary-template-expression.js +3 -3
  36. package/dist/rules/no-unnecessary-type-assertion.js +2 -2
  37. package/dist/rules/no-unnecessary-type-conversion.d.ts +4 -0
  38. package/dist/rules/no-unnecessary-type-conversion.d.ts.map +1 -0
  39. package/dist/rules/no-unnecessary-type-conversion.js +307 -0
  40. package/dist/rules/no-unsafe-assignment.js +1 -1
  41. package/dist/rules/no-unsafe-enum-comparison.js +4 -4
  42. package/dist/rules/no-unsafe-unary-minus.js +1 -1
  43. package/dist/rules/non-nullable-type-assertion-style.js +1 -1
  44. package/dist/rules/only-throw-error.d.ts +1 -0
  45. package/dist/rules/only-throw-error.d.ts.map +1 -1
  46. package/dist/rules/only-throw-error.js +47 -0
  47. package/dist/rules/prefer-find.js +2 -2
  48. package/dist/rules/prefer-nullish-coalescing.js +2 -2
  49. package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +1 -1
  50. package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js +1 -1
  51. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +1 -1
  52. package/dist/rules/prefer-reduce-type-parameter.js +2 -2
  53. package/dist/rules/prefer-regexp-exec.js +1 -1
  54. package/dist/rules/prefer-return-this-type.js +1 -1
  55. package/dist/rules/restrict-plus-operands.js +4 -4
  56. package/dist/rules/strict-boolean-expressions.d.ts.map +1 -1
  57. package/dist/rules/strict-boolean-expressions.js +3 -3
  58. package/dist/rules/switch-exhaustiveness-check.js +4 -4
  59. package/dist/rules/unbound-method.d.ts.map +1 -1
  60. package/dist/rules/unbound-method.js +2 -2
  61. package/dist/rules/use-unknown-in-catch-callback-variable.js +1 -1
  62. package/dist/util/getWrappingFixer.d.ts +3 -3
  63. package/dist/util/getWrappingFixer.d.ts.map +1 -1
  64. package/dist/util/getWrappingFixer.js +5 -2
  65. package/dist/util/isArrayMethodCallWithPredicate.js +2 -2
  66. package/dist/util/promiseUtils.d.ts +28 -0
  67. package/dist/util/promiseUtils.d.ts.map +1 -0
  68. package/dist/util/promiseUtils.js +98 -0
  69. package/dist/util/truthinessUtils.js +4 -4
  70. package/docs/rules/no-unnecessary-type-conversion.mdx +79 -0
  71. package/docs/rules/only-throw-error.mdx +6 -0
  72. package/package.json +13 -14
@@ -1 +1 @@
1
- {"version":3,"file":"unbound-method.d.ts","sourceRoot":"","sources":["../../src/rules/unbound-method.ts"],"names":[],"mappings":"AAkBA,UAAU,MAAM;IACd,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC;AAE/B,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,8BAA8B,CAAC;;AAiFpE,wBA0KG"}
1
+ {"version":3,"file":"unbound-method.d.ts","sourceRoot":"","sources":["../../src/rules/unbound-method.ts"],"names":[],"mappings":"AAkBA,UAAU,MAAM;IACd,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC;AAE/B,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,8BAA8B,CAAC;;AAiFpE,wBA4KG"}
@@ -215,8 +215,8 @@ exports.default = (0, util_1.createRule)({
215
215
  }
216
216
  }
217
217
  for (const intersectionPart of tsutils
218
- .unionTypeParts(services.getTypeAtLocation(node))
219
- .flatMap(unionPart => tsutils.intersectionTypeParts(unionPart))) {
218
+ .unionConstituents(services.getTypeAtLocation(node))
219
+ .flatMap(unionPart => tsutils.intersectionConstituents(unionPart))) {
220
220
  const reported = checkIfMethodAndReport(property.key, intersectionPart.getProperty(property.key.name));
221
221
  if (reported) {
222
222
  break;
@@ -63,7 +63,7 @@ exports.default = (0, util_1.createRule)({
63
63
  const { esTreeNodeToTSNodeMap, program } = (0, util_1.getParserServices)(context);
64
64
  const checker = program.getTypeChecker();
65
65
  function isFlaggableHandlerType(type) {
66
- for (const unionPart of tsutils.unionTypeParts(type)) {
66
+ for (const unionPart of tsutils.unionConstituents(type)) {
67
67
  const callSignatures = tsutils.getCallSignaturesOfType(unionPart);
68
68
  if (callSignatures.length === 0) {
69
69
  // Ignore any non-function components to the type. Those are not this rule's problem.
@@ -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: (...code: string[]) => string;
19
+ wrap?: (...code: string[]) => string;
20
20
  }
21
21
  /**
22
- * Wraps node with some code. Adds parenthesis as necessary.
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 it's parent changes.
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;CACrC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,mBAAmB,GAC1B,CAAC,KAAK,EAAE,QAAQ,CAAC,SAAS,KAAK,QAAQ,CAAC,OAAO,CA2CjD;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"}
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 parenthesis as necessary.
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 it's parent changes.
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 ||
@@ -58,7 +58,7 @@ function isArrayMethodCallWithPredicate(context, services, node) {
58
58
  const checker = services.program.getTypeChecker();
59
59
  const type = (0, type_utils_1.getConstrainedTypeAtLocation)(services, node.callee.object);
60
60
  return tsutils
61
- .unionTypeParts(type)
62
- .flatMap(part => tsutils.intersectionTypeParts(part))
61
+ .unionConstituents(type)
62
+ .flatMap(part => tsutils.intersectionConstituents(part))
63
63
  .some(t => checker.isArrayType(t) || checker.isTupleType(t));
64
64
  }
@@ -0,0 +1,28 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ import type { RuleContext } from '@typescript-eslint/utils/ts-eslint';
3
+ /**
4
+ * Parses a syntactically possible `Promise.then()` call. Does not check the
5
+ * type of the callee.
6
+ */
7
+ export declare function parseThenCall(node: TSESTree.CallExpression, context: RuleContext<string, unknown[]>): {
8
+ onFulfilled?: TSESTree.Expression | undefined;
9
+ onRejected?: TSESTree.Expression | undefined;
10
+ object: TSESTree.Expression;
11
+ } | undefined;
12
+ /**
13
+ * Parses a syntactically possible `Promise.catch()` call. Does not check the
14
+ * type of the callee.
15
+ */
16
+ export declare function parseCatchCall(node: TSESTree.CallExpression, context: RuleContext<string, unknown[]>): {
17
+ onRejected?: TSESTree.Expression | undefined;
18
+ object: TSESTree.Expression;
19
+ } | undefined;
20
+ /**
21
+ * Parses a syntactically possible `Promise.finally()` call. Does not check the
22
+ * type of the callee.
23
+ */
24
+ export declare function parseFinallyCall(node: TSESTree.CallExpression, context: RuleContext<string, unknown[]>): {
25
+ object: TSESTree.Expression;
26
+ onFinally?: TSESTree.Expression | undefined;
27
+ } | undefined;
28
+ //# sourceMappingURL=promiseUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promiseUtils.d.ts","sourceRoot":"","sources":["../../src/util/promiseUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAMtE;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,QAAQ,CAAC,cAAc,EAC7B,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,GAErC;IACE,WAAW,CAAC,EAAE,QAAQ,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9C,UAAU,CAAC,EAAE,QAAQ,CAAC,UAAU,GAAG,SAAS,CAAC;IAC7C,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC;CAC7B,GACD,SAAS,CAqCZ;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,QAAQ,CAAC,cAAc,EAC7B,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,GAErC;IACE,UAAU,CAAC,EAAE,QAAQ,CAAC,UAAU,GAAG,SAAS,CAAC;IAC7C,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC;CAC7B,GACD,SAAS,CAuBZ;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,CAAC,cAAc,EAC7B,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,GAErC;IACE,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC;IAC5B,SAAS,CAAC,EAAE,QAAQ,CAAC,UAAU,GAAG,SAAS,CAAC;CAC7C,GACD,SAAS,CAsBZ"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseThenCall = parseThenCall;
4
+ exports.parseCatchCall = parseCatchCall;
5
+ exports.parseFinallyCall = parseFinallyCall;
6
+ const utils_1 = require("@typescript-eslint/utils");
7
+ const misc_1 = require("./misc");
8
+ /**
9
+ * Parses a syntactically possible `Promise.then()` call. Does not check the
10
+ * type of the callee.
11
+ */
12
+ function parseThenCall(node, context) {
13
+ if (node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
14
+ const methodName = (0, misc_1.getStaticMemberAccessValue)(node.callee, context);
15
+ if (methodName === 'then') {
16
+ if (node.arguments.length >= 1) {
17
+ if (node.arguments[0].type === utils_1.AST_NODE_TYPES.SpreadElement) {
18
+ return {
19
+ object: node.callee.object,
20
+ };
21
+ }
22
+ if (node.arguments.length >= 2) {
23
+ if (node.arguments[1].type === utils_1.AST_NODE_TYPES.SpreadElement) {
24
+ return {
25
+ object: node.callee.object,
26
+ onFulfilled: node.arguments[0],
27
+ };
28
+ }
29
+ return {
30
+ object: node.callee.object,
31
+ onFulfilled: node.arguments[0],
32
+ onRejected: node.arguments[1],
33
+ };
34
+ }
35
+ return {
36
+ object: node.callee.object,
37
+ onFulfilled: node.arguments[0],
38
+ };
39
+ }
40
+ return {
41
+ object: node.callee.object,
42
+ };
43
+ }
44
+ }
45
+ return undefined;
46
+ }
47
+ /**
48
+ * Parses a syntactically possible `Promise.catch()` call. Does not check the
49
+ * type of the callee.
50
+ */
51
+ function parseCatchCall(node, context) {
52
+ if (node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
53
+ const methodName = (0, misc_1.getStaticMemberAccessValue)(node.callee, context);
54
+ if (methodName === 'catch') {
55
+ if (node.arguments.length >= 1) {
56
+ if (node.arguments[0].type === utils_1.AST_NODE_TYPES.SpreadElement) {
57
+ return {
58
+ object: node.callee.object,
59
+ };
60
+ }
61
+ return {
62
+ object: node.callee.object,
63
+ onRejected: node.arguments[0],
64
+ };
65
+ }
66
+ return {
67
+ object: node.callee.object,
68
+ };
69
+ }
70
+ }
71
+ return undefined;
72
+ }
73
+ /**
74
+ * Parses a syntactically possible `Promise.finally()` call. Does not check the
75
+ * type of the callee.
76
+ */
77
+ function parseFinallyCall(node, context) {
78
+ if (node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
79
+ const methodName = (0, misc_1.getStaticMemberAccessValue)(node.callee, context);
80
+ if (methodName === 'finally') {
81
+ if (node.arguments.length >= 1) {
82
+ if (node.arguments[0].type === utils_1.AST_NODE_TYPES.SpreadElement) {
83
+ return {
84
+ object: node.callee.object,
85
+ };
86
+ }
87
+ return {
88
+ object: node.callee.object,
89
+ onFinally: node.arguments[0],
90
+ };
91
+ }
92
+ return {
93
+ object: node.callee.object,
94
+ };
95
+ }
96
+ }
97
+ return undefined;
98
+ }
@@ -41,18 +41,18 @@ const getValueOfLiteralType_1 = require("./getValueOfLiteralType");
41
41
  const isTruthyLiteral = (type) => tsutils.isTrueLiteralType(type) ||
42
42
  (type.isLiteral() && !!(0, getValueOfLiteralType_1.getValueOfLiteralType)(type));
43
43
  const isPossiblyFalsy = (type) => tsutils
44
- .unionTypeParts(type)
44
+ .unionConstituents(type)
45
45
  // Intersections like `string & {}` can also be possibly falsy,
46
46
  // requiring us to look into the intersection.
47
- .flatMap(type => tsutils.intersectionTypeParts(type))
47
+ .flatMap(type => tsutils.intersectionConstituents(type))
48
48
  // PossiblyFalsy flag includes literal values, so exclude ones that
49
49
  // are definitely truthy
50
50
  .filter(t => !isTruthyLiteral(t))
51
51
  .some(type => tsutils.isTypeFlagSet(type, ts.TypeFlags.PossiblyFalsy));
52
52
  exports.isPossiblyFalsy = isPossiblyFalsy;
53
53
  const isPossiblyTruthy = (type) => tsutils
54
- .unionTypeParts(type)
55
- .map(type => tsutils.intersectionTypeParts(type))
54
+ .unionConstituents(type)
55
+ .map(type => tsutils.intersectionConstituents(type))
56
56
  .some(intersectionParts =>
57
57
  // It is possible to define intersections that are always falsy,
58
58
  // like `"" & { __brand: string }`.
@@ -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)
@@ -123,6 +123,11 @@ interface Options {
123
123
  | string
124
124
  )[];
125
125
 
126
+ /**
127
+ * Whether to allow rethrowing caught values that are not `Error` objects.
128
+ */
129
+ allowRethrowing?: boolean;
130
+
126
131
  /**
127
132
  * Whether to always allow throwing values typed as `any`.
128
133
  */
@@ -136,6 +141,7 @@ interface Options {
136
141
 
137
142
  const defaultOptions: Options = {
138
143
  allow: [],
144
+ allowRethrowing: false,
139
145
  allowThrowingAny: true,
140
146
  allowThrowingUnknown: true,
141
147
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.31.2-alpha.7",
3
+ "version": "8.32.0",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -50,40 +50,39 @@
50
50
  ],
51
51
  "scripts": {
52
52
  "build": "tsc -b tsconfig.build.json",
53
- "clean": "tsc -b tsconfig.build.json --clean",
54
- "postclean": "rimraf dist && rimraf coverage",
53
+ "clean": "rimraf dist/ coverage/",
55
54
  "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
56
55
  "generate:breaking-changes": "tsx tools/generate-breaking-changes.mts",
57
56
  "generate:configs": "npx nx generate-configs repo",
58
57
  "lint": "npx nx lint",
59
58
  "test": "vitest --run --config=$INIT_CWD/vitest.config.mts",
60
- "test-single": "vitest --run --config=$INIT_CWD/vitest.config.mts",
59
+ "test-single": "vitest --run --config=$INIT_CWD/vitest.config.mts --no-coverage",
61
60
  "check-types": "npx nx typecheck"
62
61
  },
63
62
  "dependencies": {
64
63
  "@eslint-community/regexpp": "^4.10.0",
65
- "@typescript-eslint/scope-manager": "8.31.2-alpha.7",
66
- "@typescript-eslint/type-utils": "8.31.2-alpha.7",
67
- "@typescript-eslint/utils": "8.31.2-alpha.7",
68
- "@typescript-eslint/visitor-keys": "8.31.2-alpha.7",
64
+ "@typescript-eslint/scope-manager": "8.32.0",
65
+ "@typescript-eslint/type-utils": "8.32.0",
66
+ "@typescript-eslint/utils": "8.32.0",
67
+ "@typescript-eslint/visitor-keys": "8.32.0",
69
68
  "graphemer": "^1.4.0",
70
69
  "ignore": "^5.3.1",
71
70
  "natural-compare": "^1.4.0",
72
- "ts-api-utils": "^2.0.1"
71
+ "ts-api-utils": "^2.1.0"
73
72
  },
74
73
  "devDependencies": {
75
74
  "@types/marked": "^5.0.2",
76
75
  "@types/mdast": "^4.0.3",
77
76
  "@types/natural-compare": "*",
78
- "@typescript-eslint/rule-schema-to-typescript-types": "8.31.2-alpha.7",
79
- "@typescript-eslint/rule-tester": "8.31.2-alpha.7",
80
- "@vitest/coverage-v8": "^3.1.1",
77
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.32.0",
78
+ "@typescript-eslint/rule-tester": "8.32.0",
79
+ "@vitest/coverage-v8": "^3.1.2",
81
80
  "ajv": "^6.12.6",
82
81
  "cross-fetch": "*",
83
82
  "eslint": "*",
84
83
  "json-schema": "*",
85
84
  "markdown-table": "^3.0.3",
86
- "marked": "^5.1.2",
85
+ "marked": "^15.0.0",
87
86
  "mdast-util-from-markdown": "^2.0.0",
88
87
  "mdast-util-mdx": "^3.0.0",
89
88
  "micromark-extension-mdxjs": "^3.0.0",
@@ -93,7 +92,7 @@
93
92
  "tsx": "*",
94
93
  "typescript": "*",
95
94
  "unist-util-visit": "^5.0.0",
96
- "vitest": "^3.1.1"
95
+ "vitest": "^3.1.2"
97
96
  },
98
97
  "peerDependencies": {
99
98
  "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0",