@alexlit/lint-kit 182.5.0 → 183.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 (629) hide show
  1. package/package.json +1 -1
  2. package/packages/config-eslint/node_modules/ajv/.tonic_example.js +20 -0
  3. package/packages/config-eslint/node_modules/ajv/LICENSE +22 -0
  4. package/packages/config-eslint/node_modules/ajv/README.md +1505 -0
  5. package/packages/config-eslint/node_modules/ajv/dist/ajv.bundle.js +7201 -0
  6. package/packages/config-eslint/node_modules/ajv/dist/ajv.min.js +3 -0
  7. package/packages/config-eslint/node_modules/ajv/dist/ajv.min.js.map +1 -0
  8. package/packages/config-eslint/node_modules/ajv/lib/ajv.d.ts +402 -0
  9. package/packages/config-eslint/node_modules/ajv/lib/ajv.js +506 -0
  10. package/packages/config-eslint/node_modules/ajv/lib/cache.js +26 -0
  11. package/packages/config-eslint/node_modules/ajv/lib/compile/async.js +90 -0
  12. package/packages/config-eslint/node_modules/ajv/lib/compile/equal.js +5 -0
  13. package/packages/config-eslint/node_modules/ajv/lib/compile/error_classes.js +34 -0
  14. package/packages/config-eslint/node_modules/ajv/lib/compile/formats.js +142 -0
  15. package/packages/config-eslint/node_modules/ajv/lib/compile/index.js +389 -0
  16. package/packages/config-eslint/node_modules/ajv/lib/compile/resolve.js +270 -0
  17. package/packages/config-eslint/node_modules/ajv/lib/compile/rules.js +66 -0
  18. package/packages/config-eslint/node_modules/ajv/lib/compile/schema_obj.js +9 -0
  19. package/packages/config-eslint/node_modules/ajv/lib/compile/ucs2length.js +20 -0
  20. package/packages/config-eslint/node_modules/ajv/lib/compile/util.js +239 -0
  21. package/packages/config-eslint/node_modules/ajv/lib/data.js +49 -0
  22. package/packages/config-eslint/node_modules/ajv/lib/definition_schema.js +37 -0
  23. package/packages/config-eslint/node_modules/ajv/lib/dot/_limit.jst +113 -0
  24. package/packages/config-eslint/node_modules/ajv/lib/dot/_limitItems.jst +12 -0
  25. package/packages/config-eslint/node_modules/ajv/lib/dot/_limitLength.jst +12 -0
  26. package/packages/config-eslint/node_modules/ajv/lib/dot/_limitProperties.jst +12 -0
  27. package/packages/config-eslint/node_modules/ajv/lib/dot/allOf.jst +32 -0
  28. package/packages/config-eslint/node_modules/ajv/lib/dot/anyOf.jst +46 -0
  29. package/packages/config-eslint/node_modules/ajv/lib/dot/coerce.def +51 -0
  30. package/packages/config-eslint/node_modules/ajv/lib/dot/comment.jst +9 -0
  31. package/packages/config-eslint/node_modules/ajv/lib/dot/const.jst +11 -0
  32. package/packages/config-eslint/node_modules/ajv/lib/dot/contains.jst +55 -0
  33. package/packages/config-eslint/node_modules/ajv/lib/dot/custom.jst +191 -0
  34. package/packages/config-eslint/node_modules/ajv/lib/dot/defaults.def +47 -0
  35. package/packages/config-eslint/node_modules/ajv/lib/dot/definitions.def +203 -0
  36. package/packages/config-eslint/node_modules/ajv/lib/dot/dependencies.jst +79 -0
  37. package/packages/config-eslint/node_modules/ajv/lib/dot/enum.jst +30 -0
  38. package/packages/config-eslint/node_modules/ajv/lib/dot/errors.def +194 -0
  39. package/packages/config-eslint/node_modules/ajv/lib/dot/format.jst +106 -0
  40. package/packages/config-eslint/node_modules/ajv/lib/dot/if.jst +73 -0
  41. package/packages/config-eslint/node_modules/ajv/lib/dot/items.jst +98 -0
  42. package/packages/config-eslint/node_modules/ajv/lib/dot/missing.def +39 -0
  43. package/packages/config-eslint/node_modules/ajv/lib/dot/multipleOf.jst +22 -0
  44. package/packages/config-eslint/node_modules/ajv/lib/dot/not.jst +43 -0
  45. package/packages/config-eslint/node_modules/ajv/lib/dot/oneOf.jst +54 -0
  46. package/packages/config-eslint/node_modules/ajv/lib/dot/pattern.jst +25 -0
  47. package/packages/config-eslint/node_modules/ajv/lib/dot/properties.jst +245 -0
  48. package/packages/config-eslint/node_modules/ajv/lib/dot/propertyNames.jst +52 -0
  49. package/packages/config-eslint/node_modules/ajv/lib/dot/ref.jst +85 -0
  50. package/packages/config-eslint/node_modules/ajv/lib/dot/required.jst +108 -0
  51. package/packages/config-eslint/node_modules/ajv/lib/dot/uniqueItems.jst +62 -0
  52. package/packages/config-eslint/node_modules/ajv/lib/dot/validate.jst +276 -0
  53. package/packages/config-eslint/node_modules/ajv/lib/dotjs/README.md +3 -0
  54. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limit.js +163 -0
  55. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitItems.js +80 -0
  56. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitLength.js +85 -0
  57. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitProperties.js +80 -0
  58. package/packages/config-eslint/node_modules/ajv/lib/dotjs/allOf.js +42 -0
  59. package/packages/config-eslint/node_modules/ajv/lib/dotjs/anyOf.js +73 -0
  60. package/packages/config-eslint/node_modules/ajv/lib/dotjs/comment.js +14 -0
  61. package/packages/config-eslint/node_modules/ajv/lib/dotjs/const.js +56 -0
  62. package/packages/config-eslint/node_modules/ajv/lib/dotjs/contains.js +81 -0
  63. package/packages/config-eslint/node_modules/ajv/lib/dotjs/custom.js +228 -0
  64. package/packages/config-eslint/node_modules/ajv/lib/dotjs/dependencies.js +168 -0
  65. package/packages/config-eslint/node_modules/ajv/lib/dotjs/enum.js +66 -0
  66. package/packages/config-eslint/node_modules/ajv/lib/dotjs/format.js +150 -0
  67. package/packages/config-eslint/node_modules/ajv/lib/dotjs/if.js +103 -0
  68. package/packages/config-eslint/node_modules/ajv/lib/dotjs/index.js +33 -0
  69. package/packages/config-eslint/node_modules/ajv/lib/dotjs/items.js +140 -0
  70. package/packages/config-eslint/node_modules/ajv/lib/dotjs/multipleOf.js +80 -0
  71. package/packages/config-eslint/node_modules/ajv/lib/dotjs/not.js +84 -0
  72. package/packages/config-eslint/node_modules/ajv/lib/dotjs/oneOf.js +73 -0
  73. package/packages/config-eslint/node_modules/ajv/lib/dotjs/pattern.js +85 -0
  74. package/packages/config-eslint/node_modules/ajv/lib/dotjs/properties.js +335 -0
  75. package/packages/config-eslint/node_modules/ajv/lib/dotjs/propertyNames.js +81 -0
  76. package/packages/config-eslint/node_modules/ajv/lib/dotjs/ref.js +124 -0
  77. package/packages/config-eslint/node_modules/ajv/lib/dotjs/required.js +270 -0
  78. package/packages/config-eslint/node_modules/ajv/lib/dotjs/uniqueItems.js +86 -0
  79. package/packages/config-eslint/node_modules/ajv/lib/dotjs/validate.js +482 -0
  80. package/packages/config-eslint/node_modules/ajv/lib/keyword.js +146 -0
  81. package/packages/config-eslint/node_modules/ajv/lib/refs/data.json +17 -0
  82. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-04.json +149 -0
  83. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-06.json +154 -0
  84. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-07.json +168 -0
  85. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-secure.json +94 -0
  86. package/packages/config-eslint/node_modules/ajv/package.json +107 -0
  87. package/packages/config-eslint/node_modules/ajv/scripts/.eslintrc.yml +3 -0
  88. package/packages/config-eslint/node_modules/ajv/scripts/bundle.js +61 -0
  89. package/packages/config-eslint/node_modules/ajv/scripts/compile-dots.js +73 -0
  90. package/packages/config-eslint/node_modules/ajv/scripts/info +10 -0
  91. package/packages/config-eslint/node_modules/ajv/scripts/prepare-tests +12 -0
  92. package/packages/config-eslint/node_modules/ajv/scripts/publish-built-version +32 -0
  93. package/packages/config-eslint/node_modules/ajv/scripts/travis-gh-pages +23 -0
  94. package/packages/config-eslint/node_modules/balanced-match/LICENSE.md +23 -0
  95. package/packages/config-eslint/node_modules/balanced-match/README.md +57 -0
  96. package/packages/config-eslint/node_modules/balanced-match/dist/commonjs/index.d.ts +9 -0
  97. package/packages/config-eslint/node_modules/balanced-match/dist/commonjs/index.d.ts.map +1 -0
  98. package/packages/config-eslint/node_modules/balanced-match/dist/commonjs/index.js +59 -0
  99. package/packages/config-eslint/node_modules/balanced-match/dist/commonjs/index.js.map +1 -0
  100. package/packages/config-eslint/node_modules/balanced-match/dist/commonjs/package.json +3 -0
  101. package/packages/config-eslint/node_modules/balanced-match/dist/esm/index.d.ts +9 -0
  102. package/packages/config-eslint/node_modules/balanced-match/dist/esm/index.d.ts.map +1 -0
  103. package/packages/config-eslint/node_modules/balanced-match/dist/esm/index.js +54 -0
  104. package/packages/config-eslint/node_modules/balanced-match/dist/esm/index.js.map +1 -0
  105. package/packages/config-eslint/node_modules/balanced-match/dist/esm/package.json +3 -0
  106. package/packages/config-eslint/node_modules/balanced-match/package.json +68 -0
  107. package/packages/config-eslint/node_modules/brace-expansion/LICENSE +23 -0
  108. package/packages/config-eslint/node_modules/brace-expansion/README.md +94 -0
  109. package/packages/config-eslint/node_modules/brace-expansion/dist/commonjs/index.d.ts +6 -0
  110. package/packages/config-eslint/node_modules/brace-expansion/dist/commonjs/index.d.ts.map +1 -0
  111. package/packages/config-eslint/node_modules/brace-expansion/dist/commonjs/index.js +199 -0
  112. package/packages/config-eslint/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -0
  113. package/packages/config-eslint/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
  114. package/packages/config-eslint/node_modules/brace-expansion/dist/esm/index.d.ts +6 -0
  115. package/packages/config-eslint/node_modules/brace-expansion/dist/esm/index.d.ts.map +1 -0
  116. package/packages/config-eslint/node_modules/brace-expansion/dist/esm/index.js +195 -0
  117. package/packages/config-eslint/node_modules/brace-expansion/dist/esm/index.js.map +1 -0
  118. package/packages/config-eslint/node_modules/brace-expansion/dist/esm/package.json +3 -0
  119. package/packages/config-eslint/node_modules/brace-expansion/package.json +64 -0
  120. package/packages/config-eslint/node_modules/eslint/LICENSE +19 -0
  121. package/packages/config-eslint/node_modules/eslint/README.md +369 -0
  122. package/packages/config-eslint/node_modules/eslint/bin/eslint.js +195 -0
  123. package/packages/config-eslint/node_modules/eslint/conf/ecma-version.js +16 -0
  124. package/packages/config-eslint/node_modules/eslint/conf/globals.js +169 -0
  125. package/packages/config-eslint/node_modules/eslint/conf/replacements.json +26 -0
  126. package/packages/config-eslint/node_modules/eslint/conf/rule-type-list.json +91 -0
  127. package/packages/config-eslint/node_modules/eslint/lib/api.js +39 -0
  128. package/packages/config-eslint/node_modules/eslint/lib/cli-engine/formatters/formatters-meta.json +18 -0
  129. package/packages/config-eslint/node_modules/eslint/lib/cli-engine/formatters/html.js +359 -0
  130. package/packages/config-eslint/node_modules/eslint/lib/cli-engine/formatters/json-with-metadata.js +16 -0
  131. package/packages/config-eslint/node_modules/eslint/lib/cli-engine/formatters/json.js +13 -0
  132. package/packages/config-eslint/node_modules/eslint/lib/cli-engine/formatters/stylish.js +153 -0
  133. package/packages/config-eslint/node_modules/eslint/lib/cli-engine/hash.js +35 -0
  134. package/packages/config-eslint/node_modules/eslint/lib/cli-engine/lint-result-cache.js +220 -0
  135. package/packages/config-eslint/node_modules/eslint/lib/cli.js +521 -0
  136. package/packages/config-eslint/node_modules/eslint/lib/config/config-loader.js +668 -0
  137. package/packages/config-eslint/node_modules/eslint/lib/config/config.js +674 -0
  138. package/packages/config-eslint/node_modules/eslint/lib/config/default-config.js +78 -0
  139. package/packages/config-eslint/node_modules/eslint/lib/config/flat-config-array.js +217 -0
  140. package/packages/config-eslint/node_modules/eslint/lib/config/flat-config-schema.js +598 -0
  141. package/packages/config-eslint/node_modules/eslint/lib/config-api.js +12 -0
  142. package/packages/config-eslint/node_modules/eslint/lib/eslint/eslint-helpers.js +1462 -0
  143. package/packages/config-eslint/node_modules/eslint/lib/eslint/eslint.js +1364 -0
  144. package/packages/config-eslint/node_modules/eslint/lib/eslint/index.js +7 -0
  145. package/packages/config-eslint/node_modules/eslint/lib/eslint/worker.js +173 -0
  146. package/packages/config-eslint/node_modules/eslint/lib/languages/js/index.js +336 -0
  147. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/index.js +7 -0
  148. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/source-code.js +1178 -0
  149. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/backward-token-comment-cursor.js +61 -0
  150. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/backward-token-cursor.js +57 -0
  151. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/cursor.js +76 -0
  152. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/cursors.js +120 -0
  153. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/decorative-cursor.js +38 -0
  154. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/filter-cursor.js +42 -0
  155. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/forward-token-comment-cursor.js +65 -0
  156. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/forward-token-cursor.js +62 -0
  157. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/index.js +695 -0
  158. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/limit-cursor.js +39 -0
  159. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/padded-token-cursor.js +45 -0
  160. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/skip-cursor.js +41 -0
  161. package/packages/config-eslint/node_modules/eslint/lib/languages/js/source-code/token-store/utils.js +131 -0
  162. package/packages/config-eslint/node_modules/eslint/lib/languages/js/validate-language-options.js +196 -0
  163. package/packages/config-eslint/node_modules/eslint/lib/linter/apply-disable-directives.js +583 -0
  164. package/packages/config-eslint/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js +828 -0
  165. package/packages/config-eslint/node_modules/eslint/lib/linter/code-path-analysis/code-path-segment.js +262 -0
  166. package/packages/config-eslint/node_modules/eslint/lib/linter/code-path-analysis/code-path-state.js +2370 -0
  167. package/packages/config-eslint/node_modules/eslint/lib/linter/code-path-analysis/code-path.js +332 -0
  168. package/packages/config-eslint/node_modules/eslint/lib/linter/code-path-analysis/debug-helpers.js +223 -0
  169. package/packages/config-eslint/node_modules/eslint/lib/linter/code-path-analysis/fork-context.js +374 -0
  170. package/packages/config-eslint/node_modules/eslint/lib/linter/code-path-analysis/id-generator.js +44 -0
  171. package/packages/config-eslint/node_modules/eslint/lib/linter/esquery.js +332 -0
  172. package/packages/config-eslint/node_modules/eslint/lib/linter/file-context.js +88 -0
  173. package/packages/config-eslint/node_modules/eslint/lib/linter/file-report.js +604 -0
  174. package/packages/config-eslint/node_modules/eslint/lib/linter/index.js +11 -0
  175. package/packages/config-eslint/node_modules/eslint/lib/linter/interpolate.js +50 -0
  176. package/packages/config-eslint/node_modules/eslint/lib/linter/linter.js +1614 -0
  177. package/packages/config-eslint/node_modules/eslint/lib/linter/rule-fixer.js +199 -0
  178. package/packages/config-eslint/node_modules/eslint/lib/linter/source-code-fixer.js +154 -0
  179. package/packages/config-eslint/node_modules/eslint/lib/linter/source-code-traverser.js +333 -0
  180. package/packages/config-eslint/node_modules/eslint/lib/linter/source-code-visitor.js +81 -0
  181. package/packages/config-eslint/node_modules/eslint/lib/linter/timing.js +209 -0
  182. package/packages/config-eslint/node_modules/eslint/lib/linter/vfile.js +115 -0
  183. package/packages/config-eslint/node_modules/eslint/lib/options.js +416 -0
  184. package/packages/config-eslint/node_modules/eslint/lib/rule-tester/index.js +7 -0
  185. package/packages/config-eslint/node_modules/eslint/lib/rule-tester/rule-tester.js +1996 -0
  186. package/packages/config-eslint/node_modules/eslint/lib/rules/accessor-pairs.js +420 -0
  187. package/packages/config-eslint/node_modules/eslint/lib/rules/array-bracket-newline.js +291 -0
  188. package/packages/config-eslint/node_modules/eslint/lib/rules/array-bracket-spacing.js +301 -0
  189. package/packages/config-eslint/node_modules/eslint/lib/rules/array-callback-return.js +510 -0
  190. package/packages/config-eslint/node_modules/eslint/lib/rules/array-element-newline.js +374 -0
  191. package/packages/config-eslint/node_modules/eslint/lib/rules/arrow-body-style.js +418 -0
  192. package/packages/config-eslint/node_modules/eslint/lib/rules/arrow-parens.js +237 -0
  193. package/packages/config-eslint/node_modules/eslint/lib/rules/arrow-spacing.js +188 -0
  194. package/packages/config-eslint/node_modules/eslint/lib/rules/block-scoped-var.js +144 -0
  195. package/packages/config-eslint/node_modules/eslint/lib/rules/block-spacing.js +202 -0
  196. package/packages/config-eslint/node_modules/eslint/lib/rules/brace-style.js +278 -0
  197. package/packages/config-eslint/node_modules/eslint/lib/rules/callback-return.js +216 -0
  198. package/packages/config-eslint/node_modules/eslint/lib/rules/camelcase.js +422 -0
  199. package/packages/config-eslint/node_modules/eslint/lib/rules/capitalized-comments.js +325 -0
  200. package/packages/config-eslint/node_modules/eslint/lib/rules/class-methods-use-this.js +250 -0
  201. package/packages/config-eslint/node_modules/eslint/lib/rules/comma-dangle.js +424 -0
  202. package/packages/config-eslint/node_modules/eslint/lib/rules/comma-spacing.js +205 -0
  203. package/packages/config-eslint/node_modules/eslint/lib/rules/comma-style.js +391 -0
  204. package/packages/config-eslint/node_modules/eslint/lib/rules/complexity.js +201 -0
  205. package/packages/config-eslint/node_modules/eslint/lib/rules/computed-property-spacing.js +251 -0
  206. package/packages/config-eslint/node_modules/eslint/lib/rules/consistent-return.js +221 -0
  207. package/packages/config-eslint/node_modules/eslint/lib/rules/consistent-this.js +179 -0
  208. package/packages/config-eslint/node_modules/eslint/lib/rules/constructor-super.js +453 -0
  209. package/packages/config-eslint/node_modules/eslint/lib/rules/curly.js +425 -0
  210. package/packages/config-eslint/node_modules/eslint/lib/rules/default-case-last.js +51 -0
  211. package/packages/config-eslint/node_modules/eslint/lib/rules/default-case.js +103 -0
  212. package/packages/config-eslint/node_modules/eslint/lib/rules/default-param-last.js +78 -0
  213. package/packages/config-eslint/node_modules/eslint/lib/rules/dot-location.js +138 -0
  214. package/packages/config-eslint/node_modules/eslint/lib/rules/dot-notation.js +216 -0
  215. package/packages/config-eslint/node_modules/eslint/lib/rules/eol-last.js +135 -0
  216. package/packages/config-eslint/node_modules/eslint/lib/rules/eqeqeq.js +210 -0
  217. package/packages/config-eslint/node_modules/eslint/lib/rules/for-direction.js +168 -0
  218. package/packages/config-eslint/node_modules/eslint/lib/rules/func-call-spacing.js +281 -0
  219. package/packages/config-eslint/node_modules/eslint/lib/rules/func-name-matching.js +338 -0
  220. package/packages/config-eslint/node_modules/eslint/lib/rules/func-names.js +204 -0
  221. package/packages/config-eslint/node_modules/eslint/lib/rules/func-style.js +221 -0
  222. package/packages/config-eslint/node_modules/eslint/lib/rules/function-call-argument-newline.js +166 -0
  223. package/packages/config-eslint/node_modules/eslint/lib/rules/function-paren-newline.js +368 -0
  224. package/packages/config-eslint/node_modules/eslint/lib/rules/generator-star-spacing.js +246 -0
  225. package/packages/config-eslint/node_modules/eslint/lib/rules/getter-return.js +242 -0
  226. package/packages/config-eslint/node_modules/eslint/lib/rules/global-require.js +117 -0
  227. package/packages/config-eslint/node_modules/eslint/lib/rules/grouped-accessor-pairs.js +268 -0
  228. package/packages/config-eslint/node_modules/eslint/lib/rules/guard-for-in.js +85 -0
  229. package/packages/config-eslint/node_modules/eslint/lib/rules/handle-callback-err.js +122 -0
  230. package/packages/config-eslint/node_modules/eslint/lib/rules/id-blacklist.js +241 -0
  231. package/packages/config-eslint/node_modules/eslint/lib/rules/id-denylist.js +223 -0
  232. package/packages/config-eslint/node_modules/eslint/lib/rules/id-length.js +217 -0
  233. package/packages/config-eslint/node_modules/eslint/lib/rules/id-match.js +363 -0
  234. package/packages/config-eslint/node_modules/eslint/lib/rules/implicit-arrow-linebreak.js +125 -0
  235. package/packages/config-eslint/node_modules/eslint/lib/rules/indent-legacy.js +1369 -0
  236. package/packages/config-eslint/node_modules/eslint/lib/rules/indent.js +2334 -0
  237. package/packages/config-eslint/node_modules/eslint/lib/rules/index.js +332 -0
  238. package/packages/config-eslint/node_modules/eslint/lib/rules/init-declarations.js +172 -0
  239. package/packages/config-eslint/node_modules/eslint/lib/rules/jsx-quotes.js +128 -0
  240. package/packages/config-eslint/node_modules/eslint/lib/rules/key-spacing.js +822 -0
  241. package/packages/config-eslint/node_modules/eslint/lib/rules/keyword-spacing.js +701 -0
  242. package/packages/config-eslint/node_modules/eslint/lib/rules/line-comment-position.js +157 -0
  243. package/packages/config-eslint/node_modules/eslint/lib/rules/linebreak-style.js +135 -0
  244. package/packages/config-eslint/node_modules/eslint/lib/rules/lines-around-comment.js +581 -0
  245. package/packages/config-eslint/node_modules/eslint/lib/rules/lines-around-directive.js +249 -0
  246. package/packages/config-eslint/node_modules/eslint/lib/rules/lines-between-class-members.js +358 -0
  247. package/packages/config-eslint/node_modules/eslint/lib/rules/logical-assignment-operators.js +688 -0
  248. package/packages/config-eslint/node_modules/eslint/lib/rules/max-classes-per-file.js +90 -0
  249. package/packages/config-eslint/node_modules/eslint/lib/rules/max-depth.js +159 -0
  250. package/packages/config-eslint/node_modules/eslint/lib/rules/max-len.js +497 -0
  251. package/packages/config-eslint/node_modules/eslint/lib/rules/max-lines-per-function.js +238 -0
  252. package/packages/config-eslint/node_modules/eslint/lib/rules/max-lines.js +189 -0
  253. package/packages/config-eslint/node_modules/eslint/lib/rules/max-nested-callbacks.js +115 -0
  254. package/packages/config-eslint/node_modules/eslint/lib/rules/max-params.js +148 -0
  255. package/packages/config-eslint/node_modules/eslint/lib/rules/max-statements-per-line.js +224 -0
  256. package/packages/config-eslint/node_modules/eslint/lib/rules/max-statements.js +188 -0
  257. package/packages/config-eslint/node_modules/eslint/lib/rules/multiline-comment-style.js +652 -0
  258. package/packages/config-eslint/node_modules/eslint/lib/rules/multiline-ternary.js +257 -0
  259. package/packages/config-eslint/node_modules/eslint/lib/rules/new-cap.js +277 -0
  260. package/packages/config-eslint/node_modules/eslint/lib/rules/new-parens.js +120 -0
  261. package/packages/config-eslint/node_modules/eslint/lib/rules/newline-after-var.js +307 -0
  262. package/packages/config-eslint/node_modules/eslint/lib/rules/newline-before-return.js +242 -0
  263. package/packages/config-eslint/node_modules/eslint/lib/rules/newline-per-chained-call.js +159 -0
  264. package/packages/config-eslint/node_modules/eslint/lib/rules/no-alert.js +149 -0
  265. package/packages/config-eslint/node_modules/eslint/lib/rules/no-array-constructor.js +195 -0
  266. package/packages/config-eslint/node_modules/eslint/lib/rules/no-async-promise-executor.js +45 -0
  267. package/packages/config-eslint/node_modules/eslint/lib/rules/no-await-in-loop.js +115 -0
  268. package/packages/config-eslint/node_modules/eslint/lib/rules/no-bitwise.js +145 -0
  269. package/packages/config-eslint/node_modules/eslint/lib/rules/no-buffer-constructor.js +74 -0
  270. package/packages/config-eslint/node_modules/eslint/lib/rules/no-caller.js +52 -0
  271. package/packages/config-eslint/node_modules/eslint/lib/rules/no-case-declarations.js +80 -0
  272. package/packages/config-eslint/node_modules/eslint/lib/rules/no-catch-shadow.js +96 -0
  273. package/packages/config-eslint/node_modules/eslint/lib/rules/no-class-assign.js +66 -0
  274. package/packages/config-eslint/node_modules/eslint/lib/rules/no-compare-neg-zero.js +74 -0
  275. package/packages/config-eslint/node_modules/eslint/lib/rules/no-cond-assign.js +175 -0
  276. package/packages/config-eslint/node_modules/eslint/lib/rules/no-confusing-arrow.js +127 -0
  277. package/packages/config-eslint/node_modules/eslint/lib/rules/no-console.js +227 -0
  278. package/packages/config-eslint/node_modules/eslint/lib/rules/no-const-assign.js +73 -0
  279. package/packages/config-eslint/node_modules/eslint/lib/rules/no-constant-binary-expression.js +603 -0
  280. package/packages/config-eslint/node_modules/eslint/lib/rules/no-constant-condition.js +177 -0
  281. package/packages/config-eslint/node_modules/eslint/lib/rules/no-constructor-return.js +62 -0
  282. package/packages/config-eslint/node_modules/eslint/lib/rules/no-continue.js +38 -0
  283. package/packages/config-eslint/node_modules/eslint/lib/rules/no-control-regex.js +142 -0
  284. package/packages/config-eslint/node_modules/eslint/lib/rules/no-debugger.js +41 -0
  285. package/packages/config-eslint/node_modules/eslint/lib/rules/no-delete-var.js +42 -0
  286. package/packages/config-eslint/node_modules/eslint/lib/rules/no-div-regex.js +60 -0
  287. package/packages/config-eslint/node_modules/eslint/lib/rules/no-dupe-args.js +98 -0
  288. package/packages/config-eslint/node_modules/eslint/lib/rules/no-dupe-class-members.js +117 -0
  289. package/packages/config-eslint/node_modules/eslint/lib/rules/no-dupe-else-if.js +145 -0
  290. package/packages/config-eslint/node_modules/eslint/lib/rules/no-dupe-keys.js +165 -0
  291. package/packages/config-eslint/node_modules/eslint/lib/rules/no-duplicate-case.js +78 -0
  292. package/packages/config-eslint/node_modules/eslint/lib/rules/no-duplicate-imports.js +368 -0
  293. package/packages/config-eslint/node_modules/eslint/lib/rules/no-else-return.js +456 -0
  294. package/packages/config-eslint/node_modules/eslint/lib/rules/no-empty-character-class.js +83 -0
  295. package/packages/config-eslint/node_modules/eslint/lib/rules/no-empty-function.js +236 -0
  296. package/packages/config-eslint/node_modules/eslint/lib/rules/no-empty-pattern.js +85 -0
  297. package/packages/config-eslint/node_modules/eslint/lib/rules/no-empty-static-block.js +73 -0
  298. package/packages/config-eslint/node_modules/eslint/lib/rules/no-empty.js +153 -0
  299. package/packages/config-eslint/node_modules/eslint/lib/rules/no-eq-null.js +51 -0
  300. package/packages/config-eslint/node_modules/eslint/lib/rules/no-eval.js +301 -0
  301. package/packages/config-eslint/node_modules/eslint/lib/rules/no-ex-assign.js +57 -0
  302. package/packages/config-eslint/node_modules/eslint/lib/rules/no-extend-native.js +180 -0
  303. package/packages/config-eslint/node_modules/eslint/lib/rules/no-extra-bind.js +224 -0
  304. package/packages/config-eslint/node_modules/eslint/lib/rules/no-extra-boolean-cast.js +420 -0
  305. package/packages/config-eslint/node_modules/eslint/lib/rules/no-extra-label.js +169 -0
  306. package/packages/config-eslint/node_modules/eslint/lib/rules/no-extra-parens.js +1669 -0
  307. package/packages/config-eslint/node_modules/eslint/lib/rules/no-extra-semi.js +167 -0
  308. package/packages/config-eslint/node_modules/eslint/lib/rules/no-fallthrough.js +260 -0
  309. package/packages/config-eslint/node_modules/eslint/lib/rules/no-floating-decimal.js +99 -0
  310. package/packages/config-eslint/node_modules/eslint/lib/rules/no-func-assign.js +77 -0
  311. package/packages/config-eslint/node_modules/eslint/lib/rules/no-global-assign.js +101 -0
  312. package/packages/config-eslint/node_modules/eslint/lib/rules/no-implicit-coercion.js +468 -0
  313. package/packages/config-eslint/node_modules/eslint/lib/rules/no-implicit-globals.js +187 -0
  314. package/packages/config-eslint/node_modules/eslint/lib/rules/no-implied-eval.js +171 -0
  315. package/packages/config-eslint/node_modules/eslint/lib/rules/no-import-assign.js +227 -0
  316. package/packages/config-eslint/node_modules/eslint/lib/rules/no-inline-comments.js +115 -0
  317. package/packages/config-eslint/node_modules/eslint/lib/rules/no-inner-declarations.js +147 -0
  318. package/packages/config-eslint/node_modules/eslint/lib/rules/no-invalid-regexp.js +244 -0
  319. package/packages/config-eslint/node_modules/eslint/lib/rules/no-invalid-this.js +178 -0
  320. package/packages/config-eslint/node_modules/eslint/lib/rules/no-irregular-whitespace.js +292 -0
  321. package/packages/config-eslint/node_modules/eslint/lib/rules/no-iterator.js +48 -0
  322. package/packages/config-eslint/node_modules/eslint/lib/rules/no-label-var.js +78 -0
  323. package/packages/config-eslint/node_modules/eslint/lib/rules/no-labels.js +156 -0
  324. package/packages/config-eslint/node_modules/eslint/lib/rules/no-lone-blocks.js +140 -0
  325. package/packages/config-eslint/node_modules/eslint/lib/rules/no-lonely-if.js +126 -0
  326. package/packages/config-eslint/node_modules/eslint/lib/rules/no-loop-func.js +273 -0
  327. package/packages/config-eslint/node_modules/eslint/lib/rules/no-loss-of-precision.js +249 -0
  328. package/packages/config-eslint/node_modules/eslint/lib/rules/no-magic-numbers.js +365 -0
  329. package/packages/config-eslint/node_modules/eslint/lib/rules/no-misleading-character-class.js +595 -0
  330. package/packages/config-eslint/node_modules/eslint/lib/rules/no-mixed-operators.js +253 -0
  331. package/packages/config-eslint/node_modules/eslint/lib/rules/no-mixed-requires.js +267 -0
  332. package/packages/config-eslint/node_modules/eslint/lib/rules/no-mixed-spaces-and-tabs.js +148 -0
  333. package/packages/config-eslint/node_modules/eslint/lib/rules/no-multi-assign.js +66 -0
  334. package/packages/config-eslint/node_modules/eslint/lib/rules/no-multi-spaces.js +179 -0
  335. package/packages/config-eslint/node_modules/eslint/lib/rules/no-multi-str.js +67 -0
  336. package/packages/config-eslint/node_modules/eslint/lib/rules/no-multiple-empty-lines.js +210 -0
  337. package/packages/config-eslint/node_modules/eslint/lib/rules/no-native-reassign.js +114 -0
  338. package/packages/config-eslint/node_modules/eslint/lib/rules/no-negated-condition.js +100 -0
  339. package/packages/config-eslint/node_modules/eslint/lib/rules/no-negated-in-lhs.js +59 -0
  340. package/packages/config-eslint/node_modules/eslint/lib/rules/no-nested-ternary.js +46 -0
  341. package/packages/config-eslint/node_modules/eslint/lib/rules/no-new-func.js +96 -0
  342. package/packages/config-eslint/node_modules/eslint/lib/rules/no-new-native-nonconstructor.js +70 -0
  343. package/packages/config-eslint/node_modules/eslint/lib/rules/no-new-object.js +76 -0
  344. package/packages/config-eslint/node_modules/eslint/lib/rules/no-new-require.js +67 -0
  345. package/packages/config-eslint/node_modules/eslint/lib/rules/no-new-symbol.js +74 -0
  346. package/packages/config-eslint/node_modules/eslint/lib/rules/no-new-wrappers.js +62 -0
  347. package/packages/config-eslint/node_modules/eslint/lib/rules/no-new.js +42 -0
  348. package/packages/config-eslint/node_modules/eslint/lib/rules/no-nonoctal-decimal-escape.js +176 -0
  349. package/packages/config-eslint/node_modules/eslint/lib/rules/no-obj-calls.js +99 -0
  350. package/packages/config-eslint/node_modules/eslint/lib/rules/no-object-constructor.js +124 -0
  351. package/packages/config-eslint/node_modules/eslint/lib/rules/no-octal-escape.js +53 -0
  352. package/packages/config-eslint/node_modules/eslint/lib/rules/no-octal.js +42 -0
  353. package/packages/config-eslint/node_modules/eslint/lib/rules/no-param-reassign.js +248 -0
  354. package/packages/config-eslint/node_modules/eslint/lib/rules/no-path-concat.js +79 -0
  355. package/packages/config-eslint/node_modules/eslint/lib/rules/no-plusplus.js +102 -0
  356. package/packages/config-eslint/node_modules/eslint/lib/rules/no-process-env.js +68 -0
  357. package/packages/config-eslint/node_modules/eslint/lib/rules/no-process-exit.js +67 -0
  358. package/packages/config-eslint/node_modules/eslint/lib/rules/no-promise-executor-return.js +264 -0
  359. package/packages/config-eslint/node_modules/eslint/lib/rules/no-proto.js +45 -0
  360. package/packages/config-eslint/node_modules/eslint/lib/rules/no-prototype-builtins.js +181 -0
  361. package/packages/config-eslint/node_modules/eslint/lib/rules/no-redeclare.js +173 -0
  362. package/packages/config-eslint/node_modules/eslint/lib/rules/no-regex-spaces.js +219 -0
  363. package/packages/config-eslint/node_modules/eslint/lib/rules/no-restricted-exports.js +227 -0
  364. package/packages/config-eslint/node_modules/eslint/lib/rules/no-restricted-globals.js +266 -0
  365. package/packages/config-eslint/node_modules/eslint/lib/rules/no-restricted-imports.js +892 -0
  366. package/packages/config-eslint/node_modules/eslint/lib/rules/no-restricted-modules.js +249 -0
  367. package/packages/config-eslint/node_modules/eslint/lib/rules/no-restricted-properties.js +233 -0
  368. package/packages/config-eslint/node_modules/eslint/lib/rules/no-restricted-syntax.js +74 -0
  369. package/packages/config-eslint/node_modules/eslint/lib/rules/no-return-assign.js +87 -0
  370. package/packages/config-eslint/node_modules/eslint/lib/rules/no-return-await.js +162 -0
  371. package/packages/config-eslint/node_modules/eslint/lib/rules/no-script-url.js +68 -0
  372. package/packages/config-eslint/node_modules/eslint/lib/rules/no-self-assign.js +186 -0
  373. package/packages/config-eslint/node_modules/eslint/lib/rules/no-self-compare.js +77 -0
  374. package/packages/config-eslint/node_modules/eslint/lib/rules/no-sequences.js +158 -0
  375. package/packages/config-eslint/node_modules/eslint/lib/rules/no-setter-return.js +224 -0
  376. package/packages/config-eslint/node_modules/eslint/lib/rules/no-shadow-restricted-names.js +113 -0
  377. package/packages/config-eslint/node_modules/eslint/lib/rules/no-shadow.js +695 -0
  378. package/packages/config-eslint/node_modules/eslint/lib/rules/no-spaced-func.js +105 -0
  379. package/packages/config-eslint/node_modules/eslint/lib/rules/no-sparse-arrays.js +68 -0
  380. package/packages/config-eslint/node_modules/eslint/lib/rules/no-sync.js +81 -0
  381. package/packages/config-eslint/node_modules/eslint/lib/rules/no-tabs.js +110 -0
  382. package/packages/config-eslint/node_modules/eslint/lib/rules/no-template-curly-in-string.js +45 -0
  383. package/packages/config-eslint/node_modules/eslint/lib/rules/no-ternary.js +38 -0
  384. package/packages/config-eslint/node_modules/eslint/lib/rules/no-this-before-super.js +365 -0
  385. package/packages/config-eslint/node_modules/eslint/lib/rules/no-throw-literal.js +46 -0
  386. package/packages/config-eslint/node_modules/eslint/lib/rules/no-trailing-spaces.js +227 -0
  387. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unassigned-vars.js +80 -0
  388. package/packages/config-eslint/node_modules/eslint/lib/rules/no-undef-init.js +101 -0
  389. package/packages/config-eslint/node_modules/eslint/lib/rules/no-undef.js +84 -0
  390. package/packages/config-eslint/node_modules/eslint/lib/rules/no-undefined.js +91 -0
  391. package/packages/config-eslint/node_modules/eslint/lib/rules/no-underscore-dangle.js +383 -0
  392. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unexpected-multiline.js +130 -0
  393. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unmodified-loop-condition.js +367 -0
  394. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unneeded-ternary.js +232 -0
  395. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unreachable-loop.js +190 -0
  396. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unreachable.js +300 -0
  397. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unsafe-finally.js +119 -0
  398. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unsafe-negation.js +152 -0
  399. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unsafe-optional-chaining.js +221 -0
  400. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unused-expressions.js +227 -0
  401. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unused-labels.js +158 -0
  402. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unused-private-class-members.js +219 -0
  403. package/packages/config-eslint/node_modules/eslint/lib/rules/no-unused-vars.js +1746 -0
  404. package/packages/config-eslint/node_modules/eslint/lib/rules/no-use-before-define.js +453 -0
  405. package/packages/config-eslint/node_modules/eslint/lib/rules/no-useless-assignment.js +658 -0
  406. package/packages/config-eslint/node_modules/eslint/lib/rules/no-useless-backreference.js +263 -0
  407. package/packages/config-eslint/node_modules/eslint/lib/rules/no-useless-call.js +95 -0
  408. package/packages/config-eslint/node_modules/eslint/lib/rules/no-useless-catch.js +57 -0
  409. package/packages/config-eslint/node_modules/eslint/lib/rules/no-useless-computed-key.js +204 -0
  410. package/packages/config-eslint/node_modules/eslint/lib/rules/no-useless-concat.js +121 -0
  411. package/packages/config-eslint/node_modules/eslint/lib/rules/no-useless-constructor.js +262 -0
  412. package/packages/config-eslint/node_modules/eslint/lib/rules/no-useless-escape.js +406 -0
  413. package/packages/config-eslint/node_modules/eslint/lib/rules/no-useless-rename.js +202 -0
  414. package/packages/config-eslint/node_modules/eslint/lib/rules/no-useless-return.js +401 -0
  415. package/packages/config-eslint/node_modules/eslint/lib/rules/no-var.js +375 -0
  416. package/packages/config-eslint/node_modules/eslint/lib/rules/no-void.js +69 -0
  417. package/packages/config-eslint/node_modules/eslint/lib/rules/no-warning-comments.js +209 -0
  418. package/packages/config-eslint/node_modules/eslint/lib/rules/no-whitespace-before-property.js +150 -0
  419. package/packages/config-eslint/node_modules/eslint/lib/rules/no-with.js +37 -0
  420. package/packages/config-eslint/node_modules/eslint/lib/rules/nonblock-statement-body-position.js +164 -0
  421. package/packages/config-eslint/node_modules/eslint/lib/rules/object-curly-newline.js +383 -0
  422. package/packages/config-eslint/node_modules/eslint/lib/rules/object-curly-spacing.js +369 -0
  423. package/packages/config-eslint/node_modules/eslint/lib/rules/object-property-newline.js +151 -0
  424. package/packages/config-eslint/node_modules/eslint/lib/rules/object-shorthand.js +652 -0
  425. package/packages/config-eslint/node_modules/eslint/lib/rules/one-var-declaration-per-line.js +117 -0
  426. package/packages/config-eslint/node_modules/eslint/lib/rules/one-var.js +717 -0
  427. package/packages/config-eslint/node_modules/eslint/lib/rules/operator-assignment.js +270 -0
  428. package/packages/config-eslint/node_modules/eslint/lib/rules/operator-linebreak.js +315 -0
  429. package/packages/config-eslint/node_modules/eslint/lib/rules/padded-blocks.js +366 -0
  430. package/packages/config-eslint/node_modules/eslint/lib/rules/padding-line-between-statements.js +612 -0
  431. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-arrow-callback.js +444 -0
  432. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-const.js +554 -0
  433. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-destructuring.js +332 -0
  434. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-exponentiation-operator.js +235 -0
  435. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-named-capture-group.js +197 -0
  436. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-numeric-literals.js +157 -0
  437. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-object-has-own.js +148 -0
  438. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-object-spread.js +319 -0
  439. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-promise-reject-errors.js +154 -0
  440. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-reflect.js +150 -0
  441. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-regex-literals.js +605 -0
  442. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-rest-params.js +125 -0
  443. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-spread.js +91 -0
  444. package/packages/config-eslint/node_modules/eslint/lib/rules/prefer-template.js +347 -0
  445. package/packages/config-eslint/node_modules/eslint/lib/rules/preserve-caught-error.js +535 -0
  446. package/packages/config-eslint/node_modules/eslint/lib/rules/quote-props.js +394 -0
  447. package/packages/config-eslint/node_modules/eslint/lib/rules/quotes.js +416 -0
  448. package/packages/config-eslint/node_modules/eslint/lib/rules/radix.js +199 -0
  449. package/packages/config-eslint/node_modules/eslint/lib/rules/require-atomic-updates.js +365 -0
  450. package/packages/config-eslint/node_modules/eslint/lib/rules/require-await.js +184 -0
  451. package/packages/config-eslint/node_modules/eslint/lib/rules/require-unicode-regexp.js +317 -0
  452. package/packages/config-eslint/node_modules/eslint/lib/rules/require-yield.js +86 -0
  453. package/packages/config-eslint/node_modules/eslint/lib/rules/rest-spread-spacing.js +150 -0
  454. package/packages/config-eslint/node_modules/eslint/lib/rules/semi-spacing.js +297 -0
  455. package/packages/config-eslint/node_modules/eslint/lib/rules/semi-style.js +218 -0
  456. package/packages/config-eslint/node_modules/eslint/lib/rules/semi.js +476 -0
  457. package/packages/config-eslint/node_modules/eslint/lib/rules/sort-imports.js +319 -0
  458. package/packages/config-eslint/node_modules/eslint/lib/rules/sort-keys.js +268 -0
  459. package/packages/config-eslint/node_modules/eslint/lib/rules/sort-vars.js +140 -0
  460. package/packages/config-eslint/node_modules/eslint/lib/rules/space-before-blocks.js +232 -0
  461. package/packages/config-eslint/node_modules/eslint/lib/rules/space-before-function-paren.js +202 -0
  462. package/packages/config-eslint/node_modules/eslint/lib/rules/space-in-parens.js +374 -0
  463. package/packages/config-eslint/node_modules/eslint/lib/rules/space-infix-ops.js +249 -0
  464. package/packages/config-eslint/node_modules/eslint/lib/rules/space-unary-ops.js +400 -0
  465. package/packages/config-eslint/node_modules/eslint/lib/rules/spaced-comment.js +447 -0
  466. package/packages/config-eslint/node_modules/eslint/lib/rules/strict.js +324 -0
  467. package/packages/config-eslint/node_modules/eslint/lib/rules/switch-colon-spacing.js +158 -0
  468. package/packages/config-eslint/node_modules/eslint/lib/rules/symbol-description.js +70 -0
  469. package/packages/config-eslint/node_modules/eslint/lib/rules/template-curly-spacing.js +168 -0
  470. package/packages/config-eslint/node_modules/eslint/lib/rules/template-tag-spacing.js +121 -0
  471. package/packages/config-eslint/node_modules/eslint/lib/rules/unicode-bom.js +73 -0
  472. package/packages/config-eslint/node_modules/eslint/lib/rules/use-isnan.js +268 -0
  473. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/ast-utils.js +2848 -0
  474. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/char-source.js +247 -0
  475. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/fix-tracker.js +125 -0
  476. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/keywords.js +67 -0
  477. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/lazy-loading-rule-map.js +118 -0
  478. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/regular-expressions.js +58 -0
  479. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/unicode/index.js +16 -0
  480. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/unicode/is-combining-character.js +13 -0
  481. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/unicode/is-emoji-modifier.js +13 -0
  482. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/unicode/is-regional-indicator-symbol.js +13 -0
  483. package/packages/config-eslint/node_modules/eslint/lib/rules/utils/unicode/is-surrogate-pair.js +14 -0
  484. package/packages/config-eslint/node_modules/eslint/lib/rules/valid-typeof.js +171 -0
  485. package/packages/config-eslint/node_modules/eslint/lib/rules/vars-on-top.js +165 -0
  486. package/packages/config-eslint/node_modules/eslint/lib/rules/wrap-iife.js +238 -0
  487. package/packages/config-eslint/node_modules/eslint/lib/rules/wrap-regex.js +91 -0
  488. package/packages/config-eslint/node_modules/eslint/lib/rules/yield-star-spacing.js +158 -0
  489. package/packages/config-eslint/node_modules/eslint/lib/rules/yoda.js +362 -0
  490. package/packages/config-eslint/node_modules/eslint/lib/services/parser-service.js +64 -0
  491. package/packages/config-eslint/node_modules/eslint/lib/services/processor-service.js +100 -0
  492. package/packages/config-eslint/node_modules/eslint/lib/services/suppressions-service.js +302 -0
  493. package/packages/config-eslint/node_modules/eslint/lib/services/warning-service.js +87 -0
  494. package/packages/config-eslint/node_modules/eslint/lib/shared/ajv.js +34 -0
  495. package/packages/config-eslint/node_modules/eslint/lib/shared/assert.js +21 -0
  496. package/packages/config-eslint/node_modules/eslint/lib/shared/ast-utils.js +30 -0
  497. package/packages/config-eslint/node_modules/eslint/lib/shared/deep-merge-arrays.js +62 -0
  498. package/packages/config-eslint/node_modules/eslint/lib/shared/directives.js +16 -0
  499. package/packages/config-eslint/node_modules/eslint/lib/shared/flags.js +89 -0
  500. package/packages/config-eslint/node_modules/eslint/lib/shared/logging.js +38 -0
  501. package/packages/config-eslint/node_modules/eslint/lib/shared/naming.js +109 -0
  502. package/packages/config-eslint/node_modules/eslint/lib/shared/option-utils.js +63 -0
  503. package/packages/config-eslint/node_modules/eslint/lib/shared/relative-module-resolver.js +28 -0
  504. package/packages/config-eslint/node_modules/eslint/lib/shared/runtime-info.js +177 -0
  505. package/packages/config-eslint/node_modules/eslint/lib/shared/serialization.js +78 -0
  506. package/packages/config-eslint/node_modules/eslint/lib/shared/severity.js +49 -0
  507. package/packages/config-eslint/node_modules/eslint/lib/shared/stats.js +30 -0
  508. package/packages/config-eslint/node_modules/eslint/lib/shared/string-utils.js +58 -0
  509. package/packages/config-eslint/node_modules/eslint/lib/shared/text-table.js +68 -0
  510. package/packages/config-eslint/node_modules/eslint/lib/shared/translate-cli-options.js +223 -0
  511. package/packages/config-eslint/node_modules/eslint/lib/shared/traverser.js +202 -0
  512. package/packages/config-eslint/node_modules/eslint/lib/types/config-api.d.ts +12 -0
  513. package/packages/config-eslint/node_modules/eslint/lib/types/index.d.ts +1475 -0
  514. package/packages/config-eslint/node_modules/eslint/lib/types/rules.d.ts +5603 -0
  515. package/packages/config-eslint/node_modules/eslint/lib/types/universal.d.ts +6 -0
  516. package/packages/config-eslint/node_modules/eslint/lib/types/use-at-your-own-risk.d.ts +34 -0
  517. package/packages/config-eslint/node_modules/eslint/lib/universal.js +10 -0
  518. package/packages/config-eslint/node_modules/eslint/lib/unsupported-api.js +21 -0
  519. package/packages/config-eslint/node_modules/eslint/messages/all-matched-files-ignored.js +21 -0
  520. package/packages/config-eslint/node_modules/eslint/messages/config-file-missing.js +16 -0
  521. package/packages/config-eslint/node_modules/eslint/messages/config-plugin-missing.js +14 -0
  522. package/packages/config-eslint/node_modules/eslint/messages/config-serialize-function.js +30 -0
  523. package/packages/config-eslint/node_modules/eslint/messages/eslintrc-incompat.js +117 -0
  524. package/packages/config-eslint/node_modules/eslint/messages/eslintrc-plugins.js +27 -0
  525. package/packages/config-eslint/node_modules/eslint/messages/extend-config-missing.js +13 -0
  526. package/packages/config-eslint/node_modules/eslint/messages/failed-to-read-json.js +11 -0
  527. package/packages/config-eslint/node_modules/eslint/messages/file-not-found.js +10 -0
  528. package/packages/config-eslint/node_modules/eslint/messages/invalid-rule-options.js +17 -0
  529. package/packages/config-eslint/node_modules/eslint/messages/invalid-rule-severity.js +13 -0
  530. package/packages/config-eslint/node_modules/eslint/messages/no-config-found.js +15 -0
  531. package/packages/config-eslint/node_modules/eslint/messages/plugin-conflict.js +22 -0
  532. package/packages/config-eslint/node_modules/eslint/messages/plugin-invalid.js +16 -0
  533. package/packages/config-eslint/node_modules/eslint/messages/plugin-missing.js +19 -0
  534. package/packages/config-eslint/node_modules/eslint/messages/shared.js +23 -0
  535. package/packages/config-eslint/node_modules/eslint/messages/whitespace-found.js +11 -0
  536. package/packages/config-eslint/node_modules/eslint/package.json +220 -0
  537. package/packages/config-eslint/node_modules/eslint-visitor-keys/LICENSE +201 -0
  538. package/packages/config-eslint/node_modules/eslint-visitor-keys/README.md +123 -0
  539. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.cjs +187 -0
  540. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.d.cts +28 -0
  541. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/index.d.ts +16 -0
  542. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/visitor-keys.d.ts +12 -0
  543. package/packages/config-eslint/node_modules/eslint-visitor-keys/lib/index.js +67 -0
  544. package/packages/config-eslint/node_modules/eslint-visitor-keys/lib/visitor-keys.js +118 -0
  545. package/packages/config-eslint/node_modules/eslint-visitor-keys/package.json +57 -0
  546. package/packages/config-eslint/node_modules/espree/LICENSE +25 -0
  547. package/packages/config-eslint/node_modules/espree/README.md +261 -0
  548. package/packages/config-eslint/node_modules/espree/dist/espree.cjs +1284 -0
  549. package/packages/config-eslint/node_modules/espree/dist/espree.d.cts +3 -0
  550. package/packages/config-eslint/node_modules/espree/dist/espree.d.cts.map +1 -0
  551. package/packages/config-eslint/node_modules/espree/dist/espree.d.ts +67 -0
  552. package/packages/config-eslint/node_modules/espree/dist/espree.d.ts.map +1 -0
  553. package/packages/config-eslint/node_modules/espree/espree.js +287 -0
  554. package/packages/config-eslint/node_modules/espree/lib/espree.js +493 -0
  555. package/packages/config-eslint/node_modules/espree/lib/options.js +176 -0
  556. package/packages/config-eslint/node_modules/espree/lib/token-translator.js +306 -0
  557. package/packages/config-eslint/node_modules/espree/lib/types.js +118 -0
  558. package/packages/config-eslint/node_modules/espree/package.json +70 -0
  559. package/packages/config-eslint/node_modules/ignore/LICENSE-MIT +21 -0
  560. package/packages/config-eslint/node_modules/ignore/README.md +412 -0
  561. package/packages/config-eslint/node_modules/ignore/index.d.ts +61 -0
  562. package/packages/config-eslint/node_modules/ignore/index.js +636 -0
  563. package/packages/config-eslint/node_modules/ignore/legacy.js +559 -0
  564. package/packages/config-eslint/node_modules/ignore/package.json +74 -0
  565. package/packages/config-eslint/node_modules/json-schema-traverse/.eslintrc.yml +27 -0
  566. package/packages/config-eslint/node_modules/json-schema-traverse/.travis.yml +8 -0
  567. package/packages/config-eslint/node_modules/json-schema-traverse/LICENSE +21 -0
  568. package/packages/config-eslint/node_modules/json-schema-traverse/README.md +83 -0
  569. package/packages/config-eslint/node_modules/json-schema-traverse/index.js +89 -0
  570. package/packages/config-eslint/node_modules/json-schema-traverse/package.json +43 -0
  571. package/packages/config-eslint/node_modules/json-schema-traverse/spec/.eslintrc.yml +6 -0
  572. package/packages/config-eslint/node_modules/json-schema-traverse/spec/fixtures/schema.js +125 -0
  573. package/packages/config-eslint/node_modules/json-schema-traverse/spec/index.spec.js +171 -0
  574. package/packages/config-eslint/node_modules/minimatch/LICENSE.md +55 -0
  575. package/packages/config-eslint/node_modules/minimatch/README.md +528 -0
  576. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts +2 -0
  577. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts.map +1 -0
  578. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
  579. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js.map +1 -0
  580. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/ast.d.ts +22 -0
  581. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/ast.d.ts.map +1 -0
  582. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/ast.js +846 -0
  583. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/ast.js.map +1 -0
  584. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts +8 -0
  585. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts.map +1 -0
  586. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/brace-expressions.js +150 -0
  587. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/brace-expressions.js.map +1 -0
  588. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/escape.d.ts +15 -0
  589. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/escape.d.ts.map +1 -0
  590. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/escape.js +30 -0
  591. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/escape.js.map +1 -0
  592. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/index.d.ts +174 -0
  593. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/index.d.ts.map +1 -0
  594. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/index.js +1121 -0
  595. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/index.js.map +1 -0
  596. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/package.json +3 -0
  597. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/unescape.d.ts +22 -0
  598. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/unescape.d.ts.map +1 -0
  599. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/unescape.js +38 -0
  600. package/packages/config-eslint/node_modules/minimatch/dist/commonjs/unescape.js.map +1 -0
  601. package/packages/config-eslint/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts +2 -0
  602. package/packages/config-eslint/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts.map +1 -0
  603. package/packages/config-eslint/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
  604. package/packages/config-eslint/node_modules/minimatch/dist/esm/assert-valid-pattern.js.map +1 -0
  605. package/packages/config-eslint/node_modules/minimatch/dist/esm/ast.d.ts +22 -0
  606. package/packages/config-eslint/node_modules/minimatch/dist/esm/ast.d.ts.map +1 -0
  607. package/packages/config-eslint/node_modules/minimatch/dist/esm/ast.js +842 -0
  608. package/packages/config-eslint/node_modules/minimatch/dist/esm/ast.js.map +1 -0
  609. package/packages/config-eslint/node_modules/minimatch/dist/esm/brace-expressions.d.ts +8 -0
  610. package/packages/config-eslint/node_modules/minimatch/dist/esm/brace-expressions.d.ts.map +1 -0
  611. package/packages/config-eslint/node_modules/minimatch/dist/esm/brace-expressions.js +146 -0
  612. package/packages/config-eslint/node_modules/minimatch/dist/esm/brace-expressions.js.map +1 -0
  613. package/packages/config-eslint/node_modules/minimatch/dist/esm/escape.d.ts +15 -0
  614. package/packages/config-eslint/node_modules/minimatch/dist/esm/escape.d.ts.map +1 -0
  615. package/packages/config-eslint/node_modules/minimatch/dist/esm/escape.js +26 -0
  616. package/packages/config-eslint/node_modules/minimatch/dist/esm/escape.js.map +1 -0
  617. package/packages/config-eslint/node_modules/minimatch/dist/esm/index.d.ts +174 -0
  618. package/packages/config-eslint/node_modules/minimatch/dist/esm/index.d.ts.map +1 -0
  619. package/packages/config-eslint/node_modules/minimatch/dist/esm/index.js +1108 -0
  620. package/packages/config-eslint/node_modules/minimatch/dist/esm/index.js.map +1 -0
  621. package/packages/config-eslint/node_modules/minimatch/dist/esm/package.json +3 -0
  622. package/packages/config-eslint/node_modules/minimatch/dist/esm/unescape.d.ts +22 -0
  623. package/packages/config-eslint/node_modules/minimatch/dist/esm/unescape.d.ts.map +1 -0
  624. package/packages/config-eslint/node_modules/minimatch/dist/esm/unescape.js +34 -0
  625. package/packages/config-eslint/node_modules/minimatch/dist/esm/unescape.js.map +1 -0
  626. package/packages/config-eslint/node_modules/minimatch/package.json +67 -0
  627. package/packages/config-eslint/package.json +8 -8
  628. package/packages/config-hooks/package.json +2 -2
  629. package/packages/config-stylelint/package.json +2 -2
