@typescript-eslint/eslint-plugin 8.0.0-alpha.9 → 8.0.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 (279) hide show
  1. package/dist/configs/all.js +6 -5
  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 +12 -2
  8. package/dist/configs/recommended-type-checked.js.map +1 -1
  9. package/dist/configs/recommended.js +6 -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 +14 -5
  14. package/dist/configs/strict-type-checked.js.map +1 -1
  15. package/dist/configs/strict.js +6 -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 -1
  20. package/dist/configs/stylistic-type-checked.js.map +1 -1
  21. package/dist/configs/stylistic.js +0 -1
  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 +12 -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-object-type.js +1 -1
  69. package/dist/rules/no-empty-object-type.js.map +1 -1
  70. package/dist/rules/no-extraneous-class.js +11 -3
  71. package/dist/rules/no-extraneous-class.js.map +1 -1
  72. package/dist/rules/no-floating-promises.js +91 -55
  73. package/dist/rules/no-floating-promises.js.map +1 -1
  74. package/dist/rules/no-implied-eval.js +6 -24
  75. package/dist/rules/no-implied-eval.js.map +1 -1
  76. package/dist/rules/no-inferrable-types.js +1 -2
  77. package/dist/rules/no-inferrable-types.js.map +1 -1
  78. package/dist/rules/no-invalid-this.js +6 -0
  79. package/dist/rules/no-invalid-this.js.map +1 -1
  80. package/dist/rules/no-magic-numbers.js +32 -1
  81. package/dist/rules/no-magic-numbers.js.map +1 -1
  82. package/dist/rules/no-misused-new.js +4 -3
  83. package/dist/rules/no-misused-new.js.map +1 -1
  84. package/dist/rules/no-misused-promises.js +76 -1
  85. package/dist/rules/no-misused-promises.js.map +1 -1
  86. package/dist/rules/no-mixed-enums.js +6 -9
  87. package/dist/rules/no-mixed-enums.js.map +1 -1
  88. package/dist/rules/no-non-null-assertion.js +12 -14
  89. package/dist/rules/no-non-null-assertion.js.map +1 -1
  90. package/dist/rules/no-require-imports.js +13 -3
  91. package/dist/rules/no-require-imports.js.map +1 -1
  92. package/dist/rules/no-restricted-imports.js +5 -6
  93. package/dist/rules/no-restricted-imports.js.map +1 -1
  94. package/dist/rules/{ban-types.js → no-restricted-types.js} +17 -70
  95. package/dist/rules/no-restricted-types.js.map +1 -0
  96. package/dist/rules/no-shadow.js +4 -9
  97. package/dist/rules/no-shadow.js.map +1 -1
  98. package/dist/rules/no-unnecessary-condition.js +8 -6
  99. package/dist/rules/no-unnecessary-condition.js.map +1 -1
  100. package/dist/rules/no-unnecessary-parameter-property-assignment.js +151 -0
  101. package/dist/rules/no-unnecessary-parameter-property-assignment.js.map +1 -0
  102. package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
  103. package/dist/rules/no-unnecessary-template-expression.js +223 -0
  104. package/dist/rules/no-unnecessary-template-expression.js.map +1 -0
  105. package/dist/rules/no-unnecessary-type-assertion.js +16 -13
  106. package/dist/rules/no-unnecessary-type-assertion.js.map +1 -1
  107. package/dist/rules/no-unnecessary-type-parameters.js +309 -0
  108. package/dist/rules/no-unnecessary-type-parameters.js.map +1 -0
  109. package/dist/rules/no-unsafe-argument.js +4 -2
  110. package/dist/rules/no-unsafe-argument.js.map +1 -1
  111. package/dist/rules/no-unsafe-assignment.js +24 -9
  112. package/dist/rules/no-unsafe-assignment.js.map +1 -1
  113. package/dist/rules/no-unsafe-call.js +5 -1
  114. package/dist/rules/no-unsafe-call.js.map +1 -1
  115. package/dist/rules/no-unsafe-enum-comparison.js +1 -5
  116. package/dist/rules/no-unsafe-enum-comparison.js.map +1 -1
  117. package/dist/rules/no-unsafe-function-type.js +47 -0
  118. package/dist/rules/no-unsafe-function-type.js.map +1 -0
  119. package/dist/rules/no-unsafe-member-access.js +10 -4
  120. package/dist/rules/no-unsafe-member-access.js.map +1 -1
  121. package/dist/rules/no-unsafe-return.js +9 -3
  122. package/dist/rules/no-unsafe-return.js.map +1 -1
  123. package/dist/rules/no-unsafe-unary-minus.js +1 -0
  124. package/dist/rules/no-unsafe-unary-minus.js.map +1 -1
  125. package/dist/rules/no-unused-expressions.js +1 -0
  126. package/dist/rules/no-unused-expressions.js.map +1 -1
  127. package/dist/rules/no-unused-vars.js +198 -79
  128. package/dist/rules/no-unused-vars.js.map +1 -1
  129. package/dist/rules/no-use-before-define.js +2 -16
  130. package/dist/rules/no-use-before-define.js.map +1 -1
  131. package/dist/rules/no-useless-constructor.js +1 -3
  132. package/dist/rules/no-useless-constructor.js.map +1 -1
  133. package/dist/rules/no-var-requires.js +2 -1
  134. package/dist/rules/no-var-requires.js.map +1 -1
  135. package/dist/rules/no-wrapper-object-types.js +61 -0
  136. package/dist/rules/no-wrapper-object-types.js.map +1 -0
  137. package/dist/rules/only-throw-error.js +1 -1
  138. package/dist/rules/only-throw-error.js.map +1 -1
  139. package/dist/rules/prefer-as-const.js +1 -1
  140. package/dist/rules/prefer-as-const.js.map +1 -1
  141. package/dist/rules/prefer-destructuring.js +3 -1
  142. package/dist/rules/prefer-destructuring.js.map +1 -1
  143. package/dist/rules/prefer-find.js +2 -1
  144. package/dist/rules/prefer-find.js.map +1 -1
  145. package/dist/rules/prefer-includes.js +1 -1
  146. package/dist/rules/prefer-includes.js.map +1 -1
  147. package/dist/rules/prefer-literal-enum-member.js +43 -2
  148. package/dist/rules/prefer-literal-enum-member.js.map +1 -1
  149. package/dist/rules/prefer-namespace-keyword.js +1 -1
  150. package/dist/rules/prefer-namespace-keyword.js.map +1 -1
  151. package/dist/rules/prefer-nullish-coalescing.js +8 -6
  152. package/dist/rules/prefer-nullish-coalescing.js.map +1 -1
  153. package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +32 -37
  154. package/dist/rules/prefer-optional-chain-utils/analyzeChain.js.map +1 -1
  155. package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js +1 -2
  156. package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js.map +1 -1
  157. package/dist/rules/prefer-optional-chain-utils/compareNodes.js +1 -2
  158. package/dist/rules/prefer-optional-chain-utils/compareNodes.js.map +1 -1
  159. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +6 -11
  160. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js.map +1 -1
  161. package/dist/rules/prefer-promise-reject-errors.js +1 -1
  162. package/dist/rules/prefer-promise-reject-errors.js.map +1 -1
  163. package/dist/rules/prefer-readonly.js +24 -12
  164. package/dist/rules/prefer-readonly.js.map +1 -1
  165. package/dist/rules/prefer-regexp-exec.js +15 -6
  166. package/dist/rules/prefer-regexp-exec.js.map +1 -1
  167. package/dist/rules/prefer-string-starts-ends-with.js.map +1 -1
  168. package/dist/rules/prefer-ts-expect-error.js +2 -1
  169. package/dist/rules/prefer-ts-expect-error.js.map +1 -1
  170. package/dist/rules/require-await.js +1 -1
  171. package/dist/rules/require-await.js.map +1 -1
  172. package/dist/rules/restrict-template-expressions.js +3 -3
  173. package/dist/rules/restrict-template-expressions.js.map +1 -1
  174. package/dist/rules/return-await.js +167 -86
  175. package/dist/rules/return-await.js.map +1 -1
  176. package/dist/rules/sort-type-constituents.js +23 -1
  177. package/dist/rules/sort-type-constituents.js.map +1 -1
  178. package/dist/rules/strict-boolean-expressions.js +112 -5
  179. package/dist/rules/strict-boolean-expressions.js.map +1 -1
  180. package/dist/rules/switch-exhaustiveness-check.js +7 -9
  181. package/dist/rules/switch-exhaustiveness-check.js.map +1 -1
  182. package/dist/rules/unbound-method.js +96 -27
  183. package/dist/rules/unbound-method.js.map +1 -1
  184. package/dist/rules/unified-signatures.js +3 -1
  185. package/dist/rules/unified-signatures.js.map +1 -1
  186. package/dist/util/astUtils.js +2 -3
  187. package/dist/util/astUtils.js.map +1 -1
  188. package/dist/util/collectUnusedVariables.js +110 -73
  189. package/dist/util/collectUnusedVariables.js.map +1 -1
  190. package/dist/util/createRule.js.map +1 -1
  191. package/dist/util/escapeRegExp.js +1 -2
  192. package/dist/util/escapeRegExp.js.map +1 -1
  193. package/dist/util/explicitReturnTypeUtils.js +11 -7
  194. package/dist/util/explicitReturnTypeUtils.js.map +1 -1
  195. package/dist/util/getESLintCoreRule.js +2 -2
  196. package/dist/util/getESLintCoreRule.js.map +1 -1
  197. package/dist/util/getForStatementHeadLoc.js +1 -2
  198. package/dist/util/getForStatementHeadLoc.js.map +1 -1
  199. package/dist/util/getFunctionHeadLoc.js +3 -4
  200. package/dist/util/getFunctionHeadLoc.js.map +1 -1
  201. package/dist/util/getMemberHeadLoc.js +80 -0
  202. package/dist/util/getMemberHeadLoc.js.map +1 -0
  203. package/dist/util/getOperatorPrecedence.js +5 -5
  204. package/dist/util/getOperatorPrecedence.js.map +1 -1
  205. package/dist/util/getStaticStringValue.js +1 -2
  206. package/dist/util/getStaticStringValue.js.map +1 -1
  207. package/dist/util/getStringLength.js +1 -2
  208. package/dist/util/getStringLength.js.map +1 -1
  209. package/dist/util/getTextWithParentheses.js +17 -0
  210. package/dist/util/getTextWithParentheses.js.map +1 -0
  211. package/dist/util/getThisExpression.js +1 -2
  212. package/dist/util/getThisExpression.js.map +1 -1
  213. package/dist/util/getWrappedCode.js +1 -2
  214. package/dist/util/getWrappedCode.js.map +1 -1
  215. package/dist/util/getWrappingFixer.js +2 -3
  216. package/dist/util/getWrappingFixer.js.map +1 -1
  217. package/dist/util/index.js +2 -0
  218. package/dist/util/index.js.map +1 -1
  219. package/dist/util/isAssignee.js +1 -2
  220. package/dist/util/isAssignee.js.map +1 -1
  221. package/dist/util/isNodeEqual.js +1 -2
  222. package/dist/util/isNodeEqual.js.map +1 -1
  223. package/dist/util/isNullLiteral.js +1 -2
  224. package/dist/util/isNullLiteral.js.map +1 -1
  225. package/dist/util/isTypeImport.js +22 -0
  226. package/dist/util/isTypeImport.js.map +1 -0
  227. package/dist/util/isUndefinedIdentifier.js +1 -2
  228. package/dist/util/isUndefinedIdentifier.js.map +1 -1
  229. package/dist/util/misc.js +15 -15
  230. package/dist/util/misc.js.map +1 -1
  231. package/dist/util/objectIterators.js +3 -4
  232. package/dist/util/objectIterators.js.map +1 -1
  233. package/dist/util/referenceContainsTypeQuery.js +20 -0
  234. package/dist/util/referenceContainsTypeQuery.js.map +1 -0
  235. package/dist/util/scopeUtils.js +11 -0
  236. package/dist/util/scopeUtils.js.map +1 -0
  237. package/docs/rules/array-type.mdx +4 -1
  238. package/docs/rules/ban-types.md +22 -0
  239. package/docs/rules/class-methods-use-this.mdx +1 -1
  240. package/docs/rules/consistent-indexed-object-style.mdx +1 -1
  241. package/docs/rules/naming-convention.mdx +16 -0
  242. package/docs/rules/no-base-to-string.mdx +1 -1
  243. package/docs/rules/no-duplicate-type-constituents.mdx +6 -2
  244. package/docs/rules/no-dynamic-delete.mdx +12 -7
  245. package/docs/rules/no-extraneous-class.mdx +6 -0
  246. package/docs/rules/no-floating-promises.mdx +146 -2
  247. package/docs/rules/no-misused-promises.mdx +18 -20
  248. package/docs/rules/no-redundant-type-constituents.mdx +4 -0
  249. package/docs/rules/no-require-imports.mdx +28 -1
  250. package/docs/rules/no-restricted-types.mdx +71 -0
  251. package/docs/rules/no-type-alias.mdx +1 -1
  252. package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +42 -0
  253. package/docs/rules/no-unnecessary-template-expression.mdx +85 -0
  254. package/docs/rules/no-unnecessary-type-parameters.mdx +114 -0
  255. package/docs/rules/no-unsafe-function-type.mdx +63 -0
  256. package/docs/rules/no-unused-expressions.mdx +41 -1
  257. package/docs/rules/no-unused-vars.mdx +5 -0
  258. package/docs/rules/no-useless-template-literals.mdx +3 -59
  259. package/docs/rules/no-var-requires.mdx +6 -0
  260. package/docs/rules/no-wrapper-object-types.mdx +75 -0
  261. package/docs/rules/only-throw-error.mdx +7 -0
  262. package/docs/rules/prefer-readonly-parameter-types.mdx +10 -4
  263. package/docs/rules/prefer-ts-expect-error.mdx +10 -0
  264. package/docs/rules/require-await.mdx +2 -2
  265. package/docs/rules/restrict-template-expressions.mdx +1 -1
  266. package/docs/rules/return-await.mdx +119 -23
  267. package/docs/rules/sort-type-constituents.mdx +29 -9
  268. package/docs/rules/sort-type-union-intersection-members.mdx +12 -0
  269. package/docs/rules/strict-boolean-expressions.mdx +6 -0
  270. package/docs/rules/unbound-method.mdx +2 -1
  271. package/package.json +14 -20
  272. package/rules.d.ts +31 -4
  273. package/dist/rules/ban-types.js.map +0 -1
  274. package/dist/rules/no-throw-literal.js +0 -97
  275. package/dist/rules/no-throw-literal.js.map +0 -1
  276. package/dist/rules/no-useless-template-literals.js +0 -153
  277. package/dist/rules/no-useless-template-literals.js.map +0 -1
  278. package/docs/rules/ban-types.mdx +0 -133
  279. package/docs/rules/no-throw-literal.mdx +0 -25
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.objectReduceKey = exports.objectMapKey = exports.objectForEachKey = void 0;
3
+ exports.objectForEachKey = objectForEachKey;
4
+ exports.objectMapKey = objectMapKey;
5
+ exports.objectReduceKey = objectReduceKey;
4
6
  function objectForEachKey(obj, callback) {
5
7
  const keys = Object.keys(obj);
6
8
  for (const key of keys) {
7
9
  callback(key);
8
10
  }
9
11
  }
