@depup/typescript-eslint__eslint-plugin 8.57.1-depup.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 (461) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/changes.json +5 -0
  4. package/dist/configs/eslint-recommended-raw.d.ts +10 -0
  5. package/dist/configs/eslint-recommended-raw.js +46 -0
  6. package/dist/configs/eslintrc/all.d.ts +159 -0
  7. package/dist/configs/eslintrc/all.js +165 -0
  8. package/dist/configs/eslintrc/base.d.ts +8 -0
  9. package/dist/configs/eslintrc/base.js +6 -0
  10. package/dist/configs/eslintrc/disable-type-checked.d.ts +71 -0
  11. package/dist/configs/eslintrc/disable-type-checked.js +73 -0
  12. package/dist/configs/eslintrc/eslint-recommended.d.ts +12 -0
  13. package/dist/configs/eslintrc/eslint-recommended.js +13 -0
  14. package/dist/configs/eslintrc/recommended-type-checked-only.d.ts +33 -0
  15. package/dist/configs/eslintrc/recommended-type-checked-only.js +39 -0
  16. package/dist/configs/eslintrc/recommended-type-checked.d.ts +56 -0
  17. package/dist/configs/eslintrc/recommended-type-checked.js +62 -0
  18. package/dist/configs/eslintrc/recommended.d.ts +29 -0
  19. package/dist/configs/eslintrc/recommended.js +35 -0
  20. package/dist/configs/eslintrc/strict-type-checked-only.d.ts +64 -0
  21. package/dist/configs/eslintrc/strict-type-checked-only.js +79 -0
  22. package/dist/configs/eslintrc/strict-type-checked.d.ts +98 -0
  23. package/dist/configs/eslintrc/strict-type-checked.js +114 -0
  24. package/dist/configs/eslintrc/strict.d.ts +40 -0
  25. package/dist/configs/eslintrc/strict.js +47 -0
  26. package/dist/configs/eslintrc/stylistic-type-checked-only.d.ts +15 -0
  27. package/dist/configs/eslintrc/stylistic-type-checked-only.js +21 -0
  28. package/dist/configs/eslintrc/stylistic-type-checked.d.ts +29 -0
  29. package/dist/configs/eslintrc/stylistic-type-checked.js +35 -0
  30. package/dist/configs/eslintrc/stylistic.d.ts +20 -0
  31. package/dist/configs/eslintrc/stylistic.js +26 -0
  32. package/dist/configs/flat/all.d.ts +7 -0
  33. package/dist/configs/flat/all.js +179 -0
  34. package/dist/configs/flat/base.d.ts +8 -0
  35. package/dist/configs/flat/base.js +17 -0
  36. package/dist/configs/flat/disable-type-checked.d.ts +7 -0
  37. package/dist/configs/flat/disable-type-checked.js +81 -0
  38. package/dist/configs/flat/eslint-recommended.d.ts +9 -0
  39. package/dist/configs/flat/eslint-recommended.js +16 -0
  40. package/dist/configs/flat/recommended-type-checked-only.d.ts +7 -0
  41. package/dist/configs/flat/recommended-type-checked-only.js +53 -0
  42. package/dist/configs/flat/recommended-type-checked.d.ts +7 -0
  43. package/dist/configs/flat/recommended-type-checked.js +76 -0
  44. package/dist/configs/flat/recommended.d.ts +7 -0
  45. package/dist/configs/flat/recommended.js +49 -0
  46. package/dist/configs/flat/strict-type-checked-only.d.ts +7 -0
  47. package/dist/configs/flat/strict-type-checked-only.js +93 -0
  48. package/dist/configs/flat/strict-type-checked.d.ts +7 -0
  49. package/dist/configs/flat/strict-type-checked.js +128 -0
  50. package/dist/configs/flat/strict.d.ts +7 -0
  51. package/dist/configs/flat/strict.js +61 -0
  52. package/dist/configs/flat/stylistic-type-checked-only.d.ts +7 -0
  53. package/dist/configs/flat/stylistic-type-checked-only.js +35 -0
  54. package/dist/configs/flat/stylistic-type-checked.d.ts +7 -0
  55. package/dist/configs/flat/stylistic-type-checked.js +49 -0
  56. package/dist/configs/flat/stylistic.d.ts +7 -0
  57. package/dist/configs/flat/stylistic.js +40 -0
  58. package/dist/index.d.ts +1128 -0
  59. package/dist/index.js +6 -0
  60. package/dist/raw-plugin.d.ts +1152 -0
  61. package/dist/raw-plugin.js +122 -0
  62. package/dist/rules/adjacent-overload-signatures.d.ts +4 -0
  63. package/dist/rules/adjacent-overload-signatures.js +124 -0
  64. package/dist/rules/array-type.d.ts +12 -0
  65. package/dist/rules/array-type.js +232 -0
  66. package/dist/rules/await-thenable.d.ts +6 -0
  67. package/dist/rules/await-thenable.js +228 -0
  68. package/dist/rules/ban-ts-comment.d.ts +17 -0
  69. package/dist/rules/ban-ts-comment.js +195 -0
  70. package/dist/rules/ban-tslint-comment.d.ts +4 -0
  71. package/dist/rules/ban-tslint-comment.js +53 -0
  72. package/dist/rules/class-literal-property-style.d.ts +7 -0
  73. package/dist/rules/class-literal-property-style.js +160 -0
  74. package/dist/rules/class-methods-use-this.d.ts +13 -0
  75. package/dist/rules/class-methods-use-this.js +219 -0
  76. package/dist/rules/consistent-generic-constructors.d.ts +6 -0
  77. package/dist/rules/consistent-generic-constructors.js +126 -0
  78. package/dist/rules/consistent-indexed-object-style.d.ts +7 -0
  79. package/dist/rules/consistent-indexed-object-style.js +256 -0
  80. package/dist/rules/consistent-return.d.ts +18 -0
  81. package/dist/rules/consistent-return.js +135 -0
  82. package/dist/rules/consistent-type-assertions.d.ts +14 -0
  83. package/dist/rules/consistent-type-assertions.js +256 -0
  84. package/dist/rules/consistent-type-definitions.d.ts +5 -0
  85. package/dist/rules/consistent-type-definitions.js +100 -0
  86. package/dist/rules/consistent-type-exports.d.ts +11 -0
  87. package/dist/rules/consistent-type-exports.js +335 -0
  88. package/dist/rules/consistent-type-imports.d.ts +15 -0
  89. package/dist/rules/consistent-type-imports.js +608 -0
  90. package/dist/rules/default-param-last.d.ts +4 -0
  91. package/dist/rules/default-param-last.js +68 -0
  92. package/dist/rules/dot-notation.d.ts +23 -0
  93. package/dist/rules/dot-notation.js +139 -0
  94. package/dist/rules/enum-utils/shared.d.ts +36 -0
  95. package/dist/rules/enum-utils/shared.js +121 -0
  96. package/dist/rules/explicit-function-return-type.d.ts +17 -0
  97. package/dist/rules/explicit-function-return-type.js +179 -0
  98. package/dist/rules/explicit-member-accessibility.d.ts +19 -0
  99. package/dist/rules/explicit-member-accessibility.js +299 -0
  100. package/dist/rules/explicit-module-boundary-types.d.ts +15 -0
  101. package/dist/rules/explicit-module-boundary-types.js +386 -0
  102. package/dist/rules/index.d.ts +448 -0
  103. package/dist/rules/index.js +275 -0
  104. package/dist/rules/init-declarations.d.ts +15 -0
  105. package/dist/rules/init-declarations.js +105 -0
  106. package/dist/rules/max-params.d.ts +25 -0
  107. package/dist/rules/max-params.js +72 -0
  108. package/dist/rules/member-ordering.d.ts +33 -0
  109. package/dist/rules/member-ordering.js +833 -0
  110. package/dist/rules/method-signature-style.d.ts +6 -0
  111. package/dist/rules/method-signature-style.js +186 -0
  112. package/dist/rules/naming-convention-utils/enums.d.ts +79 -0
  113. package/dist/rules/naming-convention-utils/enums.js +102 -0
  114. package/dist/rules/naming-convention-utils/format.d.ts +2 -0
  115. package/dist/rules/naming-convention-utils/format.js +89 -0
  116. package/dist/rules/naming-convention-utils/index.d.ts +6 -0
  117. package/dist/rules/naming-convention-utils/index.js +11 -0
  118. package/dist/rules/naming-convention-utils/parse-options.d.ts +2 -0
  119. package/dist/rules/naming-convention-utils/parse-options.js +69 -0
  120. package/dist/rules/naming-convention-utils/schema.d.ts +2 -0
  121. package/dist/rules/naming-convention-utils/schema.js +305 -0
  122. package/dist/rules/naming-convention-utils/shared.d.ts +5 -0
  123. package/dist/rules/naming-convention-utils/shared.js +16 -0
  124. package/dist/rules/naming-convention-utils/types.d.ts +39 -0
  125. package/dist/rules/naming-convention-utils/types.js +2 -0
  126. package/dist/rules/naming-convention-utils/validator.d.ts +3 -0
  127. package/dist/rules/naming-convention-utils/validator.js +349 -0
  128. package/dist/rules/naming-convention.d.ts +8 -0
  129. package/dist/rules/naming-convention.js +505 -0
  130. package/dist/rules/no-array-constructor.d.ts +4 -0
  131. package/dist/rules/no-array-constructor.js +62 -0
  132. package/dist/rules/no-array-delete.d.ts +6 -0
  133. package/dist/rules/no-array-delete.js +80 -0
  134. package/dist/rules/no-base-to-string.d.ts +11 -0
  135. package/dist/rules/no-base-to-string.js +324 -0
  136. package/dist/rules/no-confusing-non-null-assertion.d.ts +6 -0
  137. package/dist/rules/no-confusing-non-null-assertion.js +142 -0
  138. package/dist/rules/no-confusing-void-expression.d.ts +13 -0
  139. package/dist/rules/no-confusing-void-expression.js +357 -0
  140. package/dist/rules/no-deprecated.d.ts +11 -0
  141. package/dist/rules/no-deprecated.js +402 -0
  142. package/dist/rules/no-dupe-class-members.d.ts +14 -0
  143. package/dist/rules/no-dupe-class-members.js +39 -0
  144. package/dist/rules/no-duplicate-enum-values.d.ts +4 -0
  145. package/dist/rules/no-duplicate-enum-values.js +83 -0
  146. package/dist/rules/no-duplicate-type-constituents.d.ts +11 -0
  147. package/dist/rules/no-duplicate-type-constituents.js +219 -0
  148. package/dist/rules/no-dynamic-delete.d.ts +4 -0
  149. package/dist/rules/no-dynamic-delete.js +42 -0
  150. package/dist/rules/no-empty-function.d.ts +16 -0
  151. package/dist/rules/no-empty-function.js +134 -0
  152. package/dist/rules/no-empty-interface.d.ts +11 -0
  153. package/dist/rules/no-empty-interface.js +102 -0
  154. package/dist/rules/no-empty-object-type.d.ts +15 -0
  155. package/dist/rules/no-empty-object-type.js +143 -0
  156. package/dist/rules/no-explicit-any.d.ts +12 -0
  157. package/dist/rules/no-explicit-any.js +197 -0
  158. package/dist/rules/no-extra-non-null-assertion.d.ts +4 -0
  159. package/dist/rules/no-extra-non-null-assertion.js +35 -0
  160. package/dist/rules/no-extraneous-class.d.ts +13 -0
  161. package/dist/rules/no-extraneous-class.js +120 -0
  162. package/dist/rules/no-floating-promises.d.ts +16 -0
  163. package/dist/rules/no-floating-promises.js +365 -0
  164. package/dist/rules/no-for-in-array.d.ts +4 -0
  165. package/dist/rules/no-for-in-array.js +86 -0
  166. package/dist/rules/no-implied-eval.d.ts +4 -0
  167. package/dist/rules/no-implied-eval.js +152 -0
  168. package/dist/rules/no-import-type-side-effects.d.ts +7 -0
  169. package/dist/rules/no-import-type-side-effects.js +53 -0
  170. package/dist/rules/no-inferrable-types.d.ts +11 -0
  171. package/dist/rules/no-inferrable-types.js +182 -0
  172. package/dist/rules/no-invalid-this.d.ts +15 -0
  173. package/dist/rules/no-invalid-this.js +75 -0
  174. package/dist/rules/no-invalid-void-type.d.ts +9 -0
  175. package/dist/rules/no-invalid-void-type.js +210 -0
  176. package/dist/rules/no-loop-func.d.ts +13 -0
  177. package/dist/rules/no-loop-func.js +187 -0
  178. package/dist/rules/no-loss-of-precision.d.ts +9 -0
  179. package/dist/rules/no-loss-of-precision.js +35 -0
  180. package/dist/rules/no-magic-numbers.d.ts +29 -0
  181. package/dist/rules/no-magic-numbers.js +248 -0
  182. package/dist/rules/no-meaningless-void-operator.d.ts +10 -0
  183. package/dist/rules/no-meaningless-void-operator.js +102 -0
  184. package/dist/rules/no-misused-new.d.ts +4 -0
  185. package/dist/rules/no-misused-new.js +81 -0
  186. package/dist/rules/no-misused-promises.d.ts +21 -0
  187. package/dist/rules/no-misused-promises.js +765 -0
  188. package/dist/rules/no-misused-spread.d.ts +12 -0
  189. package/dist/rules/no-misused-spread.js +260 -0
  190. package/dist/rules/no-mixed-enums.d.ts +4 -0
  191. package/dist/rules/no-mixed-enums.js +200 -0
  192. package/dist/rules/no-namespace.d.ts +11 -0
  193. package/dist/rules/no-namespace.js +60 -0
  194. package/dist/rules/no-non-null-asserted-nullish-coalescing.d.ts +5 -0
  195. package/dist/rules/no-non-null-asserted-nullish-coalescing.js +73 -0
  196. package/dist/rules/no-non-null-asserted-optional-chain.d.ts +5 -0
  197. package/dist/rules/no-non-null-asserted-optional-chain.js +65 -0
  198. package/dist/rules/no-non-null-assertion.d.ts +6 -0
  199. package/dist/rules/no-non-null-assertion.js +93 -0
  200. package/dist/rules/no-redeclare.d.ts +12 -0
  201. package/dist/rules/no-redeclare.js +199 -0
  202. package/dist/rules/no-redundant-type-constituents.d.ts +4 -0
  203. package/dist/rules/no-redundant-type-constituents.js +431 -0
  204. package/dist/rules/no-require-imports.d.ts +11 -0
  205. package/dist/rules/no-require-imports.js +115 -0
  206. package/dist/rules/no-restricted-imports.d.ts +9 -0
  207. package/dist/rules/no-restricted-imports.js +243 -0
  208. package/dist/rules/no-restricted-types.d.ts +16 -0
  209. package/dist/rules/no-restricted-types.js +165 -0
  210. package/dist/rules/no-shadow.d.ts +16 -0
  211. package/dist/rules/no-shadow.js +521 -0
  212. package/dist/rules/no-this-alias.d.ts +11 -0
  213. package/dist/rules/no-this-alias.js +66 -0
  214. package/dist/rules/no-type-alias.d.ts +18 -0
  215. package/dist/rules/no-type-alias.js +268 -0
  216. package/dist/rules/no-unnecessary-boolean-literal-compare.d.ts +12 -0
  217. package/dist/rules/no-unnecessary-boolean-literal-compare.js +263 -0
  218. package/dist/rules/no-unnecessary-condition.d.ts +14 -0
  219. package/dist/rules/no-unnecessary-condition.js +675 -0
  220. package/dist/rules/no-unnecessary-parameter-property-assignment.d.ts +4 -0
  221. package/dist/rules/no-unnecessary-parameter-property-assignment.js +148 -0
  222. package/dist/rules/no-unnecessary-qualifier.d.ts +4 -0
  223. package/dist/rules/no-unnecessary-qualifier.js +156 -0
  224. package/dist/rules/no-unnecessary-template-expression.d.ts +6 -0
  225. package/dist/rules/no-unnecessary-template-expression.js +361 -0
  226. package/dist/rules/no-unnecessary-type-arguments.d.ts +5 -0
  227. package/dist/rules/no-unnecessary-type-arguments.js +197 -0
  228. package/dist/rules/no-unnecessary-type-assertion.d.ts +11 -0
  229. package/dist/rules/no-unnecessary-type-assertion.js +353 -0
  230. package/dist/rules/no-unnecessary-type-constraint.d.ts +5 -0
  231. package/dist/rules/no-unnecessary-type-constraint.js +119 -0
  232. package/dist/rules/no-unnecessary-type-conversion.d.ts +5 -0
  233. package/dist/rules/no-unnecessary-type-conversion.js +356 -0
  234. package/dist/rules/no-unnecessary-type-parameters.d.ts +5 -0
  235. package/dist/rules/no-unnecessary-type-parameters.js +422 -0
  236. package/dist/rules/no-unsafe-argument.d.ts +5 -0
  237. package/dist/rules/no-unsafe-argument.js +272 -0
  238. package/dist/rules/no-unsafe-assignment.d.ts +4 -0
  239. package/dist/rules/no-unsafe-assignment.js +322 -0
  240. package/dist/rules/no-unsafe-call.d.ts +5 -0
  241. package/dist/rules/no-unsafe-call.js +136 -0
  242. package/dist/rules/no-unsafe-declaration-merging.d.ts +4 -0
  243. package/dist/rules/no-unsafe-declaration-merging.js +54 -0
  244. package/dist/rules/no-unsafe-enum-comparison.d.ts +5 -0
  245. package/dist/rules/no-unsafe-enum-comparison.js +192 -0
  246. package/dist/rules/no-unsafe-function-type.d.ts +4 -0
  247. package/dist/rules/no-unsafe-function-type.js +45 -0
  248. package/dist/rules/no-unsafe-member-access.d.ts +10 -0
  249. package/dist/rules/no-unsafe-member-access.js +183 -0
  250. package/dist/rules/no-unsafe-return.d.ts +4 -0
  251. package/dist/rules/no-unsafe-return.js +183 -0
  252. package/dist/rules/no-unsafe-type-assertion.d.ts +4 -0
  253. package/dist/rules/no-unsafe-type-assertion.js +158 -0
  254. package/dist/rules/no-unsafe-unary-minus.d.ts +6 -0
  255. package/dist/rules/no-unsafe-unary-minus.js +78 -0
  256. package/dist/rules/no-unused-expressions.d.ts +19 -0
  257. package/dist/rules/no-unused-expressions.js +64 -0
  258. package/dist/rules/no-unused-private-class-members.d.ts +6 -0
  259. package/dist/rules/no-unused-private-class-members.js +44 -0
  260. package/dist/rules/no-unused-vars.d.ts +24 -0
  261. package/dist/rules/no-unused-vars.js +1033 -0
  262. package/dist/rules/no-use-before-define.d.ts +16 -0
  263. package/dist/rules/no-use-before-define.js +303 -0
  264. package/dist/rules/no-useless-constructor.d.ts +11 -0
  265. package/dist/rules/no-useless-constructor.js +57 -0
  266. package/dist/rules/no-useless-default-assignment.d.ts +11 -0
  267. package/dist/rules/no-useless-default-assignment.js +318 -0
  268. package/dist/rules/no-useless-empty-export.d.ts +4 -0
  269. package/dist/rules/no-useless-empty-export.js +70 -0
  270. package/dist/rules/no-var-requires.d.ts +10 -0
  271. package/dist/rules/no-var-requires.js +83 -0
  272. package/dist/rules/no-wrapper-object-types.d.ts +5 -0
  273. package/dist/rules/no-wrapper-object-types.js +60 -0
  274. package/dist/rules/non-nullable-type-assertion-style.d.ts +4 -0
  275. package/dist/rules/non-nullable-type-assertion-style.js +132 -0
  276. package/dist/rules/only-throw-error.d.ts +14 -0
  277. package/dist/rules/only-throw-error.js +158 -0
  278. package/dist/rules/parameter-properties.d.ts +13 -0
  279. package/dist/rules/parameter-properties.js +164 -0
  280. package/dist/rules/prefer-as-const.d.ts +5 -0
  281. package/dist/rules/prefer-as-const.js +72 -0
  282. package/dist/rules/prefer-destructuring.d.ts +19 -0
  283. package/dist/rules/prefer-destructuring.js +216 -0
  284. package/dist/rules/prefer-enum-initializers.d.ts +6 -0
  285. package/dist/rules/prefer-enum-initializers.js +62 -0
  286. package/dist/rules/prefer-find.d.ts +5 -0
  287. package/dist/rules/prefer-find.js +247 -0
  288. package/dist/rules/prefer-for-of.d.ts +5 -0
  289. package/dist/rules/prefer-for-of.js +115 -0
  290. package/dist/rules/prefer-function-type.d.ts +9 -0
  291. package/dist/rules/prefer-function-type.js +186 -0
  292. package/dist/rules/prefer-includes.d.ts +5 -0
  293. package/dist/rules/prefer-includes.js +242 -0
  294. package/dist/rules/prefer-literal-enum-member.d.ts +6 -0
  295. package/dist/rules/prefer-literal-enum-member.js +116 -0
  296. package/dist/rules/prefer-namespace-keyword.d.ts +4 -0
  297. package/dist/rules/prefer-namespace-keyword.js +42 -0
  298. package/dist/rules/prefer-nullish-coalescing.d.ts +22 -0
  299. package/dist/rules/prefer-nullish-coalescing.js +647 -0
  300. package/dist/rules/prefer-optional-chain-utils/PreferOptionalChainOptions.d.ts +11 -0
  301. package/dist/rules/prefer-optional-chain-utils/PreferOptionalChainOptions.js +2 -0
  302. package/dist/rules/prefer-optional-chain-utils/analyzeChain.d.ts +7 -0
  303. package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +569 -0
  304. package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.d.ts +6 -0
  305. package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js +45 -0
  306. package/dist/rules/prefer-optional-chain-utils/compareNodes.d.ts +15 -0
  307. package/dist/rules/prefer-optional-chain-utils/compareNodes.js +326 -0
  308. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.d.ts +61 -0
  309. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +411 -0
  310. package/dist/rules/prefer-optional-chain.d.ts +5 -0
  311. package/dist/rules/prefer-optional-chain.js +150 -0
  312. package/dist/rules/prefer-promise-reject-errors.d.ts +14 -0
  313. package/dist/rules/prefer-promise-reject-errors.js +124 -0
  314. package/dist/rules/prefer-readonly-parameter-types.d.ts +14 -0
  315. package/dist/rules/prefer-readonly-parameter-types.js +89 -0
  316. package/dist/rules/prefer-readonly.d.ts +10 -0
  317. package/dist/rules/prefer-readonly.js +439 -0
  318. package/dist/rules/prefer-reduce-type-parameter.d.ts +4 -0
  319. package/dist/rules/prefer-reduce-type-parameter.js +114 -0
  320. package/dist/rules/prefer-regexp-exec.d.ts +4 -0
  321. package/dist/rules/prefer-regexp-exec.js +178 -0
  322. package/dist/rules/prefer-return-this-type.d.ts +4 -0
  323. package/dist/rules/prefer-return-this-type.js +154 -0
  324. package/dist/rules/prefer-string-starts-ends-with.d.ts +12 -0
  325. package/dist/rules/prefer-string-starts-ends-with.js +512 -0
  326. package/dist/rules/prefer-ts-expect-error.d.ts +5 -0
  327. package/dist/rules/prefer-ts-expect-error.js +71 -0
  328. package/dist/rules/promise-function-async.d.ts +15 -0
  329. package/dist/rules/promise-function-async.js +204 -0
  330. package/dist/rules/related-getter-setter-pairs.d.ts +4 -0
  331. package/dist/rules/related-getter-setter-pairs.js +71 -0
  332. package/dist/rules/require-array-sort-compare.d.ts +10 -0
  333. package/dist/rules/require-array-sort-compare.js +63 -0
  334. package/dist/rules/require-await.d.ts +4 -0
  335. package/dist/rules/require-await.js +263 -0
  336. package/dist/rules/restrict-plus-operands.d.ts +15 -0
  337. package/dist/rules/restrict-plus-operands.js +231 -0
  338. package/dist/rules/restrict-template-expressions.d.ts +19 -0
  339. package/dist/rules/restrict-template-expressions.js +119 -0
  340. package/dist/rules/return-await.d.ts +5 -0
  341. package/dist/rules/return-await.js +363 -0
  342. package/dist/rules/sort-type-constituents.d.ts +14 -0
  343. package/dist/rules/sort-type-constituents.js +272 -0
  344. package/dist/rules/strict-boolean-expressions.d.ts +19 -0
  345. package/dist/rules/strict-boolean-expressions.js +882 -0
  346. package/dist/rules/strict-void-return.d.ts +10 -0
  347. package/dist/rules/strict-void-return.js +374 -0
  348. package/dist/rules/switch-exhaustiveness-check.d.ts +33 -0
  349. package/dist/rules/switch-exhaustiveness-check.js +291 -0
  350. package/dist/rules/triple-slash-reference.d.ts +12 -0
  351. package/dist/rules/triple-slash-reference.js +110 -0
  352. package/dist/rules/typedef.d.ts +16 -0
  353. package/dist/rules/typedef.js +239 -0
  354. package/dist/rules/unbound-method.d.ts +9 -0
  355. package/dist/rules/unbound-method.js +334 -0
  356. package/dist/rules/unified-signatures.d.ts +11 -0
  357. package/dist/rules/unified-signatures.js +465 -0
  358. package/dist/rules/use-unknown-in-catch-callback-variable.d.ts +6 -0
  359. package/dist/rules/use-unknown-in-catch-callback-variable.js +261 -0
  360. package/dist/util/assertionFunctionUtils.d.ts +16 -0
  361. package/dist/util/assertionFunctionUtils.js +116 -0
  362. package/dist/util/astUtils.d.ts +17 -0
  363. package/dist/util/astUtils.js +143 -0
  364. package/dist/util/baseTypeUtils.d.ts +13 -0
  365. package/dist/util/baseTypeUtils.js +75 -0
  366. package/dist/util/class-scope-analyzer/classScopeAnalyzer.d.ts +52 -0
  367. package/dist/util/class-scope-analyzer/classScopeAnalyzer.js +566 -0
  368. package/dist/util/class-scope-analyzer/extractComputedName.d.ts +17 -0
  369. package/dist/util/class-scope-analyzer/extractComputedName.js +70 -0
  370. package/dist/util/class-scope-analyzer/types.d.ts +12 -0
  371. package/dist/util/class-scope-analyzer/types.js +10 -0
  372. package/dist/util/collectUnusedVariables.d.ts +15 -0
  373. package/dist/util/collectUnusedVariables.js +598 -0
  374. package/dist/util/createRule.d.ts +5 -0
  375. package/dist/util/createRule.js +5 -0
  376. package/dist/util/escapeRegExp.d.ts +1 -0
  377. package/dist/util/escapeRegExp.js +14 -0
  378. package/dist/util/explicitReturnTypeUtils.d.ts +47 -0
  379. package/dist/util/explicitReturnTypeUtils.js +238 -0
  380. package/dist/util/getBaseTypesOfClassMember.d.ts +11 -0
  381. package/dist/util/getBaseTypesOfClassMember.js +31 -0
  382. package/dist/util/getConstraintInfo.d.ts +35 -0
  383. package/dist/util/getConstraintInfo.js +70 -0
  384. package/dist/util/getESLintCoreRule.d.ts +27 -0
  385. package/dist/util/getESLintCoreRule.js +16 -0
  386. package/dist/util/getFixOrSuggest.d.ts +9 -0
  387. package/dist/util/getFixOrSuggest.js +13 -0
  388. package/dist/util/getForStatementHeadLoc.d.ts +17 -0
  389. package/dist/util/getForStatementHeadLoc.js +26 -0
  390. package/dist/util/getFunctionHeadLoc.d.ts +101 -0
  391. package/dist/util/getFunctionHeadLoc.js +161 -0
  392. package/dist/util/getMemberHeadLoc.d.ts +36 -0
  393. package/dist/util/getMemberHeadLoc.js +79 -0
  394. package/dist/util/getOperatorPrecedence.d.ts +39 -0
  395. package/dist/util/getOperatorPrecedence.js +421 -0
  396. package/dist/util/getParentFunctionNode.d.ts +2 -0
  397. package/dist/util/getParentFunctionNode.js +18 -0
  398. package/dist/util/getStaticStringValue.d.ts +11 -0
  399. package/dist/util/getStaticStringValue.js +44 -0
  400. package/dist/util/getStringLength.d.ts +1 -0
  401. package/dist/util/getStringLength.js +14 -0
  402. package/dist/util/getTextWithParentheses.d.ts +3 -0
  403. package/dist/util/getTextWithParentheses.js +16 -0
  404. package/dist/util/getThisExpression.d.ts +2 -0
  405. package/dist/util/getThisExpression.js +24 -0
  406. package/dist/util/getValueOfLiteralType.d.ts +2 -0
  407. package/dist/util/getValueOfLiteralType.js +16 -0
  408. package/dist/util/getWrappedCode.d.ts +2 -0
  409. package/dist/util/getWrappedCode.js +6 -0
  410. package/dist/util/getWrappingFixer.d.ts +42 -0
  411. package/dist/util/getWrappingFixer.js +184 -0
  412. package/dist/util/hasOverloadSignatures.d.ts +6 -0
  413. package/dist/util/hasOverloadSignatures.js +47 -0
  414. package/dist/util/index.d.ts +40 -0
  415. package/dist/util/index.js +53 -0
  416. package/dist/util/isArrayMethodCallWithPredicate.d.ts +3 -0
  417. package/dist/util/isArrayMethodCallWithPredicate.js +64 -0
  418. package/dist/util/isAssignee.d.ts +2 -0
  419. package/dist/util/isAssignee.js +50 -0
  420. package/dist/util/isHigherPrecedenceThanAwait.d.ts +2 -0
  421. package/dist/util/isHigherPrecedenceThanAwait.js +46 -0
  422. package/dist/util/isNodeEqual.d.ts +2 -0
  423. package/dist/util/isNodeEqual.js +25 -0
  424. package/dist/util/isNullLiteral.d.ts +2 -0
  425. package/dist/util/isNullLiteral.js +7 -0
  426. package/dist/util/isPromiseAggregatorMethod.d.ts +3 -0
  427. package/dist/util/isPromiseAggregatorMethod.js +22 -0
  428. package/dist/util/isStartOfExpressionStatement.d.ts +7 -0
  429. package/dist/util/isStartOfExpressionStatement.js +22 -0
  430. package/dist/util/isTypeImport.d.ts +12 -0
  431. package/dist/util/isTypeImport.js +21 -0
  432. package/dist/util/isUndefinedIdentifier.d.ts +2 -0
  433. package/dist/util/isUndefinedIdentifier.js +7 -0
  434. package/dist/util/misc.d.ts +115 -0
  435. package/dist/util/misc.js +270 -0
  436. package/dist/util/needsPrecedingSemiColon.d.ts +11 -0
  437. package/dist/util/needsPrecedingSemiColon.js +97 -0
  438. package/dist/util/needsToBeAwaited.d.ts +7 -0
  439. package/dist/util/needsToBeAwaited.js +63 -0
  440. package/dist/util/objectIterators.d.ts +3 -0
  441. package/dist/util/objectIterators.js +25 -0
  442. package/dist/util/promiseUtils.d.ts +27 -0
  443. package/dist/util/promiseUtils.js +98 -0
  444. package/dist/util/rangeToLoc.d.ts +2 -0
  445. package/dist/util/rangeToLoc.js +9 -0
  446. package/dist/util/referenceContainsTypeQuery.d.ts +5 -0
  447. package/dist/util/referenceContainsTypeQuery.js +19 -0
  448. package/dist/util/scopeUtils.d.ts +3 -0
  449. package/dist/util/scopeUtils.js +10 -0
  450. package/dist/util/skipChainExpression.d.ts +2 -0
  451. package/dist/util/skipChainExpression.js +7 -0
  452. package/dist/util/truthinessUtils.d.ts +3 -0
  453. package/dist/util/truthinessUtils.js +60 -0
  454. package/dist/util/types.d.ts +2 -0
  455. package/dist/util/types.js +2 -0
  456. package/dist/util/walkStatements.d.ts +7 -0
  457. package/dist/util/walkStatements.js +56 -0
  458. package/index.d.ts +13 -0
  459. package/package.json +137 -0
  460. package/raw-plugin.d.ts +25 -0
  461. package/rules.d.ts +87 -0