@@ -0,0 +1,1746 @@
1
+ /**
2
+ * @fileoverview Rule to flag declared but unused variables
3
+ * @author Ilya Volodin
4
+ */
5
+
6
+ "use strict";
7
+
8
+ //------------------------------------------------------------------------------
9
+ // Requirements
10
+ //------------------------------------------------------------------------------
11
+
12
+ const astUtils = require("./utils/ast-utils");
13
+
14
+ //------------------------------------------------------------------------------
15
+ // Types
16
+ //------------------------------------------------------------------------------
17
+
18
+ /** @typedef {import("eslint-scope").Variable} Variable */
19
+ /** @typedef {import("eslint-scope").Reference} Reference */
20
+
21
+ //------------------------------------------------------------------------------
22
+ // Typedefs
23
+ //------------------------------------------------------------------------------
24
+
25
+ /**
26
+ * A simple name for the types of variables that this rule supports
27
+ * @typedef {'array-destructure'|'catch-clause'|'parameter'|'variable'} VariableType
28
+ */
29
+
30
+ /**
31
+ * Bag of data used for formatting the `unusedVar` lint message.
32
+ * @typedef {Object} UnusedVarMessageData
33
+ * @property {string} varName The name of the unused var.
34
+ * @property {'defined'|'assigned a value'} action Description of the vars state.
35
+ * @property {string} additional Any additional info to be appended at the end.
36
+ */
37
+
38
+ /**
39
+ * Bag of data used for formatting the `usedIgnoredVar` lint message.
40
+ * @typedef {Object} UsedIgnoredVarMessageData
41
+ * @property {string} varName The name of the unused var.
42
+ * @property {string} additional Any additional info to be appended at the end.
43
+ */
44
+
45
+ //------------------------------------------------------------------------------
46
+ // Rule Definition
47
+ //------------------------------------------------------------------------------
48
+
49
+ /** @type {import('../types').Rule.RuleModule} */
50
+ module.exports = {
51
+ meta: {
52
+ type: "problem",
53
+
54
+ docs: {
55
+ description: "Disallow unused variables",
56
+ recommended: true,
57
+ url: "https://eslint.org/docs/latest/rules/no-unused-vars",
58
+ },
59
+
60
+ hasSuggestions: true,
61
+
62
+ schema: [
63
+ {
64
+ oneOf: [
65
+ {
66
+ enum: ["all", "local"],
67
+ },
68
+ {
69
+ type: "object",
70
+ properties: {
71
+ vars: {
72
+ enum: ["all", "local"],
73
+ },
74
+ varsIgnorePattern: {
75
+ type: "string",
76
+ },
77
+ args: {
78
+ enum: ["all", "after-used", "none"],
79
+ },
80
+ ignoreRestSiblings: {
81
+ type: "boolean",
82
+ },
83
+ argsIgnorePattern: {
84
+ type: "string",
85
+ },
86
+ caughtErrors: {
87
+ enum: ["all", "none"],
88
+ },
89
+ caughtErrorsIgnorePattern: {
90
+ type: "string",
91
+ },
92
+ destructuredArrayIgnorePattern: {
93
+ type: "string",
94
+ },
95
+ ignoreClassWithStaticInitBlock: {
96
+ type: "boolean",
97
+ },
98
+ ignoreUsingDeclarations: {
99
+ type: "boolean",
100
+ },
101
+ reportUsedIgnorePattern: {
102
+ type: "boolean",
103
+ },
104
+ },
105
+ additionalProperties: false,
106
+ },
107
+ ],
108
+ },
109
+ ],
110
+
111
+ messages: {
112
+ unusedVar:
113
+ "'{{varName}}' is {{action}} but never used{{additional}}.",
114
+ usedIgnoredVar:
115
+ "'{{varName}}' is marked as ignored but is used{{additional}}.",
116
+ removeVar: "Remove unused variable '{{varName}}'.",
117
+ },
118
+ },
119
+
120
+ create(context) {
121
+ const sourceCode = context.sourceCode;
122
+
123
+ const REST_PROPERTY_TYPE =
124
+ /^(?:RestElement|(?:Experimental)?RestProperty)$/u;
125
+
126
+ const config = {
127
+ vars: "all",
128
+ args: "after-used",
129
+ ignoreRestSiblings: false,
130
+ caughtErrors: "all",
131
+ ignoreClassWithStaticInitBlock: false,
132
+ ignoreUsingDeclarations: false,
133
+ reportUsedIgnorePattern: false,
134
+ };
135
+
136
+ const firstOption = context.options[0];
137
+
138
+ if (firstOption) {
139
+ if (typeof firstOption === "string") {
140
+ config.vars = firstOption;
141
+ } else {
142
+ config.vars = firstOption.vars || config.vars;
143
+ config.args = firstOption.args || config.args;
144
+ config.ignoreRestSiblings =
145
+ firstOption.ignoreRestSiblings || config.ignoreRestSiblings;
146
+ config.caughtErrors =
147
+ firstOption.caughtErrors || config.caughtErrors;
148
+ config.ignoreClassWithStaticInitBlock =
149
+ firstOption.ignoreClassWithStaticInitBlock ||
150
+ config.ignoreClassWithStaticInitBlock;
151
+ config.ignoreUsingDeclarations =
152
+ firstOption.ignoreUsingDeclarations ||
153
+ config.ignoreUsingDeclarations;
154
+ config.reportUsedIgnorePattern =
155
+ firstOption.reportUsedIgnorePattern ||
156
+ config.reportUsedIgnorePattern;
157
+
158
+ if (firstOption.varsIgnorePattern) {
159
+ config.varsIgnorePattern = new RegExp(
160
+ firstOption.varsIgnorePattern,
161
+ "u",
162
+ );
163
+ }
164
+
165
+ if (firstOption.argsIgnorePattern) {
166
+ config.argsIgnorePattern = new RegExp(
167
+ firstOption.argsIgnorePattern,
168
+ "u",
169
+ );
170
+ }
171
+
172
+ if (firstOption.caughtErrorsIgnorePattern) {
173
+ config.caughtErrorsIgnorePattern = new RegExp(
174
+ firstOption.caughtErrorsIgnorePattern,
175
+ "u",
176
+ );
177
+ }
178
+
179
+ if (firstOption.destructuredArrayIgnorePattern) {
180
+ config.destructuredArrayIgnorePattern = new RegExp(
181
+ firstOption.destructuredArrayIgnorePattern,
182
+ "u",
183
+ );
184
+ }
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Determines what variable type a def is.
190
+ * @param {Object} def the declaration to check
191
+ * @returns {VariableType} a simple name for the types of variables that this rule supports
192
+ */
193
+ function defToVariableType(def) {
194
+ /*
195
+ * This `destructuredArrayIgnorePattern` error report works differently from the catch
196
+ * clause and parameter error reports. _Both_ the `varsIgnorePattern` and the
197
+ * `destructuredArrayIgnorePattern` will be checked for array destructuring. However,
198
+ * for the purposes of the report, the currently defined behavior is to only inform the
199
+ * user of the `destructuredArrayIgnorePattern` if it's present (regardless of the fact
200
+ * that the `varsIgnorePattern` would also apply). If it's not present, the user will be
201
+ * informed of the `varsIgnorePattern`, assuming that's present.
202
+ */
203
+ if (
204
+ config.destructuredArrayIgnorePattern &&
205
+ def.name.parent.type === "ArrayPattern"
206
+ ) {
207
+ return "array-destructure";
208
+ }
209
+
210
+ switch (def.type) {
211
+ case "CatchClause":
212
+ return "catch-clause";
213
+ case "Parameter":
214
+ return "parameter";
215
+
216
+ default:
217
+ return "variable";
218
+ }
219
+ }
220
+
221
+ /**
222
+ * Gets a given variable's description and configured ignore pattern
223
+ * based on the provided variableType
224
+ * @param {VariableType} variableType a simple name for the types of variables that this rule supports
225
+ * @throws {Error} (Unreachable)
226
+ * @returns {[string | undefined, string | undefined]} the given variable's description and
227
+ * ignore pattern
228
+ */
229
+ function getVariableDescription(variableType) {
230
+ let pattern;
231
+ let variableDescription;
232
+
233
+ switch (variableType) {
234
+ case "array-destructure":
235
+ pattern = config.destructuredArrayIgnorePattern;
236
+ variableDescription = "elements of array destructuring";
237
+ break;
238
+
239
+ case "catch-clause":
240
+ pattern = config.caughtErrorsIgnorePattern;
241
+ variableDescription = "caught errors";
242
+ break;
243
+
244
+ case "parameter":
245
+ pattern = config.argsIgnorePattern;
246
+ variableDescription = "args";
247
+ break;
248
+
249
+ case "variable":
250
+ pattern = config.varsIgnorePattern;
251
+ variableDescription = "vars";
252
+ break;
253
+
254
+ default:
255
+ throw new Error(
256
+ `Unexpected variable type: ${variableType}`,
257
+ );
258
+ }
259
+
260
+ if (pattern) {
261
+ pattern = pattern.toString();
262
+ }
263
+
264
+ return [variableDescription, pattern];
265
+ }
266
+
267
+ /**
268
+ * Generates the message data about the variable being defined and unused,
269
+ * including the ignore pattern if configured.
270
+ * @param {Variable} unusedVar eslint-scope variable object.
271
+ * @returns {UnusedVarMessageData} The message data to be used with this unused variable.
272
+ */
273
+ function getDefinedMessageData(unusedVar) {
274
+ const def = unusedVar.defs && unusedVar.defs[0];
275
+ let additionalMessageData = "";
276
+
277
+ if (def) {
278
+ const [variableDescription, pattern] = getVariableDescription(
279
+ defToVariableType(def),
280
+ );
281
+
282
+ if (pattern && variableDescription) {
283
+ additionalMessageData = `. Allowed unused ${variableDescription} must match ${pattern}`;
284
+ }
285
+ }
286
+
287
+ return {
288
+ varName: unusedVar.name,
289
+ action: "defined",
290
+ additional: additionalMessageData,
291
+ };
292
+ }
293
+
294
+ /**
295
+ * Generate the warning message about the variable being
296
+ * assigned and unused, including the ignore pattern if configured.
297
+ * @param {Variable} unusedVar eslint-scope variable object.
298
+ * @returns {UnusedVarMessageData} The message data to be used with this unused variable.
299
+ */
300
+ function getAssignedMessageData(unusedVar) {
301
+ const def = unusedVar.defs && unusedVar.defs[0];
302
+ let additionalMessageData = "";
303
+
304
+ if (def) {
305
+ const [variableDescription, pattern] = getVariableDescription(
306
+ defToVariableType(def),
307
+ );
308
+
309
+ if (pattern && variableDescription) {
310
+ additionalMessageData = `. Allowed unused ${variableDescription} must match ${pattern}`;
311
+ }
312
+ }
313
+
314
+ return {
315
+ varName: unusedVar.name,
316
+ action: "assigned a value",
317
+ additional: additionalMessageData,
318
+ };
319
+ }
320
+
321
+ /**
322
+ * Generate the warning message about a variable being used even though
323
+ * it is marked as being ignored.
324
+ * @param {Variable} variable eslint-scope variable object
325
+ * @param {VariableType} variableType a simple name for the types of variables that this rule supports
326
+ * @returns {UsedIgnoredVarMessageData} The message data to be used with
327
+ * this used ignored variable.
328
+ */
329
+ function getUsedIgnoredMessageData(variable, variableType) {
330
+ const [variableDescription, pattern] =
331
+ getVariableDescription(variableType);
332
+
333
+ let additionalMessageData = "";
334
+
335
+ if (pattern && variableDescription) {
336
+ additionalMessageData = `. Used ${variableDescription} must not match ${pattern}`;
337
+ }
338
+
339
+ return {
340
+ varName: variable.name,
341
+ additional: additionalMessageData,
342
+ };
343
+ }
344
+
345
+ //--------------------------------------------------------------------------
346
+ // Helpers
347
+ //--------------------------------------------------------------------------
348
+
349
+ const STATEMENT_TYPE = /(?:Statement|Declaration)$/u;
350
+
351
+ /**
352
+ * Determines if a given variable is being exported from a module.
353
+ * @param {Variable} variable eslint-scope variable object.
354
+ * @returns {boolean} True if the variable is exported, false if not.
355
+ * @private
356
+ */
357
+ function isExported(variable) {
358
+ const definition = variable.defs[0];
359
+
360
+ if (definition) {
361
+ let node = definition.node;
362
+
363
+ if (node.type === "VariableDeclarator") {
364
+ node = node.parent;
365
+ } else if (definition.type === "Parameter") {
366
+ return false;
367
+ }
368
+
369
+ return node.parent.type.indexOf("Export") === 0;
370
+ }
371
+ return false;
372
+ }
373
+
374
+ /**
375
+ * Determines if a given variable uses the explicit resource management protocol.
376
+ * @param {Variable} variable eslint-scope variable object.
377
+ * @returns {boolean} True if the variable is declared with "using" or "await using"
378
+ * @private
379
+ */
380
+ function usesExplicitResourceManagement(variable) {
381
+ const [definition] = variable.defs;
382
+
383
+ return (
384
+ definition?.type === "Variable" &&
385
+ (definition.parent.kind === "using" ||
386
+ definition.parent.kind === "await using")
387
+ );
388
+ }
389
+
390
+ /**
391
+ * Checks whether a node is a sibling of the rest property or not.
392
+ * @param {ASTNode} node a node to check
393
+ * @returns {boolean} True if the node is a sibling of the rest property, otherwise false.
394
+ */
395
+ function hasRestSibling(node) {
396
+ return (
397
+ node.type === "Property" &&
398
+ node.parent.type === "ObjectPattern" &&
399
+ REST_PROPERTY_TYPE.test(node.parent.properties.at(-1).type)
400
+ );
401
+ }
402
+
403
+ /**
404
+ * Determines if a variable has a sibling rest property
405
+ * @param {Variable} variable eslint-scope variable object.
406
+ * @returns {boolean} True if the variable has a sibling rest property, false if not.
407
+ * @private
408
+ */
409
+ function hasRestSpreadSibling(variable) {
410
+ if (config.ignoreRestSiblings) {
411
+ const hasRestSiblingDefinition = variable.defs.some(def =>
412
+ hasRestSibling(def.name.parent),
413
+ );
414
+ const hasRestSiblingReference = variable.references.some(ref =>
415
+ hasRestSibling(ref.identifier.parent),
416
+ );
417
+
418
+ return hasRestSiblingDefinition || hasRestSiblingReference;
419
+ }
420
+
421
+ return false;
422
+ }
423
+
424
+ /**
425
+ * Determines if a reference is a read operation.
426
+ * @param {Reference} ref An eslint-scope Reference
427
+ * @returns {boolean} whether the given reference represents a read operation
428
+ * @private
429
+ */
430
+ function isReadRef(ref) {
431
+ return ref.isRead();
432
+ }
433
+
434
+ /**
435
+ * Determine if an identifier is referencing an enclosing function name.
436
+ * @param {Reference} ref The reference to check.
437
+ * @param {ASTNode[]} nodes The candidate function nodes.
438
+ * @returns {boolean} True if it's a self-reference, false if not.
439
+ * @private
440
+ */
441
+ function isSelfReference(ref, nodes) {
442
+ let scope = ref.from;
443
+
444
+ while (scope) {
445
+ if (nodes.includes(scope.block)) {
446
+ return true;
447
+ }
448
+
449
+ scope = scope.upper;
450
+ }
451
+
452
+ return false;
453
+ }
454
+
455
+ /**
456
+ * Gets a list of function definitions for a specified variable.
457
+ * @param {Variable} variable eslint-scope variable object.
458
+ * @returns {ASTNode[]} Function nodes.
459
+ * @private
460
+ */
461
+ function getFunctionDefinitions(variable) {
462
+ const functionDefinitions = [];
463
+
464
+ variable.defs.forEach(def => {
465
+ const { type, node } = def;
466
+
467
+ // FunctionDeclarations
468
+ if (type === "FunctionName") {
469
+ functionDefinitions.push(node);
470
+ }
471
+
472
+ // FunctionExpressions
473
+ if (
474
+ type === "Variable" &&
475
+ node.init &&
476
+ (node.init.type === "FunctionExpression" ||
477
+ node.init.type === "ArrowFunctionExpression")
478
+ ) {
479
+ functionDefinitions.push(node.init);
480
+ }
481
+ });
482
+ return functionDefinitions;
483
+ }
484
+
485
+ /**
486
+ * Checks the position of given nodes.
487
+ * @param {ASTNode} inner A node which is expected as inside.
488
+ * @param {ASTNode} outer A node which is expected as outside.
489
+ * @returns {boolean} `true` if the `inner` node exists in the `outer` node.
490
+ * @private
491
+ */
492
+ function isInside(inner, outer) {
493
+ return (
494
+ inner.range[0] >= outer.range[0] &&
495
+ inner.range[1] <= outer.range[1]
496
+ );
497
+ }
498
+
499
+ /**
500
+ * Checks whether a given node is unused expression or not.
501
+ * @param {ASTNode} node The node itself
502
+ * @returns {boolean} The node is an unused expression.
503
+ * @private
504
+ */
505
+ function isUnusedExpression(node) {
506
+ const parent = node.parent;
507
+
508
+ if (parent.type === "ExpressionStatement") {
509
+ return true;
510
+ }
511
+
512
+ if (parent.type === "SequenceExpression") {
513
+ const isLastExpression = parent.expressions.at(-1) === node;
514
+
515
+ if (!isLastExpression) {
516
+ return true;
517
+ }
518
+ return isUnusedExpression(parent);
519
+ }
520
+
521
+ return false;
522
+ }
523
+
524
+ /**
525
+ * If a given reference is left-hand side of an assignment, this gets
526
+ * the right-hand side node of the assignment.
527
+ *
528
+ * In the following cases, this returns null.
529
+ *
530
+ * - The reference is not the LHS of an assignment expression.
531
+ * - The reference is inside of a loop.
532
+ * - The reference is inside of a function scope which is different from
533
+ * the declaration.
534
+ * @param {Reference} ref A reference to check.
535
+ * @param {ASTNode} prevRhsNode The previous RHS node.
536
+ * @returns {ASTNode|null} The RHS node or null.
537
+ * @private
538
+ */
539
+ function getRhsNode(ref, prevRhsNode) {
540
+ const id = ref.identifier;
541
+ const parent = id.parent;
542
+ const refScope = ref.from.variableScope;
543
+ const varScope = ref.resolved.scope.variableScope;
544
+ const canBeUsedLater =
545
+ refScope !== varScope || astUtils.isInLoop(id);
546
+
547
+ /*
548
+ * Inherits the previous node if this reference is in the node.
549
+ * This is for `a = a + a`-like code.
550
+ */
551
+ if (prevRhsNode && isInside(id, prevRhsNode)) {
552
+ return prevRhsNode;
553
+ }
554
+
555
+ if (
556
+ parent.type === "AssignmentExpression" &&
557
+ isUnusedExpression(parent) &&
558
+ id === parent.left &&
559
+ !canBeUsedLater
560
+ ) {
561
+ return parent.right;
562
+ }
563
+ return null;
564
+ }
565
+
566
+ /**
567
+ * Checks whether a given function node is stored to somewhere or not.
568
+ * If the function node is stored, the function can be used later.
569
+ * @param {ASTNode} funcNode A function node to check.
570
+ * @param {ASTNode} rhsNode The RHS node of the previous assignment.
571
+ * @returns {boolean} `true` if under the following conditions:
572
+ * - the funcNode is assigned to a variable.
573
+ * - the funcNode is bound as an argument of a function call.
574
+ * - the function is bound to a property and the object satisfies above conditions.
575
+ * @private
576
+ */
577
+ function isStorableFunction(funcNode, rhsNode) {
578
+ let node = funcNode;
579
+ let parent = funcNode.parent;
580
+
581
+ while (parent && isInside(parent, rhsNode)) {
582
+ switch (parent.type) {
583
+ case "SequenceExpression":
584
+ if (parent.expressions.at(-1) !== node) {
585
+ return false;
586
+ }
587
+ break;
588
+
589
+ case "CallExpression":
590
+ case "NewExpression":
591
+ return parent.callee !== node;
592
+
593
+ case "AssignmentExpression":
594
+ case "TaggedTemplateExpression":
595
+ case "YieldExpression":
596
+ return true;
597
+
598
+ default:
599
+ if (STATEMENT_TYPE.test(parent.type)) {
600
+ /*
601
+ * If it encountered statements, this is a complex pattern.
602
+ * Since analyzing complex patterns is hard, this returns `true` to avoid false positive.
603
+ */
604
+ return true;
605
+ }
606
+ }
607
+
608
+ node = parent;
609
+ parent = parent.parent;
610
+ }
611
+
612
+ return false;
613
+ }
614
+
615
+ /**
616
+ * Checks whether a given Identifier node exists inside of a function node which can be used later.
617
+ *
618
+ * "can be used later" means:
619
+ * - the function is assigned to a variable.
620
+ * - the function is bound to a property and the object can be used later.
621
+ * - the function is bound as an argument of a function call.
622
+ *
623
+ * If a reference exists in a function which can be used later, the reference is read when the function is called.
624
+ * @param {ASTNode} id An Identifier node to check.
625
+ * @param {ASTNode} rhsNode The RHS node of the previous assignment.
626
+ * @returns {boolean} `true` if the `id` node exists inside of a function node which can be used later.
627
+ * @private
628
+ */
629
+ function isInsideOfStorableFunction(id, rhsNode) {
630
+ const funcNode = astUtils.getUpperFunction(id);
631
+
632
+ return (
633
+ funcNode &&
634
+ isInside(funcNode, rhsNode) &&
635
+ isStorableFunction(funcNode, rhsNode)
636
+ );
637
+ }
638
+
639
+ /**
640
+ * Checks whether a given reference is a read to update itself or not.
641
+ * @param {Reference} ref A reference to check.
642
+ * @param {ASTNode} rhsNode The RHS node of the previous assignment.
643
+ * @returns {boolean} The reference is a read to update itself.
644
+ * @private
645
+ */
646
+ function isReadForItself(ref, rhsNode) {
647
+ const id = ref.identifier;
648
+ const parent = id.parent;
649
+
650
+ return (
651
+ ref.isRead() &&
652
+ // self update. e.g. `a += 1`, `a++`
653
+ ((parent.type === "AssignmentExpression" &&
654
+ parent.left === id &&
655
+ isUnusedExpression(parent) &&
656
+ !astUtils.isLogicalAssignmentOperator(parent.operator)) ||
657
+ (parent.type === "UpdateExpression" &&
658
+ isUnusedExpression(parent)) ||
659
+ // in RHS of an assignment for itself. e.g. `a = a + 1`
660
+ (rhsNode &&
661
+ isInside(id, rhsNode) &&
662
+ !isInsideOfStorableFunction(id, rhsNode)))
663
+ );
664
+ }
665
+
666
+ /**
667
+ * Determine if an identifier is used either in for-in or for-of loops.
668
+ * @param {Reference} ref The reference to check.
669
+ * @returns {boolean} whether reference is used in the for-in loops
670
+ * @private
671
+ */
672
+ function isForInOfRef(ref) {
673
+ let target = ref.identifier.parent;
674
+
675
+ // "for (var ...) { return; }"
676
+ if (target.type === "VariableDeclarator") {
677
+ target = target.parent.parent;
678
+ }
679
+
680
+ if (
681
+ target.type !== "ForInStatement" &&
682
+ target.type !== "ForOfStatement"
683
+ ) {
684
+ return false;
685
+ }
686
+
687
+ // "for (...) { return; }"
688
+ if (target.body.type === "BlockStatement") {
689
+ target = target.body.body[0];
690
+
691
+ // "for (...) return;"
692
+ } else {
693
+ target = target.body;
694
+ }
695
+
696
+ // For empty loop body
697
+ if (!target) {
698
+ return false;
699
+ }
700
+
701
+ return target.type === "ReturnStatement";
702
+ }
703
+
704
+ /**
705
+ * Determines if the variable is used.
706
+ * @param {Variable} variable The variable to check.
707
+ * @returns {boolean} True if the variable is used
708
+ * @private
709
+ */
710
+ function isUsedVariable(variable) {
711
+ if (variable.eslintUsed) {
712
+ return true;
713
+ }
714
+
715
+ const functionNodes = getFunctionDefinitions(variable);
716
+ const isFunctionDefinition = functionNodes.length > 0;
717
+
718
+ let rhsNode = null;
719
+
720
+ return variable.references.some(ref => {
721
+ if (isForInOfRef(ref)) {
722
+ return true;
723
+ }
724
+
725
+ const forItself = isReadForItself(ref, rhsNode);
726
+
727
+ rhsNode = getRhsNode(ref, rhsNode);
728
+
729
+ return (
730
+ isReadRef(ref) &&
731
+ !forItself &&
732
+ !(
733
+ isFunctionDefinition &&
734
+ isSelfReference(ref, functionNodes)
735
+ )
736
+ );
737
+ });
738
+ }
739
+
740
+ /**
741
+ * Checks whether the given variable is after the last used parameter.
742
+ * @param {Variable} variable The variable to check.
743
+ * @returns {boolean} `true` if the variable is defined after the last
744
+ * used parameter.
745
+ */
746
+ function isAfterLastUsedArg(variable) {
747
+ const def = variable.defs[0];
748
+ const params = sourceCode.getDeclaredVariables(def.node);
749
+ const posteriorParams = params.slice(params.indexOf(variable) + 1);
750
+
751
+ // If any used parameters occur after this parameter, do not report.
752
+ return !posteriorParams.some(
753
+ v => v.references.length > 0 || v.eslintUsed,
754
+ );
755
+ }
756
+
757
+ /**
758
+ * Gets an array of variables without read references.
759
+ * @param {Scope} scope an eslint-scope Scope object.
760
+ * @param {Variable[]} unusedVars an array that saving result.
761
+ * @returns {Variable[]} unused variables of the scope and descendant scopes.
762
+ * @private
763
+ */
764
+ function collectUnusedVariables(scope, unusedVars) {
765
+ const variables = scope.variables;
766
+ const childScopes = scope.childScopes;
767
+ let i, l;
768
+
769
+ if (scope.type !== "global" || config.vars === "all") {
770
+ for (i = 0, l = variables.length; i < l; ++i) {
771
+ const variable = variables[i];
772
+
773
+ // skip a variable of class itself name in the class scope
774
+ if (
775
+ scope.type === "class" &&
776
+ scope.block.id === variable.identifiers[0]
777
+ ) {
778
+ continue;
779
+ }
780
+
781
+ // skip function expression names
782
+ if (scope.functionExpressionScope) {
783
+ continue;
784
+ }
785
+
786
+ // skip variables marked with markVariableAsUsed()
787
+ if (
788
+ !config.reportUsedIgnorePattern &&
789
+ variable.eslintUsed
790
+ ) {
791
+ continue;
792
+ }
793
+
794
+ // skip implicit "arguments" variable
795
+ if (
796
+ scope.type === "function" &&
797
+ variable.name === "arguments" &&
798
+ variable.identifiers.length === 0
799
+ ) {
800
+ continue;
801
+ }
802
+
803
+ // explicit global variables don't have definitions.
804
+ const def = variable.defs[0];
805
+
806
+ if (def) {
807
+ const type = def.type;
808
+ const refUsedInArrayPatterns = variable.references.some(
809
+ ref =>
810
+ ref.identifier.parent.type === "ArrayPattern",
811
+ );
812
+
813
+ // skip elements of array destructuring patterns
814
+ if (
815
+ (def.name.parent.type === "ArrayPattern" ||
816
+ refUsedInArrayPatterns) &&
817
+ config.destructuredArrayIgnorePattern &&
818
+ config.destructuredArrayIgnorePattern.test(
819
+ def.name.name,
820
+ )
821
+ ) {
822
+ if (
823
+ config.reportUsedIgnorePattern &&
824
+ isUsedVariable(variable)
825
+ ) {
826
+ context.report({
827
+ node: def.name,
828
+ messageId: "usedIgnoredVar",
829
+ data: getUsedIgnoredMessageData(
830
+ variable,
831
+ "array-destructure",
832
+ ),
833
+ });
834
+ }
835
+
836
+ continue;
837
+ }
838
+
839
+ if (type === "ClassName") {
840
+ const hasStaticBlock = def.node.body.body.some(
841
+ node => node.type === "StaticBlock",
842
+ );
843
+
844
+ if (
845
+ config.ignoreClassWithStaticInitBlock &&
846
+ hasStaticBlock
847
+ ) {
848
+ continue;
849
+ }
850
+ }
851
+
852
+ // skip catch variables
853
+ if (type === "CatchClause") {
854
+ if (config.caughtErrors === "none") {
855
+ continue;
856
+ }
857
+
858
+ // skip ignored parameters
859
+ if (
860
+ config.caughtErrorsIgnorePattern &&
861
+ config.caughtErrorsIgnorePattern.test(
862
+ def.name.name,
863
+ )
864
+ ) {
865
+ if (
866
+ config.reportUsedIgnorePattern &&
867
+ isUsedVariable(variable)
868
+ ) {
869
+ context.report({
870
+ node: def.name,
871
+ messageId: "usedIgnoredVar",
872
+ data: getUsedIgnoredMessageData(
873
+ variable,
874
+ "catch-clause",
875
+ ),
876
+ });
877
+ }
878
+
879
+ continue;
880
+ }
881
+ } else if (type === "Parameter") {
882
+ // skip any setter argument
883
+ if (
884
+ (def.node.parent.type === "Property" ||
885
+ def.node.parent.type ===
886
+ "MethodDefinition") &&
887
+ def.node.parent.kind === "set"
888
+ ) {
889
+ continue;
890
+ }
891
+
892
+ // if "args" option is "none", skip any parameter
893
+ if (config.args === "none") {
894
+ continue;
895
+ }
896
+
897
+ // skip ignored parameters
898
+ if (
899
+ config.argsIgnorePattern &&
900
+ config.argsIgnorePattern.test(def.name.name)
901
+ ) {
902
+ if (
903
+ config.reportUsedIgnorePattern &&
904
+ isUsedVariable(variable)
905
+ ) {
906
+ context.report({
907
+ node: def.name,
908
+ messageId: "usedIgnoredVar",
909
+ data: getUsedIgnoredMessageData(
910
+ variable,
911
+ "parameter",
912
+ ),
913
+ });
914
+ }
915
+
916
+ continue;
917
+ }
918
+
919
+ // if "args" option is "after-used", skip used variables
920
+ if (
921
+ config.args === "after-used" &&
922
+ astUtils.isFunction(def.name.parent) &&
923
+ !isAfterLastUsedArg(variable)
924
+ ) {
925
+ continue;
926
+ }
927
+ } else {
928
+ // skip ignored variables
929
+ if (
930
+ config.varsIgnorePattern &&
931
+ config.varsIgnorePattern.test(def.name.name)
932
+ ) {
933
+ if (
934
+ config.reportUsedIgnorePattern &&
935
+ isUsedVariable(variable)
936
+ ) {
937
+ context.report({
938
+ node: def.name,
939
+ messageId: "usedIgnoredVar",
940
+ data: getUsedIgnoredMessageData(
941
+ variable,
942
+ "variable",
943
+ ),
944
+ });
945
+ }
946
+
947
+ continue;
948
+ }
949
+ }
950
+ }
951
+
952
+ if (
953
+ !isUsedVariable(variable) &&
954
+ !isExported(variable) &&
955
+ !(
956
+ config.ignoreUsingDeclarations &&
957
+ usesExplicitResourceManagement(variable)
958
+ ) &&
959
+ !hasRestSpreadSibling(variable)
960
+ ) {
961
+ unusedVars.push(variable);
962
+ }
963
+ }
964
+ }
965
+
966
+ for (i = 0, l = childScopes.length; i < l; ++i) {
967
+ collectUnusedVariables(childScopes[i], unusedVars);
968
+ }
969
+
970
+ return unusedVars;
971
+ }
972
+
973
+ /**
974
+ * fixes unused variables
975
+ * @param {Object} fixer fixer object
976
+ * @param {Object} unusedVar unused variable to fix
977
+ * @returns {Object} fixer object
978
+ */
979
+ function handleFixes(fixer, unusedVar) {
980
+ const id = unusedVar.identifiers[0];
981
+ const parent = id.parent;
982
+ const parentType = parent.type;
983
+ const tokenBefore = sourceCode.getTokenBefore(id);
984
+ const tokenAfter = sourceCode.getTokenAfter(id);
985
+ const isFunction = astUtils.isFunction;
986
+ const isLoop = astUtils.isLoop;
987
+ const allWriteReferences = unusedVar.references.filter(ref =>
988
+ ref.isWrite(),
989
+ );
990
+
991
+ /**
992
+ * get range from token before of a given node
993
+ * @param {ASTNode} node node of identifier
994
+ * @param {number} skips number of token to skip
995
+ * @returns {number} start range of token before the identifier
996
+ */
997
+ function getPreviousTokenStart(node, skips) {
998
+ return sourceCode.getTokenBefore(node, skips).range[0];
999
+ }
1000
+
1001
+ /**
1002
+ * get range to token after of a given node
1003
+ * @param {ASTNode} node node of identifier
1004
+ * @param {number} skips number of token to skip
1005
+ * @returns {number} end range of token after the identifier
1006
+ */
1007
+ function getNextTokenEnd(node, skips) {
1008
+ return sourceCode.getTokenAfter(node, skips).range[1];
1009
+ }
1010
+
1011
+ /**
1012
+ * get the value of token before of a given node
1013
+ * @param {ASTNode} node node of identifier
1014
+ * @returns {string} value of token before the identifier
1015
+ */
1016
+ function getTokenBeforeValue(node) {
1017
+ return sourceCode.getTokenBefore(node).value;
1018
+ }
1019
+
1020
+ /**
1021
+ * get the value of token after of a given node
1022
+ * @param {ASTNode} node node of identifier
1023
+ * @returns {string} value of token after the identifier
1024
+ */
1025
+ function getTokenAfterValue(node) {
1026
+ return sourceCode.getTokenAfter(node).value;
1027
+ }
1028
+
1029
+ /**
1030
+ * Check if an array has a single element with null as other element.
1031
+ * @param {ASTNode} node ArrayPattern node
1032
+ * @returns {boolean} true if array has single element with other null elements
1033
+ */
1034
+ function hasSingleElement(node) {
1035
+ return node.elements.filter(e => e !== null).length === 1;
1036
+ }
1037
+
1038
+ /**
1039
+ * check whether import specifier has an import of particular type
1040
+ * @param {ASTNode} node ImportDeclaration node
1041
+ * @param {string} type type of import to check
1042
+ * @returns {boolean} true if import specifier has import of specified type
1043
+ */
1044
+ function hasImportOfCertainType(node, type) {
1045
+ return node.specifiers.some(e => e.type === type);
1046
+ }
1047
+
1048
+ /**
1049
+ * Check whether declaration is safe to remove or not
1050
+ * @param {ASTNode} nextToken next token of unused variable
1051
+ * @param {ASTNode} prevToken previous token of unused variable
1052
+ * @returns {boolean} true if declaration is not safe to remove
1053
+ */
1054
+ function isDeclarationNotSafeToRemove(nextToken, prevToken) {
1055
+ return (
1056
+ nextToken.type === "String" ||
1057
+ (prevToken &&
1058
+ !astUtils.isSemicolonToken(prevToken) &&
1059
+ !astUtils.isOpeningBraceToken(prevToken))
1060
+ );
1061
+ }
1062
+
1063
+ /**
1064
+ * give fixes for unused variables in function parameters
1065
+ * @param {ASTNode} node node to check
1066
+ * @returns {Object} fixer object
1067
+ */
1068
+ function fixFunctionParameters(node) {
1069
+ const parentNode = node.parent;
1070
+
1071
+ if (isFunction(parentNode)) {
1072
+ // remove unused function parameter if there is only a single parameter
1073
+ if (parentNode.params.length === 1) {
1074
+ return fixer.removeRange(node.range);
1075
+ }
1076
+
1077
+ // remove first unused function parameter when there are multiple parameters
1078
+ if (
1079
+ getTokenBeforeValue(node) === "(" &&
1080
+ getTokenAfterValue(node) === ","
1081
+ ) {
1082
+ return fixer.removeRange([
1083
+ node.range[0],
1084
+ getNextTokenEnd(node),
1085
+ ]);
1086
+ }
1087
+
1088
+ // remove unused function parameters except first one when there are multiple parameters
1089
+ return fixer.removeRange([
1090
+ getPreviousTokenStart(node),
1091
+ node.range[1],
1092
+ ]);
1093
+ }
1094
+
1095
+ return null;
1096
+ }
1097
+
1098
+ /**
1099
+ * fix unused variable declarations and function parameters
1100
+ * @param {ASTNode} node parent node to identifier
1101
+ * @returns {Object} fixer object
1102
+ */
1103
+ function fixVariables(node) {
1104
+ const parentNode = node.parent;
1105
+
1106
+ // remove unused declared variables such as var a = b; or var a = b, c;
1107
+ if (parentNode.type === "VariableDeclarator") {
1108
+ // skip variable in for (const [ foo ] of bar);
1109
+ if (isLoop(parentNode.parent.parent)) {
1110
+ return null;
1111
+ }
1112
+
1113
+ /*
1114
+ * remove unused declared variable with single declaration such as 'var a = b;'
1115
+ * remove complete declaration when there is an unused variable in 'const { a } = foo;', same for arrays.
1116
+ */
1117
+ if (parentNode.parent.declarations.length === 1) {
1118
+ // if next token is a string it could become a directive if node is removed -> no suggestion.
1119
+ const nextToken = sourceCode.getTokenAfter(
1120
+ parentNode.parent,
1121
+ );
1122
+
1123
+ // if previous token exists and is not ";" or "{" not sure about ASI rules -> no suggestion.
1124
+ const prevToken = sourceCode.getTokenBefore(
1125
+ parentNode.parent,
1126
+ );
1127
+
1128
+ if (
1129
+ nextToken &&
1130
+ isDeclarationNotSafeToRemove(nextToken, prevToken)
1131
+ ) {
1132
+ return null;
1133
+ }
1134
+
1135
+ return fixer.removeRange(parentNode.parent.range);
1136
+ }
1137
+
1138
+ /*
1139
+ * remove unused declared variable with multiple declaration except first one such as 'var a = b, c = d;'
1140
+ * fix 'let bar = "hello", { a } = foo;' to 'let bar = "hello";' if 'a' is unused, same for arrays.
1141
+ */
1142
+ if (getTokenBeforeValue(parentNode) === ",") {
1143
+ return fixer.removeRange([
1144
+ getPreviousTokenStart(parentNode),
1145
+ parentNode.range[1],
1146
+ ]);
1147
+ }
1148
+
1149
+ /*
1150
+ * remove first unused declared variable when there are multiple declarations
1151
+ * fix 'let { a } = foo, bar = "hello";' to 'let bar = "hello";' if 'a' is unused, same for arrays.
1152
+ */
1153
+ return fixer.removeRange([
1154
+ parentNode.range[0],
1155
+ getNextTokenEnd(parentNode),
1156
+ ]);
1157
+ }
1158
+
1159
+ // fixes [{a: {k}}], [{a: [k]}]
1160
+ if (getTokenBeforeValue(node) === ":") {
1161
+ if (parentNode.parent.type === "ObjectPattern") {
1162
+ // eslint-disable-next-line no-use-before-define -- due to interdependency of functions
1163
+ return fixObjectWithValueSeparator(node);
1164
+ }
1165
+ }
1166
+
1167
+ // fix unused function parameters
1168
+ return fixFunctionParameters(node);
1169
+ }
1170
+
1171
+ /**
1172
+ * fix nested object like { a: { b } }
1173
+ * @param {ASTNode} node parent node to check
1174
+ * @returns {Object} fixer object
1175
+ */
1176
+ function fixNestedObjectVariable(node) {
1177
+ const parentNode = node.parent;
1178
+
1179
+ // fix for { a: { b: { c: { d } } } }
1180
+ if (
1181
+ parentNode.parent.parent.parent.type === "ObjectPattern" &&
1182
+ parentNode.parent.properties.length === 1
1183
+ ) {
1184
+ return fixNestedObjectVariable(parentNode.parent);
1185
+ }
1186
+
1187
+ // fix for { a: { b } }
1188
+ if (parentNode.parent.type === "ObjectPattern") {
1189
+ // fix for unused variables in destructured object with single property in variable declaration and function parameter
1190
+ if (parentNode.parent.properties.length === 1) {
1191
+ return fixVariables(parentNode.parent);
1192
+ }
1193
+
1194
+ // fix for first unused property when there are multiple properties such as '{ a: { b }, c }'
1195
+ if (getTokenBeforeValue(parentNode) === "{") {
1196
+ return fixer.removeRange([
1197
+ parentNode.range[0],
1198
+ getNextTokenEnd(parentNode),
1199
+ ]);
1200
+ }
1201
+
1202
+ // fix for unused property except first one when there are multiple properties such as '{ k, a: { b } }'
1203
+ return fixer.removeRange([
1204
+ getPreviousTokenStart(parentNode),
1205
+ parentNode.range[1],
1206
+ ]);
1207
+ }
1208
+
1209
+ return null;
1210
+ }
1211
+
1212
+ /**
1213
+ * fix unused variables in array and nested array
1214
+ * @param {ASTNode} node parent node to check
1215
+ * @returns {Object} fixer object
1216
+ */
1217
+ function fixNestedArrayVariable(node) {
1218
+ const parentNode = node.parent;
1219
+
1220
+ // fix for nested arrays [[ a ]]
1221
+ if (
1222
+ parentNode.parent.type === "ArrayPattern" &&
1223
+ hasSingleElement(parentNode)
1224
+ ) {
1225
+ return fixNestedArrayVariable(parentNode);
1226
+ }
1227
+
1228
+ if (hasSingleElement(parentNode)) {
1229
+ // fixes { a: [{ b }] } or { a: [[ b ]] }
1230
+ if (getTokenBeforeValue(parentNode) === ":") {
1231
+ return fixVariables(parentNode);
1232
+ }
1233
+
1234
+ // fixes [a, ...[[ b ]]] or [a, ...[{ b }]]
1235
+ if (parentNode.parent.type === "RestElement") {
1236
+ // eslint-disable-next-line no-use-before-define -- due to interdependency of functions
1237
+ return fixRestInPattern(parentNode.parent);
1238
+ }
1239
+
1240
+ // fix unused variables in destructured array in variable declaration or function parameter
1241
+ return fixVariables(parentNode);
1242
+ }
1243
+
1244
+ // remove last unused array element
1245
+ if (
1246
+ getTokenBeforeValue(node) === "," &&
1247
+ getTokenAfterValue(node) === "]"
1248
+ ) {
1249
+ return fixer.removeRange([
1250
+ getPreviousTokenStart(node),
1251
+ node.range[1],
1252
+ ]);
1253
+ }
1254
+
1255
+ // remove unused array element
1256
+ return fixer.removeRange(node.range);
1257
+ }
1258
+
1259
+ /**
1260
+ * fix cases like {a: {k}} or {a: [k]}
1261
+ * @param {ASTNode} node parent node to check
1262
+ * @returns {Object} fixer object
1263
+ */
1264
+ function fixObjectWithValueSeparator(node) {
1265
+ const parentNode = node.parent.parent;
1266
+
1267
+ // fix cases like [{a : { b }}] or [{a : [ b ]}]
1268
+ if (
1269
+ parentNode.parent.type === "ArrayPattern" &&
1270
+ parentNode.properties.length === 1
1271
+ ) {
1272
+ return fixNestedArrayVariable(parentNode);
1273
+ }
1274
+
1275
+ // fix cases like {a: {k}} or {a: [k]}
1276
+ return fixNestedObjectVariable(node);
1277
+ }
1278
+
1279
+ /**
1280
+ * fix ...[[a]] or ...[{a}] like patterns
1281
+ * @param {ASTNode} node parent node to check
1282
+ * @returns {Object} fixer object
1283
+ */
1284
+ function fixRestInPattern(node) {
1285
+ const parentNode = node.parent;
1286
+
1287
+ // fix ...[[a]] or ...[{a}] in function parameters
1288
+ if (isFunction(parentNode)) {
1289
+ if (parentNode.params.length === 1) {
1290
+ return fixer.removeRange(node.range);
1291
+ }
1292
+
1293
+ return fixer.removeRange([
1294
+ getPreviousTokenStart(node),
1295
+ node.range[1],
1296
+ ]);
1297
+ }
1298
+
1299
+ // fix rest in nested array pattern like [[a, ...[b]]]
1300
+ if (parentNode.type === "ArrayPattern") {
1301
+ // fix [[...[b]]]
1302
+ if (hasSingleElement(parentNode)) {
1303
+ if (parentNode.parent.type === "ArrayPattern") {
1304
+ return fixNestedArrayVariable(parentNode);
1305
+ }
1306
+
1307
+ // fix 'const [...[b]] = foo; and function foo([...[b]]) {}
1308
+ return fixVariables(parentNode);
1309
+ }
1310
+
1311
+ // fix [[a, ...[b]]]
1312
+ return fixer.removeRange([
1313
+ getPreviousTokenStart(node),
1314
+ node.range[1],
1315
+ ]);
1316
+ }
1317
+
1318
+ return null;
1319
+ }
1320
+
1321
+ // skip fix when variable has references that would be left behind
1322
+ if (
1323
+ allWriteReferences.some(
1324
+ ref => ref.identifier.range[0] !== id.range[0],
1325
+ )
1326
+ ) {
1327
+ return null;
1328
+ }
1329
+
1330
+ // remove declared variables such as var a; or var a, b;
1331
+ if (parentType === "VariableDeclarator") {
1332
+ if (parent.parent.declarations.length === 1) {
1333
+ // prevent fix of variable in forOf and forIn loops.
1334
+ if (
1335
+ isLoop(parent.parent.parent) &&
1336
+ parent.parent.parent.body !== parent.parent
1337
+ ) {
1338
+ return null;
1339
+ }
1340
+
1341
+ // removes only variable not semicolon in 'if (foo()) var bar;' or in 'loops' or in 'with' statement.
1342
+ if (
1343
+ parent.parent.parent.type === "IfStatement" ||
1344
+ isLoop(parent.parent.parent) ||
1345
+ (parent.parent.parent.type === "WithStatement" &&
1346
+ parent.parent.parent.body === parent.parent)
1347
+ ) {
1348
+ return fixer.replaceText(parent.parent, ";");
1349
+ }
1350
+
1351
+ // if next token is a string it could become a directive if node is removed -> no suggestion.
1352
+ const nextToken = sourceCode.getTokenAfter(parent.parent);
1353
+
1354
+ // if previous token exists and is not ";" or "{" not sure about ASI rules -> no suggestion.
1355
+ const prevToken = sourceCode.getTokenBefore(parent.parent);
1356
+
1357
+ if (
1358
+ nextToken &&
1359
+ isDeclarationNotSafeToRemove(nextToken, prevToken)
1360
+ ) {
1361
+ return null;
1362
+ }
1363
+
1364
+ // remove unused declared variable with single declaration like 'var a = b;'
1365
+ return fixer.removeRange(parent.parent.range);
1366
+ }
1367
+
1368
+ // remove unused declared variable with multiple declaration except first one like 'var a = b, c = d;'
1369
+ if (tokenBefore.value === ",") {
1370
+ return fixer.removeRange([
1371
+ tokenBefore.range[0],
1372
+ parent.range[1],
1373
+ ]);
1374
+ }
1375
+
1376
+ // remove first unused declared variable when there are multiple declarations
1377
+ return fixer.removeRange([
1378
+ parent.range[0],
1379
+ getNextTokenEnd(parent),
1380
+ ]);
1381
+ }
1382
+
1383
+ // remove variables in object patterns
1384
+ if (parent.parent.type === "ObjectPattern") {
1385
+ if (parent.parent.properties.length === 1) {
1386
+ // fix [a, ...{b}]
1387
+ if (parent.parent.parent.type === "RestElement") {
1388
+ return fixRestInPattern(parent.parent.parent);
1389
+ }
1390
+
1391
+ // fix [{ a }]
1392
+ if (parent.parent.parent.type === "ArrayPattern") {
1393
+ return fixNestedArrayVariable(parent.parent);
1394
+ }
1395
+
1396
+ /*
1397
+ * var {a} = foo;
1398
+ * function a({a}) {}
1399
+ * fix const { a: { b } } = foo;
1400
+ */
1401
+ return fixVariables(parent.parent);
1402
+ }
1403
+
1404
+ // fix const { a:b } = foo;
1405
+ if (tokenBefore.value === ":") {
1406
+ // remove first unused variable in const { a:b } = foo;
1407
+ if (
1408
+ getTokenBeforeValue(parent) === "{" &&
1409
+ getTokenAfterValue(parent) === ","
1410
+ ) {
1411
+ return fixer.removeRange([
1412
+ parent.range[0],
1413
+ getNextTokenEnd(parent),
1414
+ ]);
1415
+ }
1416
+
1417
+ // remove unused variables in const { a: b, c: d } = foo; except first one
1418
+ return fixer.removeRange([
1419
+ getPreviousTokenStart(parent),
1420
+ id.range[1],
1421
+ ]);
1422
+ }
1423
+ }
1424
+
1425
+ // remove unused variables inside an array
1426
+ if (parentType === "ArrayPattern") {
1427
+ if (hasSingleElement(parent)) {
1428
+ // fix [a, ...[b]]
1429
+ if (parent.parent.type === "RestElement") {
1430
+ return fixRestInPattern(parent.parent);
1431
+ }
1432
+
1433
+ // fix [ [a] ]
1434
+ if (parent.parent.type === "ArrayPattern") {
1435
+ return fixNestedArrayVariable(parent);
1436
+ }
1437
+
1438
+ /*
1439
+ * fix var [a] = foo;
1440
+ * fix function foo([a]) {}
1441
+ * fix const { a: [b] } = foo;
1442
+ */
1443
+ return fixVariables(parent);
1444
+ }
1445
+
1446
+ // if "a" is unused in [a, b ,c] fixes to [, b, c]
1447
+ if (tokenBefore.value === "," && tokenAfter.value === ",") {
1448
+ return fixer.removeRange(id.range);
1449
+ }
1450
+ }
1451
+
1452
+ // remove unused rest elements
1453
+ if (parentType === "RestElement") {
1454
+ // fix [a, ...rest]
1455
+ if (parent.parent.type === "ArrayPattern") {
1456
+ if (hasSingleElement(parent.parent)) {
1457
+ // fix [[...rest]] when there is only rest element
1458
+ if (parent.parent.parent.type === "ArrayPattern") {
1459
+ return fixNestedArrayVariable(parent.parent);
1460
+ }
1461
+
1462
+ // fix 'const [...rest] = foo;' and 'function foo([...rest]) {}'
1463
+ return fixVariables(parent.parent);
1464
+ }
1465
+
1466
+ // fix [a, ...rest]
1467
+ return fixer.removeRange([
1468
+ getPreviousTokenStart(id, 1),
1469
+ id.range[1],
1470
+ ]);
1471
+ }
1472
+
1473
+ // fix { a, ...rest}
1474
+ if (parent.parent.type === "ObjectPattern") {
1475
+ // fix 'const {...rest} = foo;' and 'function foo({...rest}) {}'
1476
+ if (parent.parent.properties.length === 1) {
1477
+ return fixVariables(parent.parent);
1478
+ }
1479
+
1480
+ // fix { a, ...rest} when there are multiple properties
1481
+ return fixer.removeRange([
1482
+ getPreviousTokenStart(id, 1),
1483
+ id.range[1],
1484
+ ]);
1485
+ }
1486
+
1487
+ // fix function foo(...rest) {}
1488
+ if (isFunction(parent.parent)) {
1489
+ // remove unused rest in function parameter if there is only single parameter
1490
+ if (parent.parent.params.length === 1) {
1491
+ return fixer.removeRange(parent.range);
1492
+ }
1493
+
1494
+ // remove unused rest in function parameter if there multiple parameter
1495
+ return fixer.removeRange([
1496
+ getPreviousTokenStart(parent),
1497
+ parent.range[1],
1498
+ ]);
1499
+ }
1500
+ }
1501
+
1502
+ if (parentType === "AssignmentPattern") {
1503
+ // fix [a = aDefault]
1504
+ if (parent.parent.type === "ArrayPattern") {
1505
+ return fixNestedArrayVariable(parent);
1506
+ }
1507
+
1508
+ // fix {a = aDefault}
1509
+ if (parent.parent.parent.type === "ObjectPattern") {
1510
+ if (parent.parent.parent.properties.length === 1) {
1511
+ // fixes [{a = aDefault}]
1512
+ if (
1513
+ parent.parent.parent.parent.type === "ArrayPattern"
1514
+ ) {
1515
+ return fixNestedArrayVariable(parent.parent.parent);
1516
+ }
1517
+
1518
+ // fix 'const {a = aDefault} = foo;' and 'function foo({a = aDefault}) {}'
1519
+ return fixVariables(parent.parent.parent);
1520
+ }
1521
+
1522
+ // fix unused 'a' in {a = aDefault} if it is the first property
1523
+ if (
1524
+ getTokenBeforeValue(parent.parent) === "{" &&
1525
+ getTokenAfterValue(parent.parent) === ","
1526
+ ) {
1527
+ return fixer.removeRange([
1528
+ parent.parent.range[0],
1529
+ getNextTokenEnd(parent.parent),
1530
+ ]);
1531
+ }
1532
+
1533
+ // fix unused 'b' in {a, b = aDefault} if it is not the first property
1534
+ return fixer.removeRange([
1535
+ getPreviousTokenStart(parent.parent),
1536
+ parent.parent.range[1],
1537
+ ]);
1538
+ }
1539
+
1540
+ // fix unused assignment patterns in function parameters
1541
+ if (isFunction(parent.parent)) {
1542
+ return fixFunctionParameters(parent);
1543
+ }
1544
+ }
1545
+
1546
+ // remove unused functions
1547
+ if (parentType === "FunctionDeclaration" && parent.id === id) {
1548
+ return fixer.removeRange(parent.range);
1549
+ }
1550
+
1551
+ // remove unused default import
1552
+ if (parentType === "ImportDefaultSpecifier") {
1553
+ // remove unused default import when there are not other imports
1554
+ if (
1555
+ !hasImportOfCertainType(parent.parent, "ImportSpecifier") &&
1556
+ !hasImportOfCertainType(
1557
+ parent.parent,
1558
+ "ImportNamespaceSpecifier",
1559
+ )
1560
+ ) {
1561
+ return fixer.removeRange([
1562
+ parent.range[0],
1563
+ parent.parent.source.range[0],
1564
+ ]);
1565
+ }
1566
+
1567
+ // remove unused default import when there are other imports also
1568
+ return fixer.removeRange([id.range[0], tokenAfter.range[1]]);
1569
+ }
1570
+
1571
+ if (parentType === "ImportSpecifier") {
1572
+ // remove unused imports when there is a single import
1573
+ if (
1574
+ parent.parent.specifiers.filter(
1575
+ e => e.type === "ImportSpecifier",
1576
+ ).length === 1
1577
+ ) {
1578
+ // remove unused import when there is no default import
1579
+ if (
1580
+ !hasImportOfCertainType(
1581
+ parent.parent,
1582
+ "ImportDefaultSpecifier",
1583
+ )
1584
+ ) {
1585
+ return fixer.removeRange(parent.parent.range);
1586
+ }
1587
+
1588
+ // fixes "import foo from 'module';" to "import 'module';"
1589
+ return fixer.removeRange([
1590
+ getPreviousTokenStart(parent, 1),
1591
+ tokenAfter.range[1],
1592
+ ]);
1593
+ }
1594
+
1595
+ if (getTokenBeforeValue(parent) === "{") {
1596
+ return fixer.removeRange([
1597
+ parent.range[0],
1598
+ getNextTokenEnd(parent),
1599
+ ]);
1600
+ }
1601
+
1602
+ return fixer.removeRange([
1603
+ getPreviousTokenStart(parent),
1604
+ parent.range[1],
1605
+ ]);
1606
+ }
1607
+
1608
+ if (parentType === "ImportNamespaceSpecifier") {
1609
+ if (
1610
+ hasImportOfCertainType(
1611
+ parent.parent,
1612
+ "ImportDefaultSpecifier",
1613
+ )
1614
+ ) {
1615
+ return fixer.removeRange([
1616
+ getPreviousTokenStart(parent),
1617
+ parent.range[1],
1618
+ ]);
1619
+ }
1620
+
1621
+ // fixes "import * as foo from 'module';" to "import 'module';"
1622
+ return fixer.removeRange([
1623
+ parent.range[0],
1624
+ parent.parent.source.range[0],
1625
+ ]);
1626
+ }
1627
+
1628
+ // skip error in catch(error) variable
1629
+ if (parentType === "CatchClause") {
1630
+ return null;
1631
+ }
1632
+
1633
+ // remove unused declared classes
1634
+ if (parentType === "ClassDeclaration") {
1635
+ return fixer.removeRange(parent.range);
1636
+ }
1637
+
1638
+ // remove unused variable that is in a sequence [a,b] fixes to [a]
1639
+ if (tokenBefore?.value === ",") {
1640
+ return fixer.removeRange([tokenBefore.range[0], id.range[1]]);
1641
+ }
1642
+
1643
+ // remove unused variable that is in a sequence inside function arguments and object pattern
1644
+ if (tokenAfter.value === ",") {
1645
+ // fix function foo(a, b) {}
1646
+ if (tokenBefore.value === "(") {
1647
+ return fixer.removeRange([
1648
+ id.range[0],
1649
+ tokenAfter.range[1],
1650
+ ]);
1651
+ }
1652
+
1653
+ // fix const {a, b} = foo;
1654
+ if (tokenBefore.value === "{") {
1655
+ return fixer.removeRange([
1656
+ id.range[0],
1657
+ tokenAfter.range[1],
1658
+ ]);
1659
+ }
1660
+ }
1661
+
1662
+ if (
1663
+ parentType === "ArrowFunctionExpression" &&
1664
+ parent.params.length === 1 &&
1665
+ tokenAfter?.value !== ")"
1666
+ ) {
1667
+ return fixer.replaceText(id, "()");
1668
+ }
1669
+
1670
+ return fixer.removeRange(id.range);
1671
+ }
1672
+
1673
+ //--------------------------------------------------------------------------
1674
+ // Public
1675
+ //--------------------------------------------------------------------------
1676
+
1677
+ return {
1678
+ "Program:exit"(programNode) {
1679
+ const unusedVars = collectUnusedVariables(
1680
+ sourceCode.getScope(programNode),
1681
+ [],
1682
+ );
1683
+
1684
+ for (let i = 0, l = unusedVars.length; i < l; ++i) {
1685
+ const unusedVar = unusedVars[i];
1686
+
1687
+ // Report the first declaration.
1688
+ if (unusedVar.defs.length > 0) {
1689
+ // report last write reference, https://github.com/eslint/eslint/issues/14324
1690
+ const writeReferences = unusedVar.references.filter(
1691
+ ref =>
1692
+ ref.isWrite() &&
1693
+ ref.from.variableScope ===
1694
+ unusedVar.scope.variableScope,
1695
+ );
1696
+
1697
+ let referenceToReport;
1698
+
1699
+ if (writeReferences.length > 0) {
1700
+ referenceToReport = writeReferences.at(-1);
1701
+ }
1702
+
1703
+ context.report({
1704
+ node: referenceToReport
1705
+ ? referenceToReport.identifier
1706
+ : unusedVar.identifiers[0],
1707
+ messageId: "unusedVar",
1708
+ data: unusedVar.references.some(ref =>
1709
+ ref.isWrite(),
1710
+ )
1711
+ ? getAssignedMessageData(unusedVar)
1712
+ : getDefinedMessageData(unusedVar),
1713
+ suggest: [
1714
+ {
1715
+ messageId: "removeVar",
1716
+ data: {
1717
+ varName: unusedVar.name,
1718
+ },
1719
+ fix(fixer) {
1720
+ return handleFixes(fixer, unusedVar);
1721
+ },
1722
+ },
1723
+ ],
1724
+ });
1725
+
1726
+ // If there are no regular declaration, report the first `/*globals*/` comment directive.
1727
+ } else if (unusedVar.eslintExplicitGlobalComments) {
1728
+ const directiveComment =
1729
+ unusedVar.eslintExplicitGlobalComments[0];
1730
+
1731
+ context.report({
1732
+ node: programNode,
1733
+ loc: astUtils.getNameLocationInGlobalDirectiveComment(
1734
+ sourceCode,
1735
+ directiveComment,
1736
+ unusedVar.name,
1737
+ ),
1738
+ messageId: "unusedVar",
1739
+ data: getDefinedMessageData(unusedVar),
1740
+ });
1741
+ }
1742
+ }
1743
+ },
1744
+ };
1745
+ },
1746
+ };