10
- exports.objectForEachKey = objectForEachKey;
11
12
  function objectMapKey(obj, callback) {
12
13
  const values = [];
13
14
  objectForEachKey(obj, key => {
@@ -15,7 +16,6 @@ function objectMapKey(obj, callback) {
15
16
  });
16
17
  return values;
17
18
  }
18
- exports.objectMapKey = objectMapKey;
19
19
  function objectReduceKey(obj, callback, initial) {
20
20
  let accumulator = initial;
21
21
  objectForEachKey(obj, key => {
@@ -23,5 +23,4 @@ function objectReduceKey(obj, callback, initial) {
23
23
  });
24
24
  return accumulator;
25
25
  }
26
- exports.objectReduceKey = objectReduceKey;
27
26
  //# sourceMappingURL=objectIterators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"objectIterators.js","sourceRoot":"","sources":["../../src/util/objectIterators.ts"],"names":[],"mappings":";;;AAAA,SAAS,gBAAgB,CACvB,GAAM,EACN,QAAgC;IAEhC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,QAAQ,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;AACH,CAAC;AAyBQ,4CAAgB;AAvBzB,SAAS,YAAY,CACnB,GAAM,EACN,QAAkC;IAElC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;QAC1B,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAc0B,oCAAY;AAZvC,SAAS,eAAe,CACtB,GAAM,EACN,QAAyD,EACzD,OAAoB;IAEpB,IAAI,WAAW,GAAG,OAAO,CAAC;IAC1B,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;QAC1B,WAAW,GAAG,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,OAAO,WAAW,CAAC;AACrB,CAAC;AAEwC,0CAAe"}
1
+ {"version":3,"file":"objectIterators.js","sourceRoot":"","sources":["../../src/util/objectIterators.ts"],"names":[],"mappings":";;AAiCS,4CAAgB;AAAE,oCAAY;AAAE,0CAAe;AAjCxD,SAAS,gBAAgB,CACvB,GAAM,EACN,QAAgC;IAEhC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,QAAQ,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CACnB,GAAM,EACN,QAAkC;IAElC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;QAC1B,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,eAAe,CACtB,GAAM,EACN,QAAyD,EACzD,OAAoB;IAEpB,IAAI,WAAW,GAAG,OAAO,CAAC;IAC1B,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;QAC1B,WAAW,GAAG,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.referenceContainsTypeQuery = referenceContainsTypeQuery;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ /**
6
+ * Recursively checks whether a given reference has a type query declaration among its parents
7
+ */
8
+ function referenceContainsTypeQuery(node) {
9
+ switch (node.type) {
10
+ case utils_1.AST_NODE_TYPES.TSTypeQuery:
11
+ return true;
12
+ case utils_1.AST_NODE_TYPES.TSQualifiedName:
13
+ case utils_1.AST_NODE_TYPES.Identifier:
14
+ return referenceContainsTypeQuery(node.parent);
15
+ default:
16
+ // if we find a different node, there's no chance that we're in a TSTypeQuery
17
+ return false;
18
+ }
19
+ }
20
+ //# sourceMappingURL=referenceContainsTypeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referenceContainsTypeQuery.js","sourceRoot":"","sources":["../../src/util/referenceContainsTypeQuery.ts"],"names":[],"mappings":";;AAMA,gEAaC;AAlBD,oDAA0D;AAE1D;;GAEG;AACH,SAAgB,0BAA0B,CAAC,IAAmB;IAC5D,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,sBAAc,CAAC,WAAW;YAC7B,OAAO,IAAI,CAAC;QAEd,KAAK,sBAAc,CAAC,eAAe,CAAC;QACpC,KAAK,sBAAc,CAAC,UAAU;YAC5B,OAAO,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEjD;YACE,6EAA6E;YAC7E,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isReferenceToGlobalFunction = isReferenceToGlobalFunction;
4
+ function isReferenceToGlobalFunction(calleeName, node, sourceCode) {
5
+ const ref = sourceCode
6
+ .getScope(node)
7
+ .references.find(ref => ref.identifier.name === calleeName);
8
+ // ensure it's the "global" version
9
+ return !ref?.resolved?.defs.length;
10
+ }
11
+ //# sourceMappingURL=scopeUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopeUtils.js","sourceRoot":"","sources":["../../src/util/scopeUtils.ts"],"names":[],"mappings":";;AAGA,kEAWC;AAXD,SAAgB,2BAA2B,CACzC,UAAkB,EAClB,IAAmB,EACnB,UAAsB;IAEtB,MAAM,GAAG,GAAG,UAAU;SACnB,QAAQ,CAAC,IAAI,CAAC;SACd,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;IAE9D,mCAAmC;IACnC,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC;AACrC,CAAC"}
@@ -42,7 +42,8 @@ const y: readonly string[] = ['a', 'b'];
42
42
 
43
43
  ### `"generic"`
44
44
 
45
- Always use `Array<T>` or `ReadonlyArray<T>` for all array types.
45
+ Always use `Array<T>`, `ReadonlyArray<T>`, or `Readonly<Array<T>>` for all array types.
46
+ `readonly T[]` will be modified to `ReadonlyArray<T>` and `Readonly<T[]>` will be modified to `Readonly<Array<T>`.
46
47
 
47
48
  <Tabs>
48
49
  <TabItem value="❌ Incorrect">
@@ -50,6 +51,7 @@ Always use `Array<T>` or `ReadonlyArray<T>` for all array types.
50
51
  ```ts option='{ "default": "generic" }'
51
52
  const x: string[] = ['a', 'b'];
52
53
  const y: readonly string[] = ['a', 'b'];
54
+ const z: Readonly<string[]> = ['a', 'b'];
53
55
  ```
54
56
 
55
57
  </TabItem>
@@ -58,6 +60,7 @@ const y: readonly string[] = ['a', 'b'];
58
60
  ```ts option='{ "default": "generic" }'
59
61
  const x: Array<string> = ['a', 'b'];
60
62
  const y: ReadonlyArray<string> = ['a', 'b'];
63
+ const z: Readonly<Array<string>> = ['a', 'b'];
61
64
  ```
62
65
 
63
66
  </TabItem>
@@ -0,0 +1,22 @@
1
+ :::danger Deprecated
2
+
3
+ The old `ban-types` rule encompassed multiple areas of functionality, and so has been split into several rules.
4
+
5
+ **[`no-restricted-types`](./no-restricted-types.mdx)** is the new rule for banning a configurable list of type names.
6
+ It has no options enabled by default and is akin to rules like [`no-restricted-globals`](https://eslint.org/docs/latest/rules/no-restricted-globals), [`no-restricted-properties`](https://eslint.org/docs/latest/rules/no-restricted-properties), and [`no-restricted-syntax`](https://eslint.org/docs/latest/rules/no-restricted-syntax).
7
+
8
+ The default options from `ban-types` are now covered by:
9
+
10
+ - **[`no-empty-object-type`](./no-empty-object-type.mdx)**: banning the built-in `{}` type in confusing locations
11
+ - **[`no-unsafe-function-type`](./no-unsafe-function-type.mdx)**: banning the built-in `Function`
12
+ - **[`no-wrapper-object-types`](./no-wrapper-object-types.mdx)**: banning `Object` and built-in class wrappers such as `Number`
13
+
14
+ `ban-types` itself is removed in typescript-eslint v8.
15
+ See [Announcing typescript-eslint v8 Beta](/blog/announcing-typescript-eslint-v8-beta) for more details.
16
+ :::
17
+
18
+ <!-- This doc file has been left on purpose because `ban-types` is a well-known
19
+ rule. This exists to help direct people to the replacement rules.
20
+
21
+ Note that there is no actual way to get to this page in the normal navigation,
22
+ so end-users will only be able to get to this page from the search bar. -->
@@ -31,7 +31,7 @@ const defaultOptions: Options = {
31
31
 
32
32
  ### `ignoreOverrideMethods`
33
33
 
34
- Makes the rule to ignores any class member explicitly marked with `override`.
34
+ Makes the rule ignore any class member explicitly marked with `override`.
35
35
 
36
36
  Example of a correct code when `ignoreOverrideMethods` is set to `true`:
37
37
 
@@ -23,7 +23,7 @@ type Foo = {
23
23
  type Foo = Record<string, unknown>;
24
24
  ```
25
25
 
26
- Keeping to one declaration form consistently improve code readability.
26
+ Using one declaration form consistently improves code readability.
27
27
 
28
28
  ## Options
29
29
 
@@ -583,6 +583,22 @@ This allows you to emulate the old `interface-name-prefix` rule.
583
583
  }
584
584
  ```
585
585
 
586
+ ### Enforce that function names are either in camelCase or PascalCase
587
+
588
+ Function names are typically camelCase, but UI library components (especially JSX, such as React and Solid) use PascalCase to distinguish them from intrinsic elements. If you are writing function components, consider allowing both camelCase and PascalCase for functions.
589
+
590
+ ```json
591
+ {
592
+ "@typescript-eslint/naming-convention": [
593
+ "error",
594
+ {
595
+ "selector": "function",
596
+ "format": ["camelCase", "PascalCase"]
597
+ }
598
+ ]
599
+ }
600
+ ```
601
+
586
602
  ### Enforce that variable and function names are in camelCase
587
603
 
588
604
  This allows you to lint multiple type with same pattern.
@@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
10
10
  > See **https://typescript-eslint.io/rules/no-base-to-string** for documentation.
11
11
 
12
12
  JavaScript will call `toString()` on an object when it is converted to a string, such as when `+` adding to a string or in `${}` template literals.
13
- The default Object `.toString()` returns `"[object Object]"`, which is often not what was intended.
13
+ The default Object `.toString()` uses the format `"[object Object]"`, which is often not what was intended.
14
14
  This rule reports on stringified values that aren't primitives and don't define a more useful `.toString()` method.
15
15
 
16
16
  > Note that `Function` provides its own `.toString()` that returns the function's code.
@@ -23,7 +23,7 @@ For example, given `type A = string` and `type T = string | A`, this rule would
23
23
  ```ts
24
24
  type T1 = 'A' | 'A';
25
25
 
26
- type T2 = A | A | B;
26
+ type T2 = string | string | number;
27
27
 
28
28
  type T3 = { a: string } & { a: string };
29
29
 
@@ -40,7 +40,7 @@ type T5 = StringA | StringB;
40
40
  ```ts
41
41
  type T1 = 'A' | 'B';
42
42
 
43
- type T2 = A | B | C;
43
+ type T2 = string | number | boolean;
44
44
 
45
45
  type T3 = { a: string } & { b: string };
46
46
 
@@ -70,3 +70,7 @@ It can sometimes be useful for the sake of documentation to include aliases for
70
70
  You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
71
71
 
72
72
  > In some of those cases, [branded types](https://basarat.gitbook.io/typescript/main-1/nominaltyping#using-interfaces) might be a type-safe way to represent the underlying data types.
73
+
74
+ ## Related To
75
+
76
+ - [no-redundant-type-constituents](./no-redundant-type-constituents.mdx)
@@ -11,9 +11,13 @@ import TabItem from '@theme/TabItem';
11
11
 
12
12
  Deleting dynamically computed keys can be dangerous and in some cases not well optimized.
13
13
  Using the `delete` operator on keys that aren't runtime constants could be a sign that you're using the wrong data structures.
14
- Using `Object`s with added and removed keys can cause occasional edge case bugs, such as if a key is named `"hasOwnProperty"`.
14
+ Consider using a `Map` or `Set` if you’re using an object as a key-value collection.
15
15
 
16
- > Consider using a `Map` or `Set` if you’re storing collections of objects.
16
+ Dynamically adding and removing keys from objects can cause occasional edge case bugs. For example, some objects use "hidden properties" (such as `__data`) for private storage, and deleting them can break the object's internal state. Furthermore, [`delete`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete) cannot remove inherited properties or non-configurable properties. This makes it interact badly with anything more complicated than a plain object:
17
+
18
+ - The [`length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) of an array is non-configurable, and deleting it is a runtime error.
19
+ - You can't remove properties on the prototype of an object, such as deleting methods from class instances.
20
+ - Sometimes, `delete` only removes the own property, leaving the inherited property intact. For example, deleting the [`name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) property of a function only removes the own property, but there's also a `Function.prototype.name` property that remains.
17
21
 
18
22
  ## Examples
19
23
 
@@ -21,10 +25,6 @@ Using `Object`s with added and removed keys can cause occasional edge case bugs,
21
25
  <TabItem value="❌ Incorrect">
22
26
 
23
27
  ```ts
24
- // Can be replaced with the constant equivalents, such as container.aaa
25
- delete container['aaa'];
26
- delete container['Infinity'];
27
-
28
28
  // Dynamic, difficult-to-reason-about lookups
29
29
  const name = 'name';
30
30
  delete container[name];
@@ -44,7 +44,12 @@ delete container.aaa;
44
44
 
45
45
  // Constants that must be accessed by []
46
46
  delete container[7];
47
- delete container['-Infinity'];
47
+ delete container[-1];
48
+
49
+ // All strings are allowed, to be compatible with the noPropertyAccessFromIndexSignature
50
+ // TS compiler option
51
+ delete container['aaa'];
52
+ delete container['Infinity'];
48
53
  ```
49
54
 
50
55
  </TabItem>
@@ -42,6 +42,8 @@ class HelloWorldLogger {
42
42
  console.log('Hello, world!');
43
43
  }
44
44
  }
45
+
46
+ abstract class Foo {}
45
47
  ```
46
48
 
47
49
  </TabItem>
@@ -57,6 +59,10 @@ export function isProduction() {
57
59
  function logHelloWorld() {
58
60
  console.log('Hello, world!');
59
61
  }
62
+
63
+ abstract class Foo {
64
+ abstract prop: string;
65
+ }
60
66
  ```
61
67
 
62
68
  </TabItem>
@@ -17,6 +17,7 @@ Valid ways of handling a Promise-valued statement include:
17
17
 
18
18
  - `await`ing it
19
19
  - `return`ing it
20
+ - `void`ing it
20
21
  - Calling its `.then()` with two arguments
21
22
  - Calling its `.catch()` with one argument
22
23
 
@@ -63,6 +64,9 @@ await promise;
63
64
  async function returnsPromise() {
64
65
  return 'value';
65
66
  }
67
+
68
+ void returnsPromise();
69
+
66
70
  returnsPromise().then(
67
71
  () => {},
68
72
  () => {},
@@ -80,9 +84,54 @@ await Promise.all([1, 2, 3].map(async x => x + 1));
80
84
 
81
85
  ## Options
82
86
 
87
+ ### `checkThenables`
88
+
89
+ A ["Thenable"](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables) value is an object which has a `then` method, such as a `Promise`.
90
+ Other Thenables include TypeScript's built-in `PromiseLike` interface and any custom object that happens to have a `.then()`.
91
+
92
+ The `checkThenables` option triggers `no-floating-promises` to also consider all values that satisfy the Thenable shape (a `.then()` method that takes two callback parameters), not just Promises.
93
+ This can be useful if your code works with older `Promise` polyfills instead of the native `Promise` class.
94
+
95
+ <Tabs>
96
+ <TabItem value="❌ Incorrect">
97
+
98
+ ```ts option='{"checkThenables": true}'
99
+ declare function createPromiseLike(): PromiseLike<string>;
100
+
101
+ createPromiseLike();
102
+
103
+ interface MyThenable {
104
+ then(onFulfilled: () => void, onRejected: () => void): MyThenable;
105
+ }
106
+
107
+ declare function createMyThenable(): MyThenable;
108
+
109
+ createMyThenable();
110
+ ```
111
+
112
+ </TabItem>
113
+ <TabItem value="✅ Correct">
114
+
115
+ ```ts option='{"checkThenables": true}'
116
+ declare function createPromiseLike(): PromiseLike<string>;
117
+
118
+ await createPromiseLike();
119
+
120
+ interface MyThenable {
121
+ then(onFulfilled: () => void, onRejected: () => void): MyThenable;
122
+ }
123
+
124
+ declare function createMyThenable(): MyThenable;
125
+
126
+ await createMyThenable();
127
+ ```
128
+
129
+ </TabItem>
130
+ </Tabs>
131
+
83
132
  ### `ignoreVoid`
84
133
 
85
- This allows you to stop the rule reporting promises consumed with void operator.
134
+ This option, which is `true` by default, allows you to stop the rule reporting promises consumed with void operator.
86
135
  This can be a good way to explicitly mark a promise as intentionally not awaited.
87
136
 
88
137
  Examples of **correct** code for this rule with `{ ignoreVoid: true }`:
@@ -100,7 +149,7 @@ With this option set to `true`, and if you are using `no-void`, you should turn
100
149
 
101
150
  ### `ignoreIIFE`
102
151
 
103
- This allows you to skip checking of async IIFEs (Immediately Invoked function Expressions).
152
+ This allows you to skip checking of async IIFEs (Immediately Invoked Function Expressions).
104
153
 
105
154
  Examples of **correct** code for this rule with `{ ignoreIIFE: true }`:
106
155
 
@@ -115,6 +164,101 @@ await (async function () {
115
164
  })();
116
165
  ```
117
166
 
167
+ ### `allowForKnownSafePromises`
168
+
169
+ This option allows marking specific types as "safe" to be floating. For example, you may need to do this in the case of libraries whose APIs return Promises whose rejections are safely handled by the library.
170
+
171
+ This option takes an array of type specifiers to consider safe.
172
+ Each item in the array must have one of the following forms:
173
+
174
+ - A type defined in a file (`{ from: "file", name: "Foo", path: "src/foo-file.ts" }` with `path` being an optional path relative to the project root directory)
175
+ - A type from the default library (`{ from: "lib", name: "PromiseLike" }`)
176
+ - A type from a package (`{ from: "package", name: "Foo", package: "foo-lib" }`, this also works for types defined in a typings package).
177
+
178
+ Examples of code for this rule with:
179
+
180
+ ```json
181
+ {
182
+ "allowForKnownSafePromises": [
183
+ { "from": "file", "name": "SafePromise" },
184
+ { "from": "lib", "name": "PromiseLike" },
185
+ { "from": "package", "name": "Bar", "package": "bar-lib" }
186
+ ]
187
+ }
188
+ ```
189
+
190
+ <Tabs>
191
+ <TabItem value="❌ Incorrect">
192
+
193
+ ```ts option='{"allowForKnownSafePromises":[{"from":"file","name":"SafePromise"},{"from":"lib","name":"PromiseLike"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
194
+ let promise: Promise<number> = Promise.resolve(2);
195
+ promise;
196
+
197
+ function returnsPromise(): Promise<number> {
198
+ return Promise.resolve(42);
199
+ }
200
+
201
+ returnsPromise();
202
+ ```
203
+
204
+ </TabItem>
205
+ <TabItem value="✅ Correct">
206
+
207
+ ```ts option='{"allowForKnownSafePromises":[{"from":"file","name":"SafePromise"},{"from":"lib","name":"PromiseLike"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
208
+ // promises can be marked as safe by using branded types
209
+ type SafePromise = Promise<number> & { __linterBrands?: string };
210
+
211
+ let promise: SafePromise = Promise.resolve(2);
212
+ promise;
213
+
214
+ function returnsSafePromise(): SafePromise {
215
+ return Promise.resolve(42);
216
+ }
217
+
218
+ returnsSafePromise();
219
+ ```
220
+
221
+ </TabItem>
222
+ </Tabs>
223
+
224
+ ### `allowForKnownSafeCalls`
225
+
226
+ This option allows marking specific functions as "safe" to be called to create floating Promises.
227
+ For example, you may need to do this in the case of libraries whose APIs may be called without handling the resultant Promises.
228
+
229
+ This option takes the same array format as [`allowForKnownSafePromises`](#allowForKnownSafePromises).
230
+
231
+ Examples of code for this rule with:
232
+
233
+ ```json
234
+ {
235
+ "allowForKnownSafeCalls": [
236
+ { "from": "file", "name": "safe", "path": "input.ts" }
237
+ ]
238
+ }
239
+ ```
240
+
241
+ <Tabs>
242
+ <TabItem value="❌ Incorrect">
243
+
244
+ ```ts option='{"allowForKnownSafeCalls":[{"from":"file","name":"safe","path":"input.ts"}]}'
245
+ declare function unsafe(...args: unknown[]): Promise<void>;
246
+
247
+ unsafe('...', () => {});
248
+ ```
249
+
250
+ </TabItem>
251
+ <TabItem value="✅ Correct">
252
+
253
+ ```ts option='{"allowForKnownSafeCalls":[{"from":"file","name":"safe","path":"input.ts"}]}' skipValidation
254
+ declare function safe(...args: unknown[]): Promise<void>;
255
+
256
+ safe('...', () => {});
257
+ ```
258
+
259
+ </TabItem>
260
+ </Tabs>
261
+
118
262
  ## When Not To Use It
119
263
 
120
264
  This rule can be difficult to enable on large existing projects that set up many floating Promises.
@@ -127,19 +127,18 @@ Examples of code for this rule with `checksVoidReturn: true`:
127
127
 
128
128
  ```ts option='{ "checksVoidReturn": true }'
129
129
  [1, 2, 3].forEach(async value => {
130
- await doSomething(value);
130
+ await fetch(`/${value}`);
131
131
  });
132
132
 
133
- new Promise(async (resolve, reject) => {
134
- await doSomething();
133
+ new Promise<void>(async (resolve, reject) => {
134
+ await fetch('/');
135
135
  resolve();
136
136
  });
137
137
 
138
- const eventEmitter = new EventEmitter();
139
- eventEmitter.on('some-event', async () => {
140
- synchronousCall();
141
- await doSomething();
142
- otherSynchronousCall();
138
+ document.addEventListener('click', async () => {
139
+ console.log('synchronous call');
140
+ await fetch('/');
141
+ console.log('synchronous call');
143
142
  });
144
143
  ```
145
144
 
@@ -169,8 +168,7 @@ new Promise((resolve, reject) => {
169
168
  });
170
169
 
171
170
  // Name the async wrapper to call it later
172
- const eventEmitter = new EventEmitter();
173
- eventEmitter.on('some-event', () => {
171
+ document.addEventListener('click', () => {
174
172
  const handler = async () => {
175
173
  await doSomething();
176
174
  otherSynchronousCall();
@@ -210,30 +208,30 @@ Examples of code for this rule with `checksSpreads: true`:
210
208
  <TabItem value="❌ Incorrect">
211
209
 
212
210
  ```ts option='{ "checksSpreads": true }'
213
- const getData = () => someAsyncOperation({ myArg: 'foo' });
211
+ const getData = () => fetch('/');
214
212
 
215
- return { foo: 42, ...getData() };
213
+ console.log({ foo: 42, ...getData() });
216
214
 
217
- const getData2 = async () => {
218
- await someAsyncOperation({ myArg: 'foo' });
215
+ const awaitData = async () => {
216
+ await fetch('/');
219
217
  };
220
218
 
221
- return { foo: 42, ...getData2() };
219
+ console.log({ foo: 42, ...awaitData() });
222
220
  ```
223
221
 
224
222
  </TabItem>
225
223
  <TabItem value="✅ Correct">
226
224
 
227
225
  ```ts option='{ "checksSpreads": true }'
228
- const getData = () => someAsyncOperation({ myArg: 'foo' });
226
+ const getData = () => fetch('/');
229
227
 
230
- return { foo: 42, ...(await getData()) };
228
+ console.log({ foo: 42, ...(await getData()) });
231
229
 
232
- const getData2 = async () => {
233
- await someAsyncOperation({ myArg: 'foo' });
230
+ const awaitData = async () => {
231
+ await fetch('/');
234
232
  };
235
233
 
236
- return { foo: 42, ...(await getData2()) };
234
+ console.log({ foo: 42, ...(await awaitData()) });
237
235
  ```
238
236
 
239
237
  </TabItem>
@@ -96,3 +96,7 @@ If you strongly feel a preference for these unnecessary type constituents, this
96
96
  - [Intersection Types](https://www.typescriptlang.org/docs/handbook/2/objects.html#intersection-types)
97
97
  - [Bottom Types](https://en.wikipedia.org/wiki/Bottom_type)
98
98
  - [Top Types](https://en.wikipedia.org/wiki/Top_type)
99
+
100
+ ## Related To
101
+
102
+ - [no-duplicate-type-constituents](./no-duplicate-type-constituents.mdx)
@@ -38,7 +38,7 @@ import * as lib3 from 'lib3';
38
38
 
39
39
  ### `allow`
40
40
 
41
- A array of strings. These strings will be compiled into regular expressions with the `u` flag and be used to test against the imported path. A common use case is to allow importing `package.json`. This is because `package.json` commonly lives outside of the TS root directory, so statically importing it would lead to root directory conflicts, especially with `resolveJsonModule` enabled. You can also use it to allow importing any JSON if your environment doesn't support JSON modules, or use it for other cases where `import` statements cannot work.
41
+ An array of strings. These strings will be compiled into regular expressions with the `u` flag and be used to test against the imported path. A common use case is to allow importing `package.json`. This is because `package.json` commonly lives outside of the TS root directory, so statically importing it would lead to root directory conflicts, especially with `resolveJsonModule` enabled. You can also use it to allow importing any JSON if your environment doesn't support JSON modules, or use it for other cases where `import` statements cannot work.
42
42
 
43
43
  With `{allow: ['/package\\.json$']}`:
44
44
 
@@ -59,6 +59,33 @@ console.log(require('../package.json').version);
59
59
  </TabItem>
60
60
  </Tabs>
61
61
 
62
+ ### `allowAsImport`
63
+
64
+ When set to `true`, the `import x = require(...)` declaration won't be reported.
65
+ This is useful if you use certain module options that require strict CommonJS interop semantics.
66
+
67
+ With `{allowAsImport: true}`:
68
+
69
+ <Tabs>
70
+ <TabItem value="❌ Incorrect">
71
+
72
+ ```ts option='{ "allowAsImport": true }'
73
+ var foo = require('foo');
74
+ const foo = require('foo');
75
+ let foo = require('foo');
76
+ ```
77
+
78
+ </TabItem>
79
+ <TabItem value="✅ Correct">
80
+
81
+ ```ts option='{ "allowAsImport": true }'
82
+ import foo = require('foo');
83
+ import foo from 'foo';
84
+ ```
85
+
86
+ </TabItem>
87
+ </Tabs>
88
+
62
89
  ## When Not To Use It
63
90
 
64
91
  If your project frequently uses older CommonJS `require`s, then this rule might not be applicable to you.
@@ -0,0 +1,71 @@
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/no-restricted-types** for documentation.
11
+
12
+ It can sometimes be useful to ban specific types from being used in type annotations.
13
+ For example, a project might be migrating from using one type to another, and want to ban references to the old type.
14
+
15
+ This rule can be configured to ban a list of specific types and can suggest alternatives.
16
+ Note that it does not ban the corresponding runtime objects from being used.
17
+
18
+ ## Options
19
+
20
+ ### `types`
21
+
22
+ An object whose keys are the types you want to ban, and the values are error messages.
23
+
24
+ The type can either be a type name literal (`OldType`) or a a type name with generic parameter instantiation(s) (`OldType<MyArgument>`).
25
+
26
+ The values can be:
27
+
28
+ - A string, which is the error message to be reported; or
29
+ - `false` to specifically un-ban this type (useful when you are using `extendDefaults`); or
30
+ - An object with the following properties:
31
+ - `message: string`: the message to display when the type is matched.
32
+ - `fixWith?: string`: a string to replace the banned type with when the fixer is run. If this is omitted, no fix will be done.
33
+ - `suggest?: string[]`: a list of suggested replacements for the banned type.
34
+
35
+ Example configuration:
36
+
37
+ ```jsonc
38
+ {
39
+ "@typescript-eslint/no-restricted-types": [
40
+ "error",
41
+ {
42
+ "types": {
43
+ // add a custom message to help explain why not to use it
44
+ "OldType": "Don't use OldType because it is unsafe",
45
+
46
+ // add a custom message, and tell the plugin how to fix it
47
+ "OldAPI": {
48
+ "message": "Use NewAPI instead",
49
+ "fixWith": "NewAPI",
50
+ },
51
+
52
+ // add a custom message, and tell the plugin how to suggest a fix
53
+ "SoonToBeOldAPI": {
54
+ "message": "Use NewAPI instead",
55
+ "suggest": ["NewAPIOne", "NewAPITwo"],
56
+ },
57
+ },
58
+ },
59
+ ],
60
+ }
61
+ ```
62
+
63
+ ## When Not To Use It
64
+
65
+ If you have no need to ban specific types from being used in type annotations, you don't need this rule.
66
+
67
+ ## Related To
68
+
69
+ - [`no-empty-object-type`](./no-empty-object-type.mdx)
70
+ - [`no-unsafe-function-type`](./no-unsafe-function-type.mdx)
71
+ - [`no-wrapper-object-types`](./no-wrapper-object-types.mdx)