@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.
Files changed (287) hide show
  1. package/dist/configs/all.js +7 -6
  2. package/dist/configs/all.js.map +1 -1
  3. package/dist/configs/disable-type-checked.js +3 -3
  4. package/dist/configs/disable-type-checked.js.map +1 -1
  5. package/dist/configs/recommended-type-checked-only.js +6 -0
  6. package/dist/configs/recommended-type-checked-only.js.map +1 -1
  7. package/dist/configs/recommended-type-checked.js +13 -2
  8. package/dist/configs/recommended-type-checked.js.map +1 -1
  9. package/dist/configs/recommended.js +7 -2
  10. package/dist/configs/recommended.js.map +1 -1
  11. package/dist/configs/strict-type-checked-only.js +8 -2
  12. package/dist/configs/strict-type-checked-only.js.map +1 -1
  13. package/dist/configs/strict-type-checked.js +15 -5
  14. package/dist/configs/strict-type-checked.js.map +1 -1
  15. package/dist/configs/strict.js +7 -3
  16. package/dist/configs/strict.js.map +1 -1
  17. package/dist/configs/stylistic-type-checked-only.js +3 -0
  18. package/dist/configs/stylistic-type-checked-only.js.map +1 -1
  19. package/dist/configs/stylistic-type-checked.js +3 -2
  20. package/dist/configs/stylistic-type-checked.js.map +1 -1
  21. package/dist/configs/stylistic.js +0 -2
  22. package/dist/configs/stylistic.js.map +1 -1
  23. package/dist/rules/adjacent-overload-signatures.js +2 -6
  24. package/dist/rules/adjacent-overload-signatures.js.map +1 -1
  25. package/dist/rules/array-type.js +14 -5
  26. package/dist/rules/array-type.js.map +1 -1
  27. package/dist/rules/class-literal-property-style.js +16 -16
  28. package/dist/rules/class-literal-property-style.js.map +1 -1
  29. package/dist/rules/class-methods-use-this.js.map +1 -1
  30. package/dist/rules/consistent-type-assertions.js +5 -19
  31. package/dist/rules/consistent-type-assertions.js.map +1 -1
  32. package/dist/rules/consistent-type-definitions.js +1 -1
  33. package/dist/rules/consistent-type-definitions.js.map +1 -1
  34. package/dist/rules/consistent-type-imports.js +13 -13
  35. package/dist/rules/consistent-type-imports.js.map +1 -1
  36. package/dist/rules/default-param-last.js +6 -1
  37. package/dist/rules/default-param-last.js.map +1 -1
  38. package/dist/rules/dot-notation.js +8 -1
  39. package/dist/rules/dot-notation.js.map +1 -1
  40. package/dist/rules/enum-utils/shared.js +3 -4
  41. package/dist/rules/enum-utils/shared.js.map +1 -1
  42. package/dist/rules/explicit-member-accessibility.js +49 -37
  43. package/dist/rules/explicit-member-accessibility.js.map +1 -1
  44. package/dist/rules/index.js +14 -6
  45. package/dist/rules/index.js.map +1 -1
  46. package/dist/rules/init-declarations.js +57 -1
  47. package/dist/rules/init-declarations.js.map +1 -1
  48. package/dist/rules/member-ordering.js +8 -2
  49. package/dist/rules/member-ordering.js.map +1 -1
  50. package/dist/rules/method-signature-style.js +1 -3
  51. package/dist/rules/method-signature-style.js.map +1 -1
  52. package/dist/rules/naming-convention-utils/parse-options.js +2 -5
  53. package/dist/rules/naming-convention-utils/parse-options.js.map +1 -1
  54. package/dist/rules/naming-convention-utils/shared.js +3 -4
  55. package/dist/rules/naming-convention-utils/shared.js.map +1 -1
  56. package/dist/rules/naming-convention-utils/validator.js +1 -2
  57. package/dist/rules/naming-convention-utils/validator.js.map +1 -1
  58. package/dist/rules/naming-convention.js +3 -1
  59. package/dist/rules/naming-convention.js.map +1 -1
  60. package/dist/rules/no-array-delete.js +1 -1
  61. package/dist/rules/no-array-delete.js.map +1 -1
  62. package/dist/rules/no-base-to-string.js +1 -1
  63. package/dist/rules/no-base-to-string.js.map +1 -1
  64. package/dist/rules/no-duplicate-type-constituents.js +29 -3
  65. package/dist/rules/no-duplicate-type-constituents.js.map +1 -1
  66. package/dist/rules/no-dynamic-delete.js +8 -40
  67. package/dist/rules/no-dynamic-delete.js.map +1 -1
  68. package/dist/rules/no-empty-interface.js +2 -1
  69. package/dist/rules/no-empty-interface.js.map +1 -1
  70. package/dist/rules/no-empty-object-type.js +141 -0
  71. package/dist/rules/no-empty-object-type.js.map +1 -0
  72. package/dist/rules/no-extraneous-class.js +11 -3
  73. package/dist/rules/no-extraneous-class.js.map +1 -1
  74. package/dist/rules/no-floating-promises.js +91 -55
  75. package/dist/rules/no-floating-promises.js.map +1 -1
  76. package/dist/rules/no-implied-eval.js +6 -24
  77. package/dist/rules/no-implied-eval.js.map +1 -1
  78. package/dist/rules/no-inferrable-types.js +1 -2
  79. package/dist/rules/no-inferrable-types.js.map +1 -1
  80. package/dist/rules/no-invalid-this.js +6 -0
  81. package/dist/rules/no-invalid-this.js.map +1 -1
  82. package/dist/rules/no-magic-numbers.js +32 -1
  83. package/dist/rules/no-magic-numbers.js.map +1 -1
  84. package/dist/rules/no-misused-new.js +4 -3
  85. package/dist/rules/no-misused-new.js.map +1 -1
  86. package/dist/rules/no-misused-promises.js +76 -1
  87. package/dist/rules/no-misused-promises.js.map +1 -1
  88. package/dist/rules/no-mixed-enums.js +6 -9
  89. package/dist/rules/no-mixed-enums.js.map +1 -1
  90. package/dist/rules/no-non-null-assertion.js +12 -14
  91. package/dist/rules/no-non-null-assertion.js.map +1 -1
  92. package/dist/rules/no-require-imports.js +13 -3
  93. package/dist/rules/no-require-imports.js.map +1 -1
  94. package/dist/rules/no-restricted-imports.js +5 -6
  95. package/dist/rules/no-restricted-imports.js.map +1 -1
  96. package/dist/rules/{ban-types.js → no-restricted-types.js} +17 -91
  97. package/dist/rules/no-restricted-types.js.map +1 -0
  98. package/dist/rules/no-shadow.js +4 -9
  99. package/dist/rules/no-shadow.js.map +1 -1
  100. package/dist/rules/no-unnecessary-condition.js +8 -6
  101. package/dist/rules/no-unnecessary-condition.js.map +1 -1
  102. package/dist/rules/no-unnecessary-parameter-property-assignment.js +151 -0
  103. package/dist/rules/no-unnecessary-parameter-property-assignment.js.map +1 -0
  104. package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
  105. package/dist/rules/no-unnecessary-template-expression.js +223 -0
  106. package/dist/rules/no-unnecessary-template-expression.js.map +1 -0
  107. package/dist/rules/no-unnecessary-type-assertion.js +16 -13
  108. package/dist/rules/no-unnecessary-type-assertion.js.map +1 -1
  109. package/dist/rules/no-unnecessary-type-parameters.js +309 -0
  110. package/dist/rules/no-unnecessary-type-parameters.js.map +1 -0
  111. package/dist/rules/no-unsafe-argument.js +4 -2
  112. package/dist/rules/no-unsafe-argument.js.map +1 -1
  113. package/dist/rules/no-unsafe-assignment.js +24 -9
  114. package/dist/rules/no-unsafe-assignment.js.map +1 -1
  115. package/dist/rules/no-unsafe-call.js +5 -1
  116. package/dist/rules/no-unsafe-call.js.map +1 -1
  117. package/dist/rules/no-unsafe-enum-comparison.js +1 -5
  118. package/dist/rules/no-unsafe-enum-comparison.js.map +1 -1
  119. package/dist/rules/no-unsafe-function-type.js +47 -0
  120. package/dist/rules/no-unsafe-function-type.js.map +1 -0
  121. package/dist/rules/no-unsafe-member-access.js +10 -4
  122. package/dist/rules/no-unsafe-member-access.js.map +1 -1
  123. package/dist/rules/no-unsafe-return.js +9 -3
  124. package/dist/rules/no-unsafe-return.js.map +1 -1
  125. package/dist/rules/no-unsafe-unary-minus.js +1 -0
  126. package/dist/rules/no-unsafe-unary-minus.js.map +1 -1
  127. package/dist/rules/no-unused-expressions.js +1 -0
  128. package/dist/rules/no-unused-expressions.js.map +1 -1
  129. package/dist/rules/no-unused-vars.js +198 -79
  130. package/dist/rules/no-unused-vars.js.map +1 -1
  131. package/dist/rules/no-use-before-define.js +2 -16
  132. package/dist/rules/no-use-before-define.js.map +1 -1
  133. package/dist/rules/no-useless-constructor.js +1 -3
  134. package/dist/rules/no-useless-constructor.js.map +1 -1
  135. package/dist/rules/no-var-requires.js +2 -1
  136. package/dist/rules/no-var-requires.js.map +1 -1
  137. package/dist/rules/no-wrapper-object-types.js +61 -0
  138. package/dist/rules/no-wrapper-object-types.js.map +1 -0
  139. package/dist/rules/only-throw-error.js +1 -1
  140. package/dist/rules/only-throw-error.js.map +1 -1
  141. package/dist/rules/prefer-as-const.js +1 -1
  142. package/dist/rules/prefer-as-const.js.map +1 -1
  143. package/dist/rules/prefer-destructuring.js +3 -1
  144. package/dist/rules/prefer-destructuring.js.map +1 -1
  145. package/dist/rules/prefer-find.js +2 -1
  146. package/dist/rules/prefer-find.js.map +1 -1
  147. package/dist/rules/prefer-includes.js +1 -1
  148. package/dist/rules/prefer-includes.js.map +1 -1
  149. package/dist/rules/prefer-literal-enum-member.js +43 -2
  150. package/dist/rules/prefer-literal-enum-member.js.map +1 -1
  151. package/dist/rules/prefer-namespace-keyword.js +1 -1
  152. package/dist/rules/prefer-namespace-keyword.js.map +1 -1
  153. package/dist/rules/prefer-nullish-coalescing.js +8 -6
  154. package/dist/rules/prefer-nullish-coalescing.js.map +1 -1
  155. package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +32 -37
  156. package/dist/rules/prefer-optional-chain-utils/analyzeChain.js.map +1 -1
  157. package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js +1 -2
  158. package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js.map +1 -1
  159. package/dist/rules/prefer-optional-chain-utils/compareNodes.js +1 -2
  160. package/dist/rules/prefer-optional-chain-utils/compareNodes.js.map +1 -1
  161. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +6 -11
  162. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js.map +1 -1
  163. package/dist/rules/prefer-promise-reject-errors.js +1 -1
  164. package/dist/rules/prefer-promise-reject-errors.js.map +1 -1
  165. package/dist/rules/prefer-readonly.js +24 -12
  166. package/dist/rules/prefer-readonly.js.map +1 -1
  167. package/dist/rules/prefer-regexp-exec.js +15 -6
  168. package/dist/rules/prefer-regexp-exec.js.map +1 -1
  169. package/dist/rules/prefer-string-starts-ends-with.js.map +1 -1
  170. package/dist/rules/prefer-ts-expect-error.js +2 -1
  171. package/dist/rules/prefer-ts-expect-error.js.map +1 -1
  172. package/dist/rules/require-await.js +1 -1
  173. package/dist/rules/require-await.js.map +1 -1
  174. package/dist/rules/restrict-template-expressions.js +3 -3
  175. package/dist/rules/restrict-template-expressions.js.map +1 -1
  176. package/dist/rules/return-await.js +167 -86
  177. package/dist/rules/return-await.js.map +1 -1
  178. package/dist/rules/sort-type-constituents.js +23 -1
  179. package/dist/rules/sort-type-constituents.js.map +1 -1
  180. package/dist/rules/strict-boolean-expressions.js +112 -5
  181. package/dist/rules/strict-boolean-expressions.js.map +1 -1
  182. package/dist/rules/switch-exhaustiveness-check.js +7 -9
  183. package/dist/rules/switch-exhaustiveness-check.js.map +1 -1
  184. package/dist/rules/unbound-method.js +96 -27
  185. package/dist/rules/unbound-method.js.map +1 -1
  186. package/dist/rules/unified-signatures.js +3 -1
  187. package/dist/rules/unified-signatures.js.map +1 -1
  188. package/dist/util/astUtils.js +2 -3
  189. package/dist/util/astUtils.js.map +1 -1
  190. package/dist/util/collectUnusedVariables.js +110 -73
  191. package/dist/util/collectUnusedVariables.js.map +1 -1
  192. package/dist/util/createRule.js.map +1 -1
  193. package/dist/util/escapeRegExp.js +1 -2
  194. package/dist/util/escapeRegExp.js.map +1 -1
  195. package/dist/util/explicitReturnTypeUtils.js +11 -7
  196. package/dist/util/explicitReturnTypeUtils.js.map +1 -1
  197. package/dist/util/getESLintCoreRule.js +2 -2
  198. package/dist/util/getESLintCoreRule.js.map +1 -1
  199. package/dist/util/getForStatementHeadLoc.js +1 -2
  200. package/dist/util/getForStatementHeadLoc.js.map +1 -1
  201. package/dist/util/getFunctionHeadLoc.js +3 -4
  202. package/dist/util/getFunctionHeadLoc.js.map +1 -1
  203. package/dist/util/getMemberHeadLoc.js +80 -0
  204. package/dist/util/getMemberHeadLoc.js.map +1 -0
  205. package/dist/util/getOperatorPrecedence.js +5 -5
  206. package/dist/util/getOperatorPrecedence.js.map +1 -1
  207. package/dist/util/getStaticStringValue.js +1 -2
  208. package/dist/util/getStaticStringValue.js.map +1 -1
  209. package/dist/util/getStringLength.js +1 -2
  210. package/dist/util/getStringLength.js.map +1 -1
  211. package/dist/util/getTextWithParentheses.js +17 -0
  212. package/dist/util/getTextWithParentheses.js.map +1 -0
  213. package/dist/util/getThisExpression.js +1 -2
  214. package/dist/util/getThisExpression.js.map +1 -1
  215. package/dist/util/getWrappedCode.js +1 -2
  216. package/dist/util/getWrappedCode.js.map +1 -1
  217. package/dist/util/getWrappingFixer.js +2 -3
  218. package/dist/util/getWrappingFixer.js.map +1 -1
  219. package/dist/util/index.js +2 -0
  220. package/dist/util/index.js.map +1 -1
  221. package/dist/util/isAssignee.js +1 -2
  222. package/dist/util/isAssignee.js.map +1 -1
  223. package/dist/util/isNodeEqual.js +1 -2
  224. package/dist/util/isNodeEqual.js.map +1 -1
  225. package/dist/util/isNullLiteral.js +1 -2
  226. package/dist/util/isNullLiteral.js.map +1 -1
  227. package/dist/util/isTypeImport.js +22 -0
  228. package/dist/util/isTypeImport.js.map +1 -0
  229. package/dist/util/isUndefinedIdentifier.js +1 -2
  230. package/dist/util/isUndefinedIdentifier.js.map +1 -1
  231. package/dist/util/misc.js +15 -15
  232. package/dist/util/misc.js.map +1 -1
  233. package/dist/util/objectIterators.js +3 -4
  234. package/dist/util/objectIterators.js.map +1 -1
  235. package/dist/util/referenceContainsTypeQuery.js +20 -0
  236. package/dist/util/referenceContainsTypeQuery.js.map +1 -0
  237. package/dist/util/scopeUtils.js +11 -0
  238. package/dist/util/scopeUtils.js.map +1 -0
  239. package/docs/rules/array-type.mdx +4 -1
  240. package/docs/rules/ban-types.md +22 -0
  241. package/docs/rules/class-methods-use-this.mdx +1 -1
  242. package/docs/rules/consistent-indexed-object-style.mdx +1 -1
  243. package/docs/rules/consistent-type-imports.mdx +1 -1
  244. package/docs/rules/naming-convention.mdx +16 -0
  245. package/docs/rules/no-base-to-string.mdx +1 -1
  246. package/docs/rules/no-duplicate-imports.mdx +1 -1
  247. package/docs/rules/no-duplicate-type-constituents.mdx +6 -2
  248. package/docs/rules/no-dynamic-delete.mdx +12 -7
  249. package/docs/rules/no-empty-interface.mdx +10 -0
  250. package/docs/rules/no-empty-object-type.mdx +145 -0
  251. package/docs/rules/no-extraneous-class.mdx +6 -0
  252. package/docs/rules/no-floating-promises.mdx +148 -4
  253. package/docs/rules/no-import-type-side-effects.mdx +1 -1
  254. package/docs/rules/no-misused-promises.mdx +18 -20
  255. package/docs/rules/no-redundant-type-constituents.mdx +4 -0
  256. package/docs/rules/no-require-imports.mdx +28 -1
  257. package/docs/rules/no-restricted-types.mdx +71 -0
  258. package/docs/rules/no-type-alias.mdx +1 -1
  259. package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +12 -12
  260. package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +42 -0
  261. package/docs/rules/no-unnecessary-template-expression.mdx +85 -0
  262. package/docs/rules/no-unnecessary-type-parameters.mdx +109 -0
  263. package/docs/rules/no-unsafe-function-type.mdx +63 -0
  264. package/docs/rules/no-unused-expressions.mdx +41 -1
  265. package/docs/rules/no-unused-vars.mdx +5 -0
  266. package/docs/rules/no-useless-template-literals.mdx +3 -59
  267. package/docs/rules/no-var-requires.mdx +6 -0
  268. package/docs/rules/no-wrapper-object-types.mdx +75 -0
  269. package/docs/rules/only-throw-error.mdx +7 -0
  270. package/docs/rules/prefer-readonly-parameter-types.mdx +10 -4
  271. package/docs/rules/prefer-ts-expect-error.mdx +10 -0
  272. package/docs/rules/require-await.mdx +2 -2
  273. package/docs/rules/restrict-template-expressions.mdx +1 -1
  274. package/docs/rules/return-await.mdx +119 -23
  275. package/docs/rules/sort-type-constituents.mdx +29 -9
  276. package/docs/rules/sort-type-union-intersection-members.mdx +12 -0
  277. package/docs/rules/strict-boolean-expressions.mdx +6 -0
  278. package/docs/rules/unbound-method.mdx +3 -2
  279. package/package.json +15 -20
  280. package/rules.d.ts +34 -3
  281. package/dist/rules/ban-types.js.map +0 -1
  282. package/dist/rules/no-throw-literal.js +0 -97
  283. package/dist/rules/no-throw-literal.js.map +0 -1
  284. package/dist/rules/no-useless-template-literals.js +0 -153
  285. package/dist/rules/no-useless-template-literals.js.map +0 -1
  286. package/docs/rules/ban-types.mdx +0 -138
  287. package/docs/rules/no-throw-literal.mdx +0 -25