@@ -0,0 +1,598 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectVariables = collectVariables;
4
+ const scope_manager_1 = require("@typescript-eslint/scope-manager");
5
+ const utils_1 = require("@typescript-eslint/utils");
6
+ const isTypeImport_1 = require("./isTypeImport");
7
+ const referenceContainsTypeQuery_1 = require("./referenceContainsTypeQuery");
8
+ /**
9
+ * This class leverages an AST visitor to mark variables as used via the
10
+ * `eslintUsed` property.
11
+ */
12
+ class UnusedVarsVisitor extends scope_manager_1.Visitor {
13
+ /**
14
+ * We keep a weak cache so that multiple rules can share the calculation
15
+ */
16
+ static RESULTS_CACHE = new WeakMap();
17
+ ClassDeclaration = this.visitClass;
18
+ ClassExpression = this.visitClass;
19
+ ForInStatement = this.visitForInForOf;
20
+ ForOfStatement = this.visitForInForOf;
21
+ //#region HELPERS
22
+ FunctionDeclaration = this.visitFunction;
23
+ FunctionExpression = this.visitFunction;
24
+ MethodDefinition = this.visitSetter;
25
+ Property = this.visitSetter;
26
+ TSCallSignatureDeclaration = this.visitFunctionTypeSignature;
27
+ TSConstructorType = this.visitFunctionTypeSignature;
28
+ TSConstructSignatureDeclaration = this.visitFunctionTypeSignature;
29
+ TSDeclareFunction = this.visitFunctionTypeSignature;
30
+ TSEmptyBodyFunctionExpression = this.visitFunctionTypeSignature;
31
+ //#endregion HELPERS
32
+ //#region VISITORS
33
+ // NOTE - This is a simple visitor - meaning it does not support selectors
34
+ TSFunctionType = this.visitFunctionTypeSignature;
35
+ TSMethodSignature = this.visitFunctionTypeSignature;
36
+ #scopeManager;
37
+ constructor(scopeManager) {
38
+ super({
39
+ visitChildrenEvenIfSelectorExists: true,
40
+ });
41
+ this.#scopeManager = scopeManager;
42
+ }
43
+ static collectUnusedVariables(program, scopeManager) {
44
+ const cached = this.RESULTS_CACHE.get(program);
45
+ if (cached) {
46
+ return cached;
47
+ }
48
+ const visitor = new this(scopeManager);
49
+ visitor.visit(program);
50
+ const unusedVars = visitor.collectUnusedVariables(visitor.getScope(program));
51
+ this.RESULTS_CACHE.set(program, unusedVars);
52
+ return unusedVars;
53
+ }
54
+ Identifier(node) {
55
+ const scope = this.getScope(node);
56
+ if (scope.type === utils_1.TSESLint.Scope.ScopeType.function &&
57
+ node.name === 'this' &&
58
+ // this parameters should always be considered used as they're pseudo-parameters
59
+ 'params' in scope.block &&
60
+ scope.block.params.includes(node)) {
61
+ this.markVariableAsUsed(node);
62
+ }
63
+ }
64
+ TSEnumDeclaration(node) {
65
+ // enum members create variables because they can be referenced within the enum,
66
+ // but they obviously aren't unused variables for the purposes of this rule.
67
+ const scope = this.getScope(node);
68
+ for (const variable of scope.variables) {
69
+ this.markVariableAsUsed(variable);
70
+ }
71
+ }
72
+ TSMappedType(node) {
73
+ // mapped types create a variable for their type name, but it's not necessary to reference it,
74
+ // so we shouldn't consider it as unused for the purpose of this rule.
75
+ this.markVariableAsUsed(node.key);
76
+ }
77
+ TSModuleDeclaration(node) {
78
+ // -- global augmentation can be in any file, and they do not need exports
79
+ if (node.kind === 'global') {
80
+ this.markVariableAsUsed('global', node.parent);
81
+ }
82
+ }
83
+ TSParameterProperty(node) {
84
+ let identifier;
85
+ switch (node.parameter.type) {
86
+ case utils_1.AST_NODE_TYPES.AssignmentPattern:
87
+ identifier = node.parameter.left;
88
+ break;
89
+ case utils_1.AST_NODE_TYPES.Identifier:
90
+ identifier = node.parameter;
91
+ break;
92
+ }
93
+ this.markVariableAsUsed(identifier);
94
+ }
95
+ collectUnusedVariables(scope, variables = {
96
+ unusedVariables: new Set(),
97
+ usedVariables: new Set(),
98
+ }) {
99
+ if (
100
+ // skip function expression names
101
+ // this scope is created just to house the variable that allows a function
102
+ // expression to self-reference if it has a name defined
103
+ !scope.functionExpressionScope) {
104
+ for (const variable of scope.variables) {
105
+ // cases that we don't want to treat as used or unused
106
+ if (
107
+ // implicit lib variables (from @typescript-eslint/scope-manager)
108
+ // these aren't variables that should be checked ever
109
+ variable instanceof scope_manager_1.ImplicitLibVariable) {
110
+ continue;
111
+ }
112
+ if (
113
+ // variables marked with markVariableAsUsed()
114
+ variable.eslintUsed ||
115
+ // basic exported variables
116
+ isExported(variable) ||
117
+ // variables implicitly exported via a merged declaration
118
+ isMergeableExported(variable) ||
119
+ // used variables
120
+ isUsedVariable(variable)) {
121
+ variables.usedVariables.add(variable);
122
+ }
123
+ else {
124
+ variables.unusedVariables.add(variable);
125
+ }
126
+ }
127
+ }
128
+ for (const childScope of scope.childScopes) {
129
+ this.collectUnusedVariables(childScope, variables);
130
+ }
131
+ return variables;
132
+ }
133
+ getScope(currentNode) {
134
+ // On Program node, get the outermost scope to avoid return Node.js special function scope or ES modules scope.
135
+ const inner = currentNode.type !== utils_1.AST_NODE_TYPES.Program;
136
+ let node = currentNode;
137
+ while (node) {
138
+ const scope = this.#scopeManager.acquire(node, inner);
139
+ if (scope) {
140
+ if (scope.type === scope_manager_1.ScopeType.functionExpressionName) {
141
+ return scope.childScopes[0];
142
+ }
143
+ return scope;
144
+ }
145
+ node = node.parent;
146
+ }
147
+ return this.#scopeManager.scopes[0];
148
+ }
149
+ markVariableAsUsed(variableOrIdentifierOrName, parent) {
150
+ if (typeof variableOrIdentifierOrName !== 'string' &&
151
+ !('type' in variableOrIdentifierOrName)) {
152
+ variableOrIdentifierOrName.eslintUsed = true;
153
+ return;
154
+ }
155
+ let name;
156
+ let node;
157
+ if (typeof variableOrIdentifierOrName === 'string') {
158
+ name = variableOrIdentifierOrName;
159
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
160
+ node = parent;
161
+ }
162
+ else {
163
+ name = variableOrIdentifierOrName.name;
164
+ node = variableOrIdentifierOrName;
165
+ }
166
+ let currentScope = this.getScope(node);
167
+ while (currentScope) {
168
+ const variable = currentScope.variables.find(scopeVar => scopeVar.name === name);
169
+ if (variable) {
170
+ variable.eslintUsed = true;
171
+ return;
172
+ }
173
+ currentScope = currentScope.upper;
174
+ }
175
+ }
176
+ visitClass(node) {
177
+ // skip a variable of class itself name in the class scope
178
+ const scope = this.getScope(node);
179
+ for (const variable of scope.variables) {
180
+ if (variable.identifiers[0] === scope.block.id) {
181
+ this.markVariableAsUsed(variable);
182
+ return;
183
+ }
184
+ }
185
+ }
186
+ visitForInForOf(node) {
187
+ /**
188
+ * (Brad Zacher): I hate that this has to exist.
189
+ * But it is required for compat with the base ESLint rule.
190
+ *
191
+ * In 2015, ESLint decided to add an exception for these two specific cases
192
+ * ```
193
+ * for (var key in object) return;
194
+ *
195
+ * var key;
196
+ * for (key in object) return;
197
+ * ```
198
+ *
199
+ * I disagree with it, but what are you going to do...
200
+ *
201
+ * https://github.com/eslint/eslint/issues/2342
202
+ */
203
+ let idOrVariable;
204
+ if (node.left.type === utils_1.AST_NODE_TYPES.VariableDeclaration) {
205
+ const variable = this.#scopeManager.getDeclaredVariables(node.left).at(0);
206
+ if (!variable) {
207
+ return;
208
+ }
209
+ idOrVariable = variable;
210
+ }
211
+ if (node.left.type === utils_1.AST_NODE_TYPES.Identifier) {
212
+ idOrVariable = node.left;
213
+ }
214
+ if (idOrVariable == null) {
215
+ return;
216
+ }
217
+ let body = node.body;
218
+ if (node.body.type === utils_1.AST_NODE_TYPES.BlockStatement) {
219
+ if (node.body.body.length !== 1) {
220
+ return;
221
+ }
222
+ body = node.body.body[0];
223
+ }
224
+ if (body.type !== utils_1.AST_NODE_TYPES.ReturnStatement) {
225
+ return;
226
+ }
227
+ this.markVariableAsUsed(idOrVariable);
228
+ }
229
+ visitFunction(node) {
230
+ const scope = this.getScope(node);
231
+ // skip implicit "arguments" variable
232
+ const variable = scope.set.get('arguments');
233
+ if (variable?.defs.length === 0) {
234
+ this.markVariableAsUsed(variable);
235
+ }
236
+ }
237
+ visitFunctionTypeSignature(node) {
238
+ // function type signature params create variables because they can be referenced within the signature,
239
+ // but they obviously aren't unused variables for the purposes of this rule.
240
+ for (const param of node.params) {
241
+ this.visitPattern(param, name => {
242
+ this.markVariableAsUsed(name);
243
+ });
244
+ }
245
+ }
246
+ visitSetter(node) {
247
+ if (node.kind === 'set') {
248
+ // ignore setter parameters because they're syntactically required to exist
249
+ for (const param of node.value.params) {
250
+ this.visitPattern(param, id => {
251
+ this.markVariableAsUsed(id);
252
+ });
253
+ }
254
+ }
255
+ }
256
+ }
257
+ //#region private helpers
258
+ /**
259
+ * Checks the position of given nodes.
260
+ * @param inner A node which is expected as inside.
261
+ * @param outer A node which is expected as outside.
262
+ * @returns `true` if the `inner` node exists in the `outer` node.
263
+ */
264
+ function isInside(inner, outer) {
265
+ return inner.range[0] >= outer.range[0] && inner.range[1] <= outer.range[1];
266
+ }
267
+ /**
268
+ * Determine if an identifier is referencing an enclosing name.
269
+ * This only applies to declarations that create their own scope (modules, functions, classes)
270
+ * @param ref The reference to check.
271
+ * @param nodes The candidate function nodes.
272
+ * @returns True if it's a self-reference, false if not.
273
+ */
274
+ function isSelfReference(ref, nodes) {
275
+ let scope = ref.from;
276
+ while (scope) {
277
+ if (nodes.has(scope.block)) {
278
+ return true;
279
+ }
280
+ scope = scope.upper;
281
+ }
282
+ return false;
283
+ }
284
+ const MERGEABLE_TYPES = new Set([
285
+ utils_1.AST_NODE_TYPES.ClassDeclaration,
286
+ utils_1.AST_NODE_TYPES.FunctionDeclaration,
287
+ utils_1.AST_NODE_TYPES.TSInterfaceDeclaration,
288
+ utils_1.AST_NODE_TYPES.TSModuleDeclaration,
289
+ utils_1.AST_NODE_TYPES.TSTypeAliasDeclaration,
290
+ ]);
291
+ /**
292
+ * Determine if the variable is directly exported
293
+ * @param variable the variable to check
294
+ */
295
+ function isMergeableExported(variable) {
296
+ // If all of the merged things are of the same type, TS will error if not all of them are exported - so we only need to find one
297
+ for (const def of variable.defs) {
298
+ // parameters can never be exported.
299
+ // their `node` prop points to the function decl, which can be exported
300
+ // so we need to special case them
301
+ if (def.type === utils_1.TSESLint.Scope.DefinitionType.Parameter) {
302
+ continue;
303
+ }
304
+ if ((MERGEABLE_TYPES.has(def.node.type) &&
305
+ def.node.parent.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) ||
306
+ def.node.parent.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
307
+ return true;
308
+ }
309
+ }
310
+ return false;
311
+ }
312
+ /**
313
+ * Determines if a given variable is being exported from a module.
314
+ * @param variable eslint-scope variable object.
315
+ * @returns True if the variable is exported, false if not.
316
+ */
317
+ function isExported(variable) {
318
+ return variable.defs.some(definition => {
319
+ let node = definition.node;
320
+ if (node.type === utils_1.AST_NODE_TYPES.VariableDeclarator) {
321
+ node = node.parent;
322
+ }
323
+ else if (definition.type === utils_1.TSESLint.Scope.DefinitionType.Parameter) {
324
+ return false;
325
+ }
326
+ return node.parent.type.startsWith('Export');
327
+ });
328
+ }
329
+ const LOGICAL_ASSIGNMENT_OPERATORS = new Set(['??=', '&&=', '||=']);
330
+ /**
331
+ * Determines if the variable is used.
332
+ * @param variable The variable to check.
333
+ * @returns True if the variable is used
334
+ */
335
+ function isUsedVariable(variable) {
336
+ /**
337
+ * Gets a list of function definitions for a specified variable.
338
+ * @param variable eslint-scope variable object.
339
+ * @returns Function nodes.
340
+ */
341
+ function getFunctionDefinitions(variable) {
342
+ const functionDefinitions = new Set();
343
+ variable.defs.forEach(def => {
344
+ // FunctionDeclarations
345
+ if (def.type === utils_1.TSESLint.Scope.DefinitionType.FunctionName) {
346
+ functionDefinitions.add(def.node);
347
+ }
348
+ // FunctionExpressions
349
+ if (def.type === utils_1.TSESLint.Scope.DefinitionType.Variable &&
350
+ (def.node.init?.type === utils_1.AST_NODE_TYPES.FunctionExpression ||
351
+ def.node.init?.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression)) {
352
+ functionDefinitions.add(def.node.init);
353
+ }
354
+ });
355
+ return functionDefinitions;
356
+ }
357
+ function getTypeDeclarations(variable) {
358
+ const nodes = new Set();
359
+ variable.defs.forEach(def => {
360
+ if (def.node.type === utils_1.AST_NODE_TYPES.TSInterfaceDeclaration ||
361
+ def.node.type === utils_1.AST_NODE_TYPES.TSTypeAliasDeclaration) {
362
+ nodes.add(def.node);
363
+ }
364
+ });
365
+ return nodes;
366
+ }
367
+ function getModuleDeclarations(variable) {
368
+ const nodes = new Set();
369
+ variable.defs.forEach(def => {
370
+ if (def.node.type === utils_1.AST_NODE_TYPES.TSModuleDeclaration) {
371
+ nodes.add(def.node);
372
+ }
373
+ });
374
+ return nodes;
375
+ }
376
+ function getEnumDeclarations(variable) {
377
+ const nodes = new Set();
378
+ variable.defs.forEach(def => {
379
+ if (def.node.type === utils_1.AST_NODE_TYPES.TSEnumDeclaration) {
380
+ nodes.add(def.node);
381
+ }
382
+ });
383
+ return nodes;
384
+ }
385
+ /**
386
+ * Checks if the ref is contained within one of the given nodes
387
+ */
388
+ function isInsideOneOf(ref, nodes) {
389
+ for (const node of nodes) {
390
+ if (isInside(ref.identifier, node)) {
391
+ return true;
392
+ }
393
+ }
394
+ return false;
395
+ }
396
+ /**
397
+ * Checks whether a given node is unused expression or not.
398
+ * @param node The node itself
399
+ * @returns The node is an unused expression.
400
+ */
401
+ function isUnusedExpression(node) {
402
+ const parent = node.parent;
403
+ if (parent.type === utils_1.AST_NODE_TYPES.ExpressionStatement) {
404
+ return true;
405
+ }
406
+ if (parent.type === utils_1.AST_NODE_TYPES.SequenceExpression) {
407
+ const isLastExpression = parent.expressions[parent.expressions.length - 1] === node;
408
+ if (!isLastExpression) {
409
+ return true;
410
+ }
411
+ return isUnusedExpression(parent);
412
+ }
413
+ return false;
414
+ }
415
+ /**
416
+ * If a given reference is left-hand side of an assignment, this gets
417
+ * the right-hand side node of the assignment.
418
+ *
419
+ * In the following cases, this returns null.
420
+ *
421
+ * - The reference is not the LHS of an assignment expression.
422
+ * - The reference is inside of a loop.
423
+ * - The reference is inside of a function scope which is different from
424
+ * the declaration.
425
+ * @param ref A reference to check.
426
+ * @param prevRhsNode The previous RHS node.
427
+ * @returns The RHS node or null.
428
+ */
429
+ function getRhsNode(ref, prevRhsNode) {
430
+ /**
431
+ * Checks whether the given node is in a loop or not.
432
+ * @param node The node to check.
433
+ * @returns `true` if the node is in a loop.
434
+ */
435
+ function isInLoop(node) {
436
+ let currentNode = node;
437
+ while (currentNode) {
438
+ if (utils_1.ASTUtils.isFunction(currentNode)) {
439
+ break;
440
+ }
441
+ if (utils_1.ASTUtils.isLoop(currentNode)) {
442
+ return true;
443
+ }
444
+ currentNode = currentNode.parent;
445
+ }
446
+ return false;
447
+ }
448
+ const id = ref.identifier;
449
+ const parent = id.parent;
450
+ const refScope = ref.from.variableScope;
451
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
452
+ const varScope = ref.resolved.scope.variableScope;
453
+ const canBeUsedLater = refScope !== varScope || isInLoop(id);
454
+ /*
455
+ * Inherits the previous node if this reference is in the node.
456
+ * This is for `a = a + a`-like code.
457
+ */
458
+ if (prevRhsNode && isInside(id, prevRhsNode)) {
459
+ return prevRhsNode;
460
+ }
461
+ if (parent.type === utils_1.AST_NODE_TYPES.AssignmentExpression &&
462
+ isUnusedExpression(parent) &&
463
+ id === parent.left &&
464
+ !canBeUsedLater) {
465
+ return parent.right;
466
+ }
467
+ return null;
468
+ }
469
+ /**
470
+ * Checks whether a given reference is a read to update itself or not.
471
+ * @param ref A reference to check.
472
+ * @param rhsNode The RHS node of the previous assignment.
473
+ * @returns The reference is a read to update itself.
474
+ */
475
+ function isReadForItself(ref, rhsNode) {
476
+ /**
477
+ * Checks whether a given Identifier node exists inside of a function node which can be used later.
478
+ *
479
+ * "can be used later" means:
480
+ * - the function is assigned to a variable.
481
+ * - the function is bound to a property and the object can be used later.
482
+ * - the function is bound as an argument of a function call.
483
+ *
484
+ * If a reference exists in a function which can be used later, the reference is read when the function is called.
485
+ * @param id An Identifier node to check.
486
+ * @param rhsNode The RHS node of the previous assignment.
487
+ * @returns `true` if the `id` node exists inside of a function node which can be used later.
488
+ */
489
+ function isInsideOfStorableFunction(id, rhsNode) {
490
+ /**
491
+ * Finds a function node from ancestors of a node.
492
+ * @param node A start node to find.
493
+ * @returns A found function node.
494
+ */
495
+ function getUpperFunction(node) {
496
+ let currentNode = node;
497
+ while (currentNode) {
498
+ if (utils_1.ASTUtils.isFunction(currentNode)) {
499
+ return currentNode;
500
+ }
501
+ currentNode = currentNode.parent;
502
+ }
503
+ return null;
504
+ }
505
+ /**
506
+ * Checks whether a given function node is stored to somewhere or not.
507
+ * If the function node is stored, the function can be used later.
508
+ * @param funcNode A function node to check.
509
+ * @param rhsNode The RHS node of the previous assignment.
510
+ * @returns `true` if under the following conditions:
511
+ * - the funcNode is assigned to a variable.
512
+ * - the funcNode is bound as an argument of a function call.
513
+ * - the function is bound to a property and the object satisfies above conditions.
514
+ */
515
+ function isStorableFunction(funcNode, rhsNode) {
516
+ let node = funcNode;
517
+ let parent = funcNode.parent;
518
+ while (parent && isInside(parent, rhsNode)) {
519
+ switch (parent.type) {
520
+ case utils_1.AST_NODE_TYPES.SequenceExpression:
521
+ if (parent.expressions[parent.expressions.length - 1] !== node) {
522
+ return false;
523
+ }
524
+ break;
525
+ case utils_1.AST_NODE_TYPES.CallExpression:
526
+ case utils_1.AST_NODE_TYPES.NewExpression:
527
+ return parent.callee !== node;
528
+ case utils_1.AST_NODE_TYPES.AssignmentExpression:
529
+ case utils_1.AST_NODE_TYPES.TaggedTemplateExpression:
530
+ case utils_1.AST_NODE_TYPES.YieldExpression:
531
+ return true;
532
+ default:
533
+ if (parent.type.endsWith('Statement') ||
534
+ parent.type.endsWith('Declaration')) {
535
+ /*
536
+ * If it encountered statements, this is a complex pattern.
537
+ * Since analyzing complex patterns is hard, this returns `true` to avoid false positive.
538
+ */
539
+ return true;
540
+ }
541
+ }
542
+ node = parent;
543
+ parent = parent.parent;
544
+ }
545
+ return false;
546
+ }
547
+ const funcNode = getUpperFunction(id);
548
+ return (!!funcNode &&
549
+ isInside(funcNode, rhsNode) &&
550
+ isStorableFunction(funcNode, rhsNode));
551
+ }
552
+ const id = ref.identifier;
553
+ const parent = id.parent;
554
+ return (ref.isRead() && // in RHS of an assignment for itself. e.g. `a = a + 1`
555
+ // self update. e.g. `a += 1`, `a++`
556
+ ((parent.type === utils_1.AST_NODE_TYPES.AssignmentExpression &&
557
+ !LOGICAL_ASSIGNMENT_OPERATORS.has(parent.operator) &&
558
+ isUnusedExpression(parent) &&
559
+ parent.left === id) ||
560
+ (parent.type === utils_1.AST_NODE_TYPES.UpdateExpression &&
561
+ isUnusedExpression(parent)) ||
562
+ (!!rhsNode &&
563
+ isInside(id, rhsNode) &&
564
+ !isInsideOfStorableFunction(id, rhsNode))));
565
+ }
566
+ const functionNodes = getFunctionDefinitions(variable);
567
+ const isFunctionDefinition = functionNodes.size > 0;
568
+ const typeDeclNodes = getTypeDeclarations(variable);
569
+ const isTypeDecl = typeDeclNodes.size > 0;
570
+ const moduleDeclNodes = getModuleDeclarations(variable);
571
+ const isModuleDecl = moduleDeclNodes.size > 0;
572
+ const enumDeclNodes = getEnumDeclarations(variable);
573
+ const isEnumDecl = enumDeclNodes.size > 0;
574
+ const isImportedAsType = variable.defs.every(isTypeImport_1.isTypeImport);
575
+ let rhsNode = null;
576
+ return variable.references.some(ref => {
577
+ const forItself = isReadForItself(ref, rhsNode);
578
+ rhsNode = getRhsNode(ref, rhsNode);
579
+ return (ref.isRead() &&
580
+ !forItself &&
581
+ !(!isImportedAsType && (0, referenceContainsTypeQuery_1.referenceContainsTypeQuery)(ref.identifier)) &&
582
+ !(isFunctionDefinition && isSelfReference(ref, functionNodes)) &&
583
+ !(isTypeDecl && isInsideOneOf(ref, typeDeclNodes)) &&
584
+ !(isModuleDecl && isSelfReference(ref, moduleDeclNodes)) &&
585
+ !(isEnumDecl && isSelfReference(ref, enumDeclNodes)));
586
+ });
587
+ }
588
+ //#endregion private helpers
589
+ /**
590
+ * Collects the set of unused variables for a given context.
591
+ *
592
+ * Due to complexity, this does not take into consideration:
593
+ * - variables within declaration files
594
+ * - variables within ambient module declarations
595
+ */
596
+ function collectVariables(context) {
597
+ return UnusedVarsVisitor.collectUnusedVariables(context.sourceCode.ast, utils_1.ESLintUtils.nullThrows(context.sourceCode.scopeManager, 'Missing required scope manager'));
598
+ }
@@ -0,0 +1,5 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ import type { ESLintPluginDocs } from '../../rules';
3
+ export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, ESLintPluginDocs>>) => ESLintUtils.RuleModule<MessageIds, Options, ESLintPluginDocs, ESLintUtils.RuleListener> & {
4
+ name: string;
5
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRule = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ exports.createRule = utils_1.ESLintUtils.RuleCreator(name => `https://typescript-eslint.io/rules/${name}`);
@@ -0,0 +1 @@
1
+ export declare function escapeRegExp(string?: string): string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.escapeRegExp = escapeRegExp;
4
+ /**
5
+ * Lodash <https://lodash.com/>
6
+ * Released under MIT license <https://lodash.com/license>
7
+ */
8
+ const reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
9
+ const reHasRegExpChar = RegExp(reRegExpChar.source);
10
+ function escapeRegExp(string = '') {
11
+ return string && reHasRegExpChar.test(string)
12
+ ? string.replaceAll(reRegExpChar, '\\$&')
13
+ : string;
14
+ }
@@ -0,0 +1,47 @@
1
+ import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
2
+ export type FunctionExpression = TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression;
3
+ export type FunctionNode = FunctionExpression | TSESTree.FunctionDeclaration;
4
+ export interface FunctionInfo<T extends FunctionNode> {
5
+ node: T;
6
+ returns: TSESTree.ReturnStatement[];
7
+ }
8
+ /**
9
+ * Checks if a function belongs to:
10
+ * ```
11
+ * () => () => ...
12
+ * () => function () { ... }
13
+ * () => { return () => ... }
14
+ * () => { return function () { ... } }
15
+ * function fn() { return () => ... }
16
+ * function fn() { return function() { ... } }
17
+ * ```
18
+ */
19
+ export declare function doesImmediatelyReturnFunctionExpression({ node, returns, }: FunctionInfo<FunctionNode>): boolean;
20
+ interface Options {
21
+ allowDirectConstAssertionInArrowFunctions?: boolean;
22
+ allowExpressions?: boolean;
23
+ allowHigherOrderFunctions?: boolean;
24
+ allowTypedFunctionExpressions?: boolean;
25
+ }
26
+ /**
27
+ * True when the provided function expression is typed.
28
+ */
29
+ export declare function isTypedFunctionExpression(node: FunctionExpression, options: Options): boolean;
30
+ /**
31
+ * Check whether the function expression return type is either typed or valid
32
+ * with the provided options.
33
+ */
34
+ export declare function isValidFunctionExpressionReturnType(node: FunctionExpression, options: Options): boolean;
35
+ /**
36
+ * Checks if a function declaration/expression has a return type.
37
+ */
38
+ export declare function checkFunctionReturnType({ node, returns }: FunctionInfo<FunctionNode>, options: Options, sourceCode: TSESLint.SourceCode, report: (loc: TSESTree.SourceLocation) => void): void;
39
+ /**
40
+ * Checks if a function declaration/expression has a return type.
41
+ */
42
+ export declare function checkFunctionExpressionReturnType(info: FunctionInfo<FunctionExpression>, options: Options, sourceCode: TSESLint.SourceCode, report: (loc: TSESTree.SourceLocation) => void): void;
43
+ /**
44
+ * Check whether any ancestor of the provided function has a valid return type.
45
+ */
46
+ export declare function ancestorHasReturnType(node: FunctionNode): boolean;
47
+ export {};