@@ -1,153 +0,0 @@
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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const utils_1 = require("@typescript-eslint/utils");
27
- const ts = __importStar(require("typescript"));
28
- const util_1 = require("../util");
29
- exports.default = (0, util_1.createRule)({
30
- name: 'no-useless-template-literals',
31
- meta: {
32
- fixable: 'code',
33
- type: 'suggestion',
34
- docs: {
35
- description: 'Disallow unnecessary template literals',
36
- recommended: 'strict',
37
- requiresTypeChecking: true,
38
- },
39
- messages: {
40
- noUselessTemplateLiteral: 'Template literal expression is unnecessary and can be simplified.',
41
- },
42
- schema: [],
43
- },
44
- defaultOptions: [],
45
- create(context) {
46
- const services = (0, util_1.getParserServices)(context);
47
- function isUnderlyingTypeString(expression) {
48
- const type = (0, util_1.getConstrainedTypeAtLocation)(services, expression);
49
- const isString = (t) => {
50
- return (0, util_1.isTypeFlagSet)(t, ts.TypeFlags.StringLike);
51
- };
52
- if (type.isUnion()) {
53
- return type.types.every(isString);
54
- }
55
- if (type.isIntersection()) {
56
- return type.types.some(isString);
57
- }
58
- return isString(type);
59
- }
60
- function isLiteral(expression) {
61
- return expression.type === utils_1.AST_NODE_TYPES.Literal;
62
- }
63
- function isTemplateLiteral(expression) {
64
- return expression.type === utils_1.AST_NODE_TYPES.TemplateLiteral;
65
- }
66
- function isInfinityIdentifier(expression) {
67
- return (expression.type === utils_1.AST_NODE_TYPES.Identifier &&
68
- expression.name === 'Infinity');
69
- }
70
- function isNaNIdentifier(expression) {
71
- return (expression.type === utils_1.AST_NODE_TYPES.Identifier &&
72
- expression.name === 'NaN');
73
- }
74
- return {
75
- TemplateLiteral(node) {
76
- if (node.parent.type === utils_1.AST_NODE_TYPES.TaggedTemplateExpression) {
77
- return;
78
- }
79
- const hasSingleStringVariable = node.quasis.length === 2 &&
80
- node.quasis[0].value.raw === '' &&
81
- node.quasis[1].value.raw === '' &&
82
- node.expressions.length === 1 &&
83
- isUnderlyingTypeString(node.expressions[0]);
84
- if (hasSingleStringVariable) {
85
- context.report({
86
- node: node.expressions[0],
87
- messageId: 'noUselessTemplateLiteral',
88
- fix(fixer) {
89
- const [prevQuasi, nextQuasi] = node.quasis;
90
- // Remove the quasis and backticks.
91
- return [
92
- fixer.removeRange([
93
- prevQuasi.range[1] - 3,
94
- node.expressions[0].range[0],
95
- ]),
96
- fixer.removeRange([
97
- node.expressions[0].range[1],
98
- nextQuasi.range[0] + 2,
99
- ]),
100
- ];
101
- },
102
- });
103
- return;
104
- }
105
- const fixableExpressions = node.expressions.filter(expression => isLiteral(expression) ||
106
- isTemplateLiteral(expression) ||
107
- (0, util_1.isUndefinedIdentifier)(expression) ||
108
- isInfinityIdentifier(expression) ||
109
- isNaNIdentifier(expression));
110
- fixableExpressions.forEach(expression => {
111
- context.report({
112
- node: expression,
113
- messageId: 'noUselessTemplateLiteral',
114
- fix(fixer) {
115
- const index = node.expressions.indexOf(expression);
116
- const prevQuasi = node.quasis[index];
117
- const nextQuasi = node.quasis[index + 1];
118
- // Remove the quasis' parts that are related to the current expression.
119
- const fixes = [
120
- fixer.removeRange([
121
- prevQuasi.range[1] - 2,
122
- expression.range[0],
123
- ]),
124
- fixer.removeRange([
125
- expression.range[1],
126
- nextQuasi.range[0] + 1,
127
- ]),
128
- ];
129
- const stringValue = (0, util_1.getStaticStringValue)(expression);
130
- if (stringValue != null) {
131
- const escapedValue = stringValue.replace(/([`$\\])/g, '\\$1');
132
- fixes.push(fixer.replaceText(expression, escapedValue));
133
- }
134
- else if (isTemplateLiteral(expression)) {
135
- // Note that some template literals get handled in the previous branch too.
136
- // Remove the beginning and trailing backtick characters.
137
- fixes.push(fixer.removeRange([
138
- expression.range[0],
139
- expression.range[0] + 1,
140
- ]), fixer.removeRange([
141
- expression.range[1] - 1,
142
- expression.range[1],
143
- ]));
144
- }
145
- return fixes;
146
- },
147
- });
148
- });
149
- },
150
- };
151
- },
152
- });
153
- //# sourceMappingURL=no-useless-template-literals.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"no-useless-template-literals.js","sourceRoot":"","sources":["../../src/rules/no-useless-template-literals.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAA0D;AAC1D,+CAAiC;AAEjC,kCAOiB;AAIjB,kBAAe,IAAA,iBAAU,EAAgB;IACvC,IAAI,EAAE,8BAA8B;IACpC,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,wCAAwC;YACrD,WAAW,EAAE,QAAQ;YACrB,oBAAoB,EAAE,IAAI;SAC3B;QACD,QAAQ,EAAE;YACR,wBAAwB,EACtB,mEAAmE;SACtE;QACD,MAAM,EAAE,EAAE;KACX;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,MAAM,QAAQ,GAAG,IAAA,wBAAiB,EAAC,OAAO,CAAC,CAAC;QAE5C,SAAS,sBAA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ChB,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;oCACnB,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;iCACxB,CAAC,EACF,KAAK,CAAC,WAAW,CAAC;oCAChB,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;oCACvB,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;iCACpB,CAAC,CACH,CAAC;4BACJ,CAAC;4BAED,OAAO,KAAK,CAAC;wBACf,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -1,138 +0,0 @@
1
- ---
2
- description: 'Disallow certain types.'
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/ban-types** for documentation.
11
-
12
- Some built-in types have aliases, while some types are considered dangerous or harmful.
13
- It's often a good idea to ban certain types to help with consistency and safety.
14
-
15
- This rule bans specific types and can suggest alternatives.
16
- Note that it does not ban the corresponding runtime objects from being used.
17
-
18
- ## Examples
19
-
20
- Examples of code with the default options:
21
-
22
- <Tabs>
23
- <TabItem value="❌ Incorrect">
24
-
25
- ```ts
26
- // use lower-case primitives for consistency
27
- const str: String = 'foo';
28
- const bool: Boolean = true;
29
- const num: Number = 1;
30
- const symb: Symbol = Symbol('foo');
31
- const bigInt: BigInt = 1n;
32
-
33
- // use a proper function type
34
- const func: Function = () => 1;
35
-
36
- // use safer object types
37
- const lowerObj: Object = {};
38
- const capitalObj: Object = { a: 'string' };
39
-
40
- const curly1: {} = 1;
41
- const curly2: {} = { a: 'string' };
42
- ```
43
-
44
- </TabItem>
45
- <TabItem value="✅ Correct">
46
-
47
- ```ts
48
- // use lower-case primitives for consistency
49
- const str: string = 'foo';
50
- const bool: boolean = true;
51
- const num: number = 1;
52
- const symb: symbol = Symbol('foo');
53
- const bigInt: bigint = 1n;
54
-
55
- // use a proper function type
56
- const func: () => number = () => 1;
57
-
58
- // use safer object types
59
- const lowerObj: object = {};
60
- const capitalObj: { a: string } = { a: 'string' };
61
-
62
- const curly1: number = 1;
63
- const curly2: Record<'a', string> = { a: 'string' };
64
- ```
65
-
66
- </TabItem>
67
- </Tabs>
68
-
69
- ## Options
70
-
71
- The default options provide a set of "best practices", intended to provide safety and standardization in your codebase:
72
-
73
- - Don't use the upper-case primitive types, you should use the lower-case types for consistency.
74
- - Avoid the `Function` type, as it provides little safety for the following reasons:
75
- - It provides no type safety when calling the value, which means it's easy to provide the wrong arguments.
76
- - It accepts class declarations, which will fail when called, as they are called without the `new` keyword.
77
- - Avoid the `Object` and `{}` types, as they mean "any non-nullish value".
78
- - This is a point of confusion for many developers, who think it means "any object type".
79
- - See [this comment for more information](https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492).
80
-
81
- <details>
82
- <summary>Default Options</summary>
83
-
84
- {/* Inject default options */}
85
-
86
- </details>
87
-
88
- ### `types`
89
-
90
- An object whose keys are the types you want to ban, and the values are error messages.
91
-
92
- The type can either be a type name literal (`Foo`), a type name with generic parameter instantiation(s) (`Foo<Bar>`), the empty object literal (`{}`), or the empty tuple type (`[]`).
93
-
94
- The values can be:
95
-
96
- - A string, which is the error message to be reported; or
97
- - `false` to specifically un-ban this type (useful when you are using `extendDefaults`); or
98
- - An object with the following properties:
99
- - `message: string` - the message to display when the type is matched.
100
- - `fixWith?: string` - a string to replace the banned type with when the fixer is run. If this is omitted, no fix will be done.
101
- - `suggest?: string[]` - a list of suggested replacements for the banned type.
102
-
103
- ### `extendDefaults`
104
-
105
- If you're specifying custom `types`, you can set this to `true` to extend the default `types` configuration. This is a convenience option to save you copying across the defaults when adding another type.
106
-
107
- If this is `false`, the rule will _only_ use the types defined in your configuration.
108
-
109
- Example configuration:
110
-
111
- ```jsonc
112
- {
113
- "@typescript-eslint/ban-types": [
114
- "error",
115
- {
116
- "types": {
117
- // add a custom message to help explain why not to use it
118
- "Foo": "Don't use Foo because it is unsafe",
119
-
120
- // add a custom message, AND tell the plugin how to fix it
121
- "OldAPI": {
122
- "message": "Use NewAPI instead",
123
- "fixWith": "NewAPI",
124
- },
125
-
126
- // un-ban a type that's banned by default
127
- "{}": false,
128
- },
129
- "extendDefaults": true,
130
- },
131
- ],
132
- }
133
- ```
134
-
135
- ## When Not To Use It
136
-
137
- If your project is a rare one that intentionally deals with the class equivalents of primitives, it might not be worthwhile to enable the default `ban-types` options.
138
- 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.
@@ -1,25 +0,0 @@
1
- ---
2
- description: 'Disallow throwing literals as exceptions.'
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-throw-literal** for documentation.
11
-
12
- It is considered good practice to only `throw` the `Error` object itself or an object using the `Error` object as base objects for user-defined exceptions.
13
- The fundamental benefit of `Error` objects is that they automatically keep track of where they were built and originated.
14
-
15
- This rule restricts what can be thrown as an exception.
16
-
17
- :::warning
18
- This rule is being renamed to [`only-throw-error`](./only-throw-error.mdx).
19
- When it was first created, it only prevented literals from being thrown (hence the name), but it has now been expanded to only allow expressions which have a possibility of being an `Error` object.
20
- With the `allowThrowingAny` and `allowThrowingUnknown` options, it can be configured to only allow throwing values which are guaranteed to be an instance of `Error`.
21
-
22
- The current name `no-throw-literal` will be removed in a future major version of typescript-eslint.
23
- :::
24
-
25
- {/* Intentionally Omitted: When Not To Use It */}