eslint 8.57.1 → 9.39.1

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 (458) hide show
  1. package/README.md +165 -115
  2. package/bin/eslint.js +112 -89
  3. package/conf/default-cli-options.js +22 -22
  4. package/conf/ecma-version.js +16 -0
  5. package/conf/globals.js +109 -94
  6. package/conf/replacements.json +24 -20
  7. package/conf/rule-type-list.json +89 -26
  8. package/lib/api.js +16 -20
  9. package/lib/cli-engine/cli-engine.js +841 -810
  10. package/lib/cli-engine/file-enumerator.js +384 -390
  11. package/lib/cli-engine/formatters/formatters-meta.json +17 -45
  12. package/lib/cli-engine/formatters/html.js +110 -102
  13. package/lib/cli-engine/formatters/json-with-metadata.js +5 -5
  14. package/lib/cli-engine/formatters/json.js +2 -2
  15. package/lib/cli-engine/formatters/stylish.js +97 -76
  16. package/lib/cli-engine/hash.js +1 -1
  17. package/lib/cli-engine/index.js +1 -1
  18. package/lib/cli-engine/lint-result-cache.js +165 -148
  19. package/lib/cli-engine/load-rules.js +17 -17
  20. package/lib/cli.js +481 -399
  21. package/lib/config/config-loader.js +816 -0
  22. package/lib/config/config.js +674 -0
  23. package/lib/config/default-config.js +57 -46
  24. package/lib/config/flat-config-array.js +170 -333
  25. package/lib/config/flat-config-schema.js +389 -389
  26. package/lib/config-api.js +12 -0
  27. package/lib/eslint/eslint-helpers.js +1196 -663
  28. package/lib/eslint/eslint.js +1262 -607
  29. package/lib/eslint/index.js +3 -3
  30. package/lib/eslint/legacy-eslint.js +786 -0
  31. package/lib/eslint/worker.js +173 -0
  32. package/lib/languages/js/index.js +336 -0
  33. package/lib/languages/js/source-code/index.js +7 -0
  34. package/lib/languages/js/source-code/source-code.js +1364 -0
  35. package/lib/languages/js/source-code/token-store/backward-token-comment-cursor.js +61 -0
  36. package/lib/languages/js/source-code/token-store/backward-token-cursor.js +57 -0
  37. package/lib/{source-code → languages/js/source-code}/token-store/cursor.js +36 -36
  38. package/lib/languages/js/source-code/token-store/cursors.js +120 -0
  39. package/lib/{source-code → languages/js/source-code}/token-store/decorative-cursor.js +17 -18
  40. package/lib/{source-code → languages/js/source-code}/token-store/filter-cursor.js +19 -20
  41. package/lib/languages/js/source-code/token-store/forward-token-comment-cursor.js +65 -0
  42. package/lib/languages/js/source-code/token-store/forward-token-cursor.js +62 -0
  43. package/lib/languages/js/source-code/token-store/index.js +721 -0
  44. package/lib/{source-code → languages/js/source-code}/token-store/limit-cursor.js +17 -18
  45. package/lib/languages/js/source-code/token-store/padded-token-cursor.js +45 -0
  46. package/lib/{source-code → languages/js/source-code}/token-store/skip-cursor.js +19 -20
  47. package/lib/languages/js/source-code/token-store/utils.js +110 -0
  48. package/lib/languages/js/validate-language-options.js +196 -0
  49. package/lib/linter/apply-disable-directives.js +490 -371
  50. package/lib/linter/code-path-analysis/code-path-analyzer.js +650 -674
  51. package/lib/linter/code-path-analysis/code-path-segment.js +215 -216
  52. package/lib/linter/code-path-analysis/code-path-state.js +2118 -2096
  53. package/lib/linter/code-path-analysis/code-path.js +307 -317
  54. package/lib/linter/code-path-analysis/debug-helpers.js +183 -163
  55. package/lib/linter/code-path-analysis/fork-context.js +297 -272
  56. package/lib/linter/code-path-analysis/id-generator.js +22 -23
  57. package/lib/linter/esquery.js +332 -0
  58. package/lib/linter/file-context.js +144 -0
  59. package/lib/linter/file-report.js +608 -0
  60. package/lib/linter/index.js +3 -5
  61. package/lib/linter/interpolate.js +38 -16
  62. package/lib/linter/linter.js +2328 -1785
  63. package/lib/linter/rule-fixer.js +136 -107
  64. package/lib/linter/rules.js +37 -46
  65. package/lib/linter/source-code-fixer.js +96 -94
  66. package/lib/linter/source-code-traverser.js +333 -0
  67. package/lib/linter/source-code-visitor.js +81 -0
  68. package/lib/linter/timing.js +145 -97
  69. package/lib/linter/vfile.js +115 -0
  70. package/lib/options.js +464 -326
  71. package/lib/rule-tester/index.js +3 -1
  72. package/lib/rule-tester/rule-tester.js +1371 -998
  73. package/lib/rules/accessor-pairs.js +333 -259
  74. package/lib/rules/array-bracket-newline.js +250 -220
  75. package/lib/rules/array-bracket-spacing.js +286 -229
  76. package/lib/rules/array-callback-return.js +401 -354
  77. package/lib/rules/array-element-newline.js +358 -295
  78. package/lib/rules/arrow-body-style.js +400 -278
  79. package/lib/rules/arrow-parens.js +206 -155
  80. package/lib/rules/arrow-spacing.js +169 -145
  81. package/lib/rules/block-scoped-var.js +125 -123
  82. package/lib/rules/block-spacing.js +186 -158
  83. package/lib/rules/brace-style.js +262 -181
  84. package/lib/rules/callback-return.js +203 -174
  85. package/lib/rules/camelcase.js +403 -380
  86. package/lib/rules/capitalized-comments.js +253 -228
  87. package/lib/rules/class-methods-use-this.js +231 -168
  88. package/lib/rules/comma-dangle.js +379 -328
  89. package/lib/rules/comma-spacing.js +193 -177
  90. package/lib/rules/comma-style.js +375 -298
  91. package/lib/rules/complexity.js +180 -144
  92. package/lib/rules/computed-property-spacing.js +236 -193
  93. package/lib/rules/consistent-return.js +181 -170
  94. package/lib/rules/consistent-this.js +167 -141
  95. package/lib/rules/constructor-super.js +418 -411
  96. package/lib/rules/curly.js +407 -468
  97. package/lib/rules/default-case-last.js +39 -32
  98. package/lib/rules/default-case.js +89 -83
  99. package/lib/rules/default-param-last.js +69 -53
  100. package/lib/rules/dot-location.js +122 -92
  101. package/lib/rules/dot-notation.js +193 -153
  102. package/lib/rules/eol-last.js +122 -102
  103. package/lib/rules/eqeqeq.js +191 -155
  104. package/lib/rules/for-direction.js +150 -122
  105. package/lib/rules/func-call-spacing.js +261 -213
  106. package/lib/rules/func-name-matching.js +294 -209
  107. package/lib/rules/func-names.js +165 -164
  108. package/lib/rules/func-style.js +209 -86
  109. package/lib/rules/function-call-argument-newline.js +152 -111
  110. package/lib/rules/function-paren-newline.js +349 -273
  111. package/lib/rules/generator-star-spacing.js +229 -192
  112. package/lib/rules/getter-return.js +208 -170
  113. package/lib/rules/global-require.js +85 -58
  114. package/lib/rules/grouped-accessor-pairs.js +201 -148
  115. package/lib/rules/guard-for-in.js +72 -63
  116. package/lib/rules/handle-callback-err.js +108 -87
  117. package/lib/rules/id-blacklist.js +182 -187
  118. package/lib/rules/id-denylist.js +174 -179
  119. package/lib/rules/id-length.js +197 -157
  120. package/lib/rules/id-match.js +350 -286
  121. package/lib/rules/implicit-arrow-linebreak.js +102 -61
  122. package/lib/rules/indent-legacy.js +1345 -1102
  123. package/lib/rules/indent.js +2272 -1741
  124. package/lib/rules/index.js +320 -294
  125. package/lib/rules/init-declarations.js +139 -106
  126. package/lib/rules/jsx-quotes.js +94 -64
  127. package/lib/rules/key-spacing.js +750 -615
  128. package/lib/rules/keyword-spacing.js +648 -587
  129. package/lib/rules/line-comment-position.js +143 -108
  130. package/lib/rules/linebreak-style.js +115 -88
  131. package/lib/rules/lines-around-comment.js +540 -430
  132. package/lib/rules/lines-around-directive.js +233 -185
  133. package/lib/rules/lines-between-class-members.js +305 -216
  134. package/lib/rules/logical-assignment-operators.js +582 -398
  135. package/lib/rules/max-classes-per-file.js +69 -68
  136. package/lib/rules/max-depth.js +146 -143
  137. package/lib/rules/max-len.js +473 -416
  138. package/lib/rules/max-lines-per-function.js +201 -176
  139. package/lib/rules/max-lines.js +158 -162
  140. package/lib/rules/max-nested-callbacks.js +102 -104
  141. package/lib/rules/max-params.js +102 -75
  142. package/lib/rules/max-statements-per-line.js +205 -180
  143. package/lib/rules/max-statements.js +168 -164
  144. package/lib/rules/multiline-comment-style.js +638 -460
  145. package/lib/rules/multiline-ternary.js +241 -158
  146. package/lib/rules/new-cap.js +233 -232
  147. package/lib/rules/new-parens.js +88 -61
  148. package/lib/rules/newline-after-var.js +287 -233
  149. package/lib/rules/newline-before-return.js +229 -204
  150. package/lib/rules/newline-per-chained-call.js +142 -109
  151. package/lib/rules/no-alert.js +90 -79
  152. package/lib/rules/no-array-constructor.js +175 -113
  153. package/lib/rules/no-async-promise-executor.js +30 -24
  154. package/lib/rules/no-await-in-loop.js +79 -70
  155. package/lib/rules/no-bitwise.js +113 -87
  156. package/lib/rules/no-buffer-constructor.js +61 -37
  157. package/lib/rules/no-caller.js +39 -33
  158. package/lib/rules/no-case-declarations.js +61 -45
  159. package/lib/rules/no-catch-shadow.js +76 -62
  160. package/lib/rules/no-class-assign.js +51 -48
  161. package/lib/rules/no-compare-neg-zero.js +62 -48
  162. package/lib/rules/no-cond-assign.js +148 -132
  163. package/lib/rules/no-confusing-arrow.js +98 -63
  164. package/lib/rules/no-console.js +202 -188
  165. package/lib/rules/no-const-assign.js +58 -41
  166. package/lib/rules/no-constant-binary-expression.js +501 -407
  167. package/lib/rules/no-constant-condition.js +158 -131
  168. package/lib/rules/no-constructor-return.js +49 -49
  169. package/lib/rules/no-continue.js +25 -26
  170. package/lib/rules/no-control-regex.js +125 -121
  171. package/lib/rules/no-debugger.js +28 -30
  172. package/lib/rules/no-delete-var.js +29 -29
  173. package/lib/rules/no-div-regex.js +47 -40
  174. package/lib/rules/no-dupe-args.js +79 -69
  175. package/lib/rules/no-dupe-class-members.js +102 -89
  176. package/lib/rules/no-dupe-else-if.js +100 -77
  177. package/lib/rules/no-dupe-keys.js +133 -110
  178. package/lib/rules/no-duplicate-case.js +50 -43
  179. package/lib/rules/no-duplicate-imports.js +266 -188
  180. package/lib/rules/no-else-return.js +430 -385
  181. package/lib/rules/no-empty-character-class.js +57 -50
  182. package/lib/rules/no-empty-function.js +197 -128
  183. package/lib/rules/no-empty-pattern.js +63 -56
  184. package/lib/rules/no-empty-static-block.js +61 -35
  185. package/lib/rules/no-empty.js +135 -85
  186. package/lib/rules/no-eq-null.js +37 -32
  187. package/lib/rules/no-eval.js +258 -249
  188. package/lib/rules/no-ex-assign.js +42 -39
  189. package/lib/rules/no-extend-native.js +161 -160
  190. package/lib/rules/no-extra-bind.js +201 -190
  191. package/lib/rules/no-extra-boolean-cast.js +398 -295
  192. package/lib/rules/no-extra-label.js +150 -130
  193. package/lib/rules/no-extra-parens.js +1654 -1307
  194. package/lib/rules/no-extra-semi.js +146 -126
  195. package/lib/rules/no-fallthrough.js +200 -136
  196. package/lib/rules/no-floating-decimal.js +74 -48
  197. package/lib/rules/no-func-assign.js +54 -55
  198. package/lib/rules/no-global-assign.js +78 -72
  199. package/lib/rules/no-implicit-coercion.js +350 -262
  200. package/lib/rules/no-implicit-globals.js +174 -133
  201. package/lib/rules/no-implied-eval.js +150 -112
  202. package/lib/rules/no-import-assign.js +145 -159
  203. package/lib/rules/no-inline-comments.js +101 -96
  204. package/lib/rules/no-inner-declarations.js +115 -78
  205. package/lib/rules/no-invalid-regexp.js +223 -174
  206. package/lib/rules/no-invalid-this.js +145 -117
  207. package/lib/rules/no-irregular-whitespace.js +266 -250
  208. package/lib/rules/no-iterator.js +29 -33
  209. package/lib/rules/no-label-var.js +59 -61
  210. package/lib/rules/no-labels.js +138 -131
  211. package/lib/rules/no-lone-blocks.js +127 -123
  212. package/lib/rules/no-lonely-if.js +105 -67
  213. package/lib/rules/no-loop-func.js +245 -184
  214. package/lib/rules/no-loss-of-precision.js +236 -201
  215. package/lib/rules/no-magic-numbers.js +339 -217
  216. package/lib/rules/no-misleading-character-class.js +548 -253
  217. package/lib/rules/no-mixed-operators.js +188 -164
  218. package/lib/rules/no-mixed-requires.js +253 -224
  219. package/lib/rules/no-mixed-spaces-and-tabs.js +135 -103
  220. package/lib/rules/no-multi-assign.js +46 -47
  221. package/lib/rules/no-multi-spaces.js +163 -125
  222. package/lib/rules/no-multi-str.js +42 -40
  223. package/lib/rules/no-multiple-empty-lines.js +196 -140
  224. package/lib/rules/no-native-reassign.js +90 -74
  225. package/lib/rules/no-negated-condition.js +79 -74
  226. package/lib/rules/no-negated-in-lhs.js +45 -32
  227. package/lib/rules/no-nested-ternary.js +33 -31
  228. package/lib/rules/no-new-func.js +71 -62
  229. package/lib/rules/no-new-native-nonconstructor.js +43 -39
  230. package/lib/rules/no-new-object.js +48 -39
  231. package/lib/rules/no-new-require.js +48 -31
  232. package/lib/rules/no-new-symbol.js +61 -43
  233. package/lib/rules/no-new-wrappers.js +43 -41
  234. package/lib/rules/no-new.js +28 -29
  235. package/lib/rules/no-nonoctal-decimal-escape.js +149 -121
  236. package/lib/rules/no-obj-calls.js +66 -53
  237. package/lib/rules/no-object-constructor.js +104 -97
  238. package/lib/rules/no-octal-escape.js +40 -43
  239. package/lib/rules/no-octal.js +29 -32
  240. package/lib/rules/no-param-reassign.js +236 -218
  241. package/lib/rules/no-path-concat.js +66 -51
  242. package/lib/rules/no-plusplus.js +60 -63
  243. package/lib/rules/no-process-env.js +49 -32
  244. package/lib/rules/no-process-exit.js +48 -28
  245. package/lib/rules/no-promise-executor-return.js +205 -204
  246. package/lib/rules/no-proto.js +26 -29
  247. package/lib/rules/no-prototype-builtins.js +146 -124
  248. package/lib/rules/no-redeclare.js +154 -155
  249. package/lib/rules/no-regex-spaces.js +183 -161
  250. package/lib/rules/no-restricted-exports.js +208 -174
  251. package/lib/rules/no-restricted-globals.js +254 -112
  252. package/lib/rules/no-restricted-imports.js +824 -384
  253. package/lib/rules/no-restricted-modules.js +222 -186
  254. package/lib/rules/no-restricted-properties.js +218 -153
  255. package/lib/rules/no-restricted-syntax.js +56 -52
  256. package/lib/rules/no-return-assign.js +56 -49
  257. package/lib/rules/no-return-await.js +147 -120
  258. package/lib/rules/no-script-url.js +53 -46
  259. package/lib/rules/no-self-assign.js +148 -145
  260. package/lib/rules/no-self-compare.js +63 -46
  261. package/lib/rules/no-sequences.js +135 -115
  262. package/lib/rules/no-setter-return.js +176 -178
  263. package/lib/rules/no-shadow-restricted-names.js +84 -36
  264. package/lib/rules/no-shadow.js +598 -310
  265. package/lib/rules/no-spaced-func.js +82 -60
  266. package/lib/rules/no-sparse-arrays.js +46 -28
  267. package/lib/rules/no-sync.js +61 -44
  268. package/lib/rules/no-tabs.js +83 -54
  269. package/lib/rules/no-template-curly-in-string.js +33 -32
  270. package/lib/rules/no-ternary.js +25 -28
  271. package/lib/rules/no-this-before-super.js +332 -298
  272. package/lib/rules/no-throw-literal.js +31 -36
  273. package/lib/rules/no-trailing-spaces.js +208 -174
  274. package/lib/rules/no-unassigned-vars.js +80 -0
  275. package/lib/rules/no-undef-init.js +86 -60
  276. package/lib/rules/no-undef.js +52 -47
  277. package/lib/rules/no-undefined.js +73 -74
  278. package/lib/rules/no-underscore-dangle.js +370 -322
  279. package/lib/rules/no-unexpected-multiline.js +112 -102
  280. package/lib/rules/no-unmodified-loop-condition.js +254 -254
  281. package/lib/rules/no-unneeded-ternary.js +212 -146
  282. package/lib/rules/no-unreachable-loop.js +145 -140
  283. package/lib/rules/no-unreachable.js +255 -248
  284. package/lib/rules/no-unsafe-finally.js +93 -85
  285. package/lib/rules/no-unsafe-negation.js +105 -81
  286. package/lib/rules/no-unsafe-optional-chaining.js +193 -177
  287. package/lib/rules/no-unused-expressions.js +199 -158
  288. package/lib/rules/no-unused-labels.js +139 -124
  289. package/lib/rules/no-unused-private-class-members.js +206 -182
  290. package/lib/rules/no-unused-vars.js +1708 -687
  291. package/lib/rules/no-use-before-define.js +327 -229
  292. package/lib/rules/no-useless-assignment.js +654 -0
  293. package/lib/rules/no-useless-backreference.js +212 -143
  294. package/lib/rules/no-useless-call.js +58 -53
  295. package/lib/rules/no-useless-catch.js +40 -40
  296. package/lib/rules/no-useless-computed-key.js +144 -108
  297. package/lib/rules/no-useless-concat.js +65 -59
  298. package/lib/rules/no-useless-constructor.js +160 -97
  299. package/lib/rules/no-useless-escape.js +364 -291
  300. package/lib/rules/no-useless-rename.js +183 -153
  301. package/lib/rules/no-useless-return.js +344 -307
  302. package/lib/rules/no-var.js +245 -212
  303. package/lib/rules/no-void.js +51 -46
  304. package/lib/rules/no-warning-comments.js +191 -183
  305. package/lib/rules/no-whitespace-before-property.js +131 -97
  306. package/lib/rules/no-with.js +24 -26
  307. package/lib/rules/nonblock-statement-body-position.js +149 -112
  308. package/lib/rules/object-curly-newline.js +306 -247
  309. package/lib/rules/object-curly-spacing.js +360 -296
  310. package/lib/rules/object-property-newline.js +137 -88
  311. package/lib/rules/object-shorthand.js +632 -500
  312. package/lib/rules/one-var-declaration-per-line.js +104 -82
  313. package/lib/rules/one-var.js +686 -536
  314. package/lib/rules/operator-assignment.js +219 -158
  315. package/lib/rules/operator-linebreak.js +295 -233
  316. package/lib/rules/padded-blocks.js +346 -290
  317. package/lib/rules/padding-line-between-statements.js +443 -421
  318. package/lib/rules/prefer-arrow-callback.js +371 -315
  319. package/lib/rules/prefer-const.js +418 -373
  320. package/lib/rules/prefer-destructuring.js +309 -278
  321. package/lib/rules/prefer-exponentiation-operator.js +176 -132
  322. package/lib/rules/prefer-named-capture-group.js +160 -141
  323. package/lib/rules/prefer-numeric-literals.js +121 -112
  324. package/lib/rules/prefer-object-has-own.js +116 -82
  325. package/lib/rules/prefer-object-spread.js +214 -193
  326. package/lib/rules/prefer-promise-reject-errors.js +140 -118
  327. package/lib/rules/prefer-reflect.js +126 -103
  328. package/lib/rules/prefer-regex-literals.js +561 -463
  329. package/lib/rules/prefer-rest-params.js +79 -80
  330. package/lib/rules/prefer-spread.js +47 -43
  331. package/lib/rules/prefer-template.js +266 -194
  332. package/lib/rules/preserve-caught-error.js +535 -0
  333. package/lib/rules/quote-props.js +373 -289
  334. package/lib/rules/quotes.js +374 -308
  335. package/lib/rules/radix.js +152 -134
  336. package/lib/rules/require-atomic-updates.js +316 -282
  337. package/lib/rules/require-await.js +153 -82
  338. package/lib/rules/require-unicode-regexp.js +296 -108
  339. package/lib/rules/require-yield.js +53 -54
  340. package/lib/rules/rest-spread-spacing.js +128 -98
  341. package/lib/rules/semi-spacing.js +281 -232
  342. package/lib/rules/semi-style.js +176 -116
  343. package/lib/rules/semi.js +456 -418
  344. package/lib/rules/sort-imports.js +307 -229
  345. package/lib/rules/sort-keys.js +219 -181
  346. package/lib/rules/sort-vars.js +127 -91
  347. package/lib/rules/space-before-blocks.js +199 -171
  348. package/lib/rules/space-before-function-paren.js +186 -148
  349. package/lib/rules/space-in-parens.js +359 -270
  350. package/lib/rules/space-infix-ops.js +237 -183
  351. package/lib/rules/space-unary-ops.js +356 -280
  352. package/lib/rules/spaced-comment.js +363 -301
  353. package/lib/rules/strict.js +266 -229
  354. package/lib/rules/switch-colon-spacing.js +130 -104
  355. package/lib/rules/symbol-description.js +45 -48
  356. package/lib/rules/template-curly-spacing.js +148 -124
  357. package/lib/rules/template-tag-spacing.js +98 -70
  358. package/lib/rules/unicode-bom.js +54 -54
  359. package/lib/rules/use-isnan.js +237 -110
  360. package/lib/rules/utils/ast-utils.js +2139 -1688
  361. package/lib/rules/utils/char-source.js +247 -0
  362. package/lib/rules/utils/fix-tracker.js +99 -88
  363. package/lib/rules/utils/keywords.js +59 -59
  364. package/lib/rules/utils/lazy-loading-rule-map.js +81 -78
  365. package/lib/rules/utils/regular-expressions.js +35 -19
  366. package/lib/rules/utils/unicode/index.js +9 -4
  367. package/lib/rules/utils/unicode/is-combining-character.js +1 -1
  368. package/lib/rules/utils/unicode/is-emoji-modifier.js +1 -1
  369. package/lib/rules/utils/unicode/is-regional-indicator-symbol.js +1 -1
  370. package/lib/rules/utils/unicode/is-surrogate-pair.js +1 -1
  371. package/lib/rules/valid-typeof.js +153 -109
  372. package/lib/rules/vars-on-top.js +152 -144
  373. package/lib/rules/wrap-iife.js +204 -173
  374. package/lib/rules/wrap-regex.js +77 -47
  375. package/lib/rules/yield-star-spacing.js +145 -116
  376. package/lib/rules/yoda.js +283 -274
  377. package/lib/services/parser-service.js +65 -0
  378. package/lib/services/processor-service.js +101 -0
  379. package/lib/services/suppressions-service.js +302 -0
  380. package/lib/services/warning-service.js +98 -0
  381. package/lib/shared/ajv.js +14 -14
  382. package/lib/shared/assert.js +21 -0
  383. package/lib/shared/ast-utils.js +7 -6
  384. package/lib/shared/deep-merge-arrays.js +62 -0
  385. package/lib/shared/directives.js +3 -2
  386. package/lib/shared/flags.js +108 -0
  387. package/lib/shared/logging.js +24 -16
  388. package/lib/shared/naming.js +109 -0
  389. package/lib/shared/option-utils.js +63 -0
  390. package/lib/shared/relative-module-resolver.js +18 -40
  391. package/lib/shared/runtime-info.js +138 -128
  392. package/lib/shared/serialization.js +78 -0
  393. package/lib/shared/severity.js +22 -22
  394. package/lib/shared/stats.js +30 -0
  395. package/lib/shared/string-utils.js +19 -21
  396. package/lib/shared/text-table.js +68 -0
  397. package/lib/shared/translate-cli-options.js +281 -0
  398. package/lib/shared/traverser.js +153 -146
  399. package/lib/types/config-api.d.ts +12 -0
  400. package/lib/types/index.d.ts +1473 -0
  401. package/lib/types/rules.d.ts +5589 -0
  402. package/lib/types/universal.d.ts +6 -0
  403. package/lib/types/use-at-your-own-risk.d.ts +87 -0
  404. package/lib/universal.js +10 -0
  405. package/lib/unsupported-api.js +8 -9
  406. package/messages/all-files-ignored.js +3 -3
  407. package/messages/all-matched-files-ignored.js +21 -0
  408. package/messages/config-file-missing.js +16 -0
  409. package/messages/config-plugin-missing.js +14 -0
  410. package/messages/config-serialize-function.js +30 -0
  411. package/messages/eslintrc-incompat.js +35 -16
  412. package/messages/eslintrc-plugins.js +8 -5
  413. package/messages/extend-config-missing.js +3 -3
  414. package/messages/failed-to-read-json.js +3 -3
  415. package/messages/file-not-found.js +3 -3
  416. package/messages/invalid-rule-options.js +2 -2
  417. package/messages/invalid-rule-severity.js +2 -2
  418. package/messages/no-config-found.js +4 -4
  419. package/messages/plugin-conflict.js +9 -9
  420. package/messages/plugin-invalid.js +4 -4
  421. package/messages/plugin-missing.js +4 -4
  422. package/messages/print-config-with-directory-path.js +2 -2
  423. package/messages/shared.js +6 -1
  424. package/messages/whitespace-found.js +3 -3
  425. package/package.json +105 -60
  426. package/conf/config-schema.js +0 -93
  427. package/lib/cli-engine/formatters/checkstyle.js +0 -60
  428. package/lib/cli-engine/formatters/compact.js +0 -60
  429. package/lib/cli-engine/formatters/jslint-xml.js +0 -41
  430. package/lib/cli-engine/formatters/junit.js +0 -82
  431. package/lib/cli-engine/formatters/tap.js +0 -95
  432. package/lib/cli-engine/formatters/unix.js +0 -58
  433. package/lib/cli-engine/formatters/visualstudio.js +0 -63
  434. package/lib/cli-engine/xml-escape.js +0 -34
  435. package/lib/config/flat-config-helpers.js +0 -111
  436. package/lib/config/rule-validator.js +0 -158
  437. package/lib/eslint/flat-eslint.js +0 -1159
  438. package/lib/linter/config-comment-parser.js +0 -185
  439. package/lib/linter/node-event-generator.js +0 -354
  440. package/lib/linter/report-translator.js +0 -369
  441. package/lib/linter/safe-emitter.js +0 -52
  442. package/lib/rule-tester/flat-rule-tester.js +0 -1131
  443. package/lib/rules/require-jsdoc.js +0 -122
  444. package/lib/rules/utils/patterns/letters.js +0 -36
  445. package/lib/rules/valid-jsdoc.js +0 -516
  446. package/lib/shared/config-validator.js +0 -347
  447. package/lib/shared/deprecation-warnings.js +0 -58
  448. package/lib/shared/types.js +0 -216
  449. package/lib/source-code/index.js +0 -5
  450. package/lib/source-code/source-code.js +0 -1055
  451. package/lib/source-code/token-store/backward-token-comment-cursor.js +0 -57
  452. package/lib/source-code/token-store/backward-token-cursor.js +0 -58
  453. package/lib/source-code/token-store/cursors.js +0 -90
  454. package/lib/source-code/token-store/forward-token-comment-cursor.js +0 -57
  455. package/lib/source-code/token-store/forward-token-cursor.js +0 -63
  456. package/lib/source-code/token-store/index.js +0 -627
  457. package/lib/source-code/token-store/padded-token-cursor.js +0 -38
  458. package/lib/source-code/token-store/utils.js +0 -107
@@ -0,0 +1,1473 @@
1
+ /**
2
+ * @fileoverview This file contains the core types for ESLint. It was initially extracted
3
+ * from the `@types/eslint` package.
4
+ */
5
+
6
+ /*
7
+ * MIT License
8
+ * Copyright (c) Microsoft Corporation.
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE
26
+ */
27
+
28
+ import * as ESTree from "estree";
29
+ import type {
30
+ CustomRuleDefinitionType,
31
+ CustomRuleTypeDefinitions,
32
+ DeprecatedInfo,
33
+ LanguageOptions as GenericLanguageOptions,
34
+ RuleContext as CoreRuleContext,
35
+ RuleDefinition,
36
+ SourceRange,
37
+ TextSourceCode,
38
+ TraversalStep,
39
+ RulesConfig,
40
+ GlobalAccess,
41
+ GlobalsConfig,
42
+ LinterOptionsConfig,
43
+ EnvironmentConfig,
44
+ ObjectMetaProperties as CoreObjectMetaProperties,
45
+ Plugin as CorePlugin,
46
+ LintMessage as CoreLintMessage,
47
+ Processor as CoreProcessor,
48
+ ConfigObject,
49
+ LegacyConfigObject,
50
+ SeverityName,
51
+ SeverityLevel,
52
+ Severity as CoreSeverity,
53
+ EcmaVersion as CoreEcmaVersion,
54
+ ConfigOverride as CoreConfigOverride,
55
+ ProcessorFile as CoreProcessorFile,
56
+ JavaScriptParserOptionsConfig,
57
+ RulesMeta,
58
+ RuleConfig,
59
+ RuleTextEditor,
60
+ RuleTextEdit,
61
+ RuleVisitor,
62
+ BaseConfig as CoreBaseConfig,
63
+ RuleFixer as CoreRuleFixer,
64
+ ViolationReportBase,
65
+ ViolationMessage,
66
+ ViolationLocation,
67
+ SuggestionMessage,
68
+ LintSuggestion as CoreLintSuggestion,
69
+ JavaScriptSourceType,
70
+ HasRules as CoreHasRules,
71
+ SuggestedEditBase,
72
+ SuggestedEdit,
73
+ ViolationReport,
74
+ } from "@eslint/core";
75
+ import { LegacyESLint } from "./use-at-your-own-risk.js";
76
+
77
+ //------------------------------------------------------------------------------
78
+ // Helpers
79
+ //------------------------------------------------------------------------------
80
+
81
+ /** Adds matching `:exit` selectors for all properties of a `RuleVisitor`. */
82
+ type WithExit<RuleVisitorType extends RuleVisitor> = {
83
+ [Key in keyof RuleVisitorType as
84
+ | Key
85
+ | `${Key & string}:exit`]: RuleVisitorType[Key];
86
+ };
87
+
88
+ //------------------------------------------------------------------------------
89
+ // Exports
90
+ //------------------------------------------------------------------------------
91
+
92
+ export namespace AST {
93
+ type TokenType =
94
+ | "Boolean"
95
+ | "Null"
96
+ | "Identifier"
97
+ | "PrivateIdentifier"
98
+ | "Keyword"
99
+ | "Punctuator"
100
+ | "JSXIdentifier"
101
+ | "JSXText"
102
+ | "Numeric"
103
+ | "String"
104
+ | "Template"
105
+ | "RegularExpression";
106
+
107
+ interface Token {
108
+ type: TokenType;
109
+ value: string;
110
+ range: Range;
111
+ loc: SourceLocation;
112
+ }
113
+
114
+ interface SourceLocation {
115
+ start: ESTree.Position;
116
+ end: ESTree.Position;
117
+ }
118
+
119
+ type Range = [number, number];
120
+
121
+ interface Program extends ESTree.Program {
122
+ comments: ESTree.Comment[];
123
+ tokens: Token[];
124
+ loc: SourceLocation;
125
+ range: Range;
126
+ }
127
+ }
128
+
129
+ export namespace Scope {
130
+ interface ScopeManager {
131
+ scopes: Scope[];
132
+ globalScope: Scope | null;
133
+
134
+ acquire(node: ESTree.Node, inner?: boolean): Scope | null;
135
+
136
+ getDeclaredVariables(node: ESTree.Node): Variable[];
137
+ }
138
+
139
+ interface Scope {
140
+ type:
141
+ | "block"
142
+ | "catch"
143
+ | "class"
144
+ | "class-field-initializer"
145
+ | "class-static-block"
146
+ | "for"
147
+ | "function"
148
+ | "function-expression-name"
149
+ | "global"
150
+ | "module"
151
+ | "switch"
152
+ | "with"
153
+ | "TDZ";
154
+ isStrict: boolean;
155
+ upper: Scope | null;
156
+ childScopes: Scope[];
157
+ variableScope: Scope;
158
+ block: ESTree.Node;
159
+ variables: Variable[];
160
+ set: Map<string, Variable>;
161
+ references: Reference[];
162
+ through: Reference[];
163
+ functionExpressionScope: boolean;
164
+ implicit?: {
165
+ variables: Variable[];
166
+ set: Map<string, Variable>;
167
+ };
168
+ }
169
+
170
+ interface Variable {
171
+ name: string;
172
+ scope: Scope;
173
+ identifiers: ESTree.Identifier[];
174
+ references: Reference[];
175
+ defs: Definition[];
176
+ }
177
+
178
+ interface Reference {
179
+ identifier: ESTree.Identifier;
180
+ from: Scope;
181
+ resolved: Variable | null;
182
+ writeExpr: ESTree.Node | null;
183
+ init: boolean;
184
+
185
+ isWrite(): boolean;
186
+
187
+ isRead(): boolean;
188
+
189
+ isWriteOnly(): boolean;
190
+
191
+ isReadOnly(): boolean;
192
+
193
+ isReadWrite(): boolean;
194
+ }
195
+
196
+ type DefinitionType =
197
+ | { type: "CatchClause"; node: ESTree.CatchClause; parent: null }
198
+ | {
199
+ type: "ClassName";
200
+ node: ESTree.ClassDeclaration | ESTree.ClassExpression;
201
+ parent: null;
202
+ }
203
+ | {
204
+ type: "FunctionName";
205
+ node: ESTree.FunctionDeclaration | ESTree.FunctionExpression;
206
+ parent: null;
207
+ }
208
+ | {
209
+ type: "ImplicitGlobalVariable";
210
+ node:
211
+ | ESTree.AssignmentExpression
212
+ | ESTree.ForInStatement
213
+ | ESTree.ForOfStatement;
214
+ parent: null;
215
+ }
216
+ | {
217
+ type: "ImportBinding";
218
+ node:
219
+ | ESTree.ImportSpecifier
220
+ | ESTree.ImportDefaultSpecifier
221
+ | ESTree.ImportNamespaceSpecifier;
222
+ parent: ESTree.ImportDeclaration;
223
+ }
224
+ | {
225
+ type: "Parameter";
226
+ node:
227
+ | ESTree.FunctionDeclaration
228
+ | ESTree.FunctionExpression
229
+ | ESTree.ArrowFunctionExpression;
230
+ parent: null;
231
+ }
232
+ | { type: "TDZ"; node: any; parent: null }
233
+ | {
234
+ type: "Variable";
235
+ node: ESTree.VariableDeclarator;
236
+ parent: ESTree.VariableDeclaration;
237
+ };
238
+
239
+ type Definition = DefinitionType & { name: ESTree.Identifier };
240
+ }
241
+
242
+ // #region SourceCode
243
+
244
+ export class SourceCode
245
+ implements
246
+ TextSourceCode<{
247
+ LangOptions: Linter.LanguageOptions;
248
+ RootNode: AST.Program;
249
+ SyntaxElementWithLoc: AST.Token | ESTree.Node;
250
+ ConfigNode: ESTree.Comment;
251
+ }>
252
+ {
253
+ text: string;
254
+ ast: AST.Program;
255
+ lines: string[];
256
+ hasBOM: boolean;
257
+ parserServices: SourceCode.ParserServices;
258
+ scopeManager: Scope.ScopeManager;
259
+ visitorKeys: SourceCode.VisitorKeys;
260
+
261
+ constructor(text: string, ast: AST.Program);
262
+ constructor(config: SourceCode.Config);
263
+
264
+ static splitLines(text: string): string[];
265
+
266
+ getLoc(syntaxElement: AST.Token | ESTree.Node): ESTree.SourceLocation;
267
+ getRange(syntaxElement: AST.Token | ESTree.Node): SourceRange;
268
+
269
+ getText(
270
+ node?: ESTree.Node,
271
+ beforeCount?: number,
272
+ afterCount?: number,
273
+ ): string;
274
+
275
+ getLines(): string[];
276
+
277
+ getAllComments(): ESTree.Comment[];
278
+
279
+ getAncestors(node: ESTree.Node): ESTree.Node[];
280
+
281
+ getDeclaredVariables(node: ESTree.Node): Scope.Variable[];
282
+
283
+ /** @deprecated */
284
+ getJSDocComment(node: ESTree.Node): ESTree.Comment | null;
285
+
286
+ getNodeByRangeIndex(index: number): ESTree.Node | null;
287
+
288
+ /** @deprecated Use `isSpaceBetween()` instead. */
289
+ isSpaceBetweenTokens(
290
+ first: ESTree.Node | AST.Token,
291
+ second: ESTree.Node | AST.Token,
292
+ ): boolean;
293
+
294
+ getLocFromIndex(index: number): ESTree.Position;
295
+
296
+ getIndexFromLoc(location: ESTree.Position): number;
297
+
298
+ // Inherited methods from TokenStore
299
+ // ---------------------------------
300
+
301
+ getTokenByRangeStart(
302
+ offset: number,
303
+ options?: { includeComments: false },
304
+ ): AST.Token | null;
305
+ getTokenByRangeStart(
306
+ offset: number,
307
+ options: { includeComments: boolean },
308
+ ): AST.Token | ESTree.Comment | null;
309
+
310
+ getFirstToken: SourceCode.UnaryNodeCursorWithSkipOptions;
311
+
312
+ getFirstTokens: SourceCode.UnaryNodeCursorWithCountOptions;
313
+
314
+ getLastToken: SourceCode.UnaryNodeCursorWithSkipOptions;
315
+
316
+ getLastTokens: SourceCode.UnaryNodeCursorWithCountOptions;
317
+
318
+ getTokenBefore: SourceCode.UnaryCursorWithSkipOptions;
319
+
320
+ getTokensBefore: SourceCode.UnaryCursorWithCountOptions;
321
+
322
+ getTokenAfter: SourceCode.UnaryCursorWithSkipOptions;
323
+
324
+ getTokensAfter: SourceCode.UnaryCursorWithCountOptions;
325
+
326
+ /** @deprecated Use `getTokenBefore()` instead. */
327
+ getTokenOrCommentBefore(
328
+ node: ESTree.Node | AST.Token | ESTree.Comment,
329
+ skip?: number | undefined,
330
+ ): AST.Token | ESTree.Comment | null;
331
+
332
+ /** @deprecated Use `getTokenAfter()` instead. */
333
+ getTokenOrCommentAfter(
334
+ node: ESTree.Node | AST.Token | ESTree.Comment,
335
+ skip?: number | undefined,
336
+ ): AST.Token | ESTree.Comment | null;
337
+
338
+ getFirstTokenBetween: SourceCode.BinaryCursorWithSkipOptions;
339
+
340
+ getFirstTokensBetween: SourceCode.BinaryCursorWithCountOptions;
341
+
342
+ getLastTokenBetween: SourceCode.BinaryCursorWithSkipOptions;
343
+
344
+ getLastTokensBetween: SourceCode.BinaryCursorWithCountOptions;
345
+
346
+ getTokensBetween: SourceCode.BinaryCursorWithCountOptions;
347
+
348
+ getTokens: ((
349
+ node: ESTree.Node,
350
+ beforeCount?: number,
351
+ afterCount?: number,
352
+ ) => AST.Token[]) &
353
+ SourceCode.UnaryNodeCursorWithCountOptions;
354
+
355
+ commentsExistBetween(
356
+ left: ESTree.Node | AST.Token | ESTree.Comment,
357
+ right: ESTree.Node | AST.Token | ESTree.Comment,
358
+ ): boolean;
359
+
360
+ getCommentsBefore(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[];
361
+
362
+ getCommentsAfter(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[];
363
+
364
+ getCommentsInside(node: ESTree.Node): ESTree.Comment[];
365
+
366
+ getScope(node: ESTree.Node): Scope.Scope;
367
+
368
+ isSpaceBetween(
369
+ first: ESTree.Node | AST.Token,
370
+ second: ESTree.Node | AST.Token,
371
+ ): boolean;
372
+
373
+ isGlobalReference(node: ESTree.Identifier): boolean;
374
+
375
+ markVariableAsUsed(name: string, refNode?: ESTree.Node): boolean;
376
+
377
+ traverse(): Iterable<TraversalStep>;
378
+ }
379
+
380
+ export namespace SourceCode {
381
+ interface Config {
382
+ text: string;
383
+ ast: AST.Program;
384
+ hasBOM?: boolean | undefined;
385
+ parserServices?: ParserServices | null | undefined;
386
+ scopeManager?: Scope.ScopeManager | null | undefined;
387
+ visitorKeys?: VisitorKeys | null | undefined;
388
+ }
389
+
390
+ type ParserServices = any;
391
+
392
+ interface VisitorKeys {
393
+ [nodeType: string]: string[];
394
+ }
395
+
396
+ interface UnaryNodeCursorWithSkipOptions {
397
+ <T extends AST.Token>(
398
+ node: ESTree.Node,
399
+ options:
400
+ | ((token: AST.Token) => token is T)
401
+ | {
402
+ filter: (token: AST.Token) => token is T;
403
+ includeComments?: false | undefined;
404
+ skip?: number | undefined;
405
+ },
406
+ ): T | null;
407
+ <T extends AST.Token | ESTree.Comment>(
408
+ node: ESTree.Node,
409
+ options: {
410
+ filter: (
411
+ tokenOrComment: AST.Token | ESTree.Comment,
412
+ ) => tokenOrComment is T;
413
+ includeComments: boolean;
414
+ skip?: number | undefined;
415
+ },
416
+ ): T | null;
417
+ (
418
+ node: ESTree.Node,
419
+ options?:
420
+ | {
421
+ filter?: ((token: AST.Token) => boolean) | undefined;
422
+ includeComments?: false | undefined;
423
+ skip?: number | undefined;
424
+ }
425
+ | ((token: AST.Token) => boolean)
426
+ | number,
427
+ ): AST.Token | null;
428
+ (
429
+ node: ESTree.Node,
430
+ options: {
431
+ filter?:
432
+ | ((token: AST.Token | ESTree.Comment) => boolean)
433
+ | undefined;
434
+ includeComments: boolean;
435
+ skip?: number | undefined;
436
+ },
437
+ ): AST.Token | ESTree.Comment | null;
438
+ }
439
+
440
+ interface UnaryNodeCursorWithCountOptions {
441
+ <T extends AST.Token>(
442
+ node: ESTree.Node,
443
+ options:
444
+ | ((token: AST.Token) => token is T)
445
+ | {
446
+ filter: (token: AST.Token) => token is T;
447
+ includeComments?: false | undefined;
448
+ count?: number | undefined;
449
+ },
450
+ ): T[];
451
+ <T extends AST.Token | ESTree.Comment>(
452
+ node: ESTree.Node,
453
+ options: {
454
+ filter: (
455
+ tokenOrComment: AST.Token | ESTree.Comment,
456
+ ) => tokenOrComment is T;
457
+ includeComments: boolean;
458
+ count?: number | undefined;
459
+ },
460
+ ): T[];
461
+ (
462
+ node: ESTree.Node,
463
+ options?:
464
+ | {
465
+ filter?: ((token: AST.Token) => boolean) | undefined;
466
+ includeComments?: false | undefined;
467
+ count?: number | undefined;
468
+ }
469
+ | ((token: AST.Token) => boolean)
470
+ | number,
471
+ ): AST.Token[];
472
+ (
473
+ node: ESTree.Node,
474
+ options: {
475
+ filter?:
476
+ | ((token: AST.Token | ESTree.Comment) => boolean)
477
+ | undefined;
478
+ includeComments: boolean;
479
+ count?: number | undefined;
480
+ },
481
+ ): Array<AST.Token | ESTree.Comment>;
482
+ }
483
+
484
+ interface UnaryCursorWithSkipOptions {
485
+ <T extends AST.Token>(
486
+ node: ESTree.Node | AST.Token | ESTree.Comment,
487
+ options:
488
+ | ((token: AST.Token) => token is T)
489
+ | {
490
+ filter: (token: AST.Token) => token is T;
491
+ includeComments?: false | undefined;
492
+ skip?: number | undefined;
493
+ },
494
+ ): T | null;
495
+ <T extends AST.Token | ESTree.Comment>(
496
+ node: ESTree.Node | AST.Token | ESTree.Comment,
497
+ options: {
498
+ filter: (
499
+ tokenOrComment: AST.Token | ESTree.Comment,
500
+ ) => tokenOrComment is T;
501
+ includeComments: boolean;
502
+ skip?: number | undefined;
503
+ },
504
+ ): T | null;
505
+ (
506
+ node: ESTree.Node | AST.Token | ESTree.Comment,
507
+ options?:
508
+ | {
509
+ filter?: ((token: AST.Token) => boolean) | undefined;
510
+ includeComments?: false | undefined;
511
+ skip?: number | undefined;
512
+ }
513
+ | ((token: AST.Token) => boolean)
514
+ | number,
515
+ ): AST.Token | null;
516
+ (
517
+ node: ESTree.Node | AST.Token | ESTree.Comment,
518
+ options: {
519
+ filter?:
520
+ | ((token: AST.Token | ESTree.Comment) => boolean)
521
+ | undefined;
522
+ includeComments: boolean;
523
+ skip?: number | undefined;
524
+ },
525
+ ): AST.Token | ESTree.Comment | null;
526
+ }
527
+
528
+ interface UnaryCursorWithCountOptions {
529
+ <T extends AST.Token>(
530
+ node: ESTree.Node | AST.Token | ESTree.Comment,
531
+ options:
532
+ | ((token: AST.Token) => token is T)
533
+ | {
534
+ filter: (token: AST.Token) => token is T;
535
+ includeComments?: false | undefined;
536
+ count?: number | undefined;
537
+ },
538
+ ): T[];
539
+ <T extends AST.Token | ESTree.Comment>(
540
+ node: ESTree.Node | AST.Token | ESTree.Comment,
541
+ options: {
542
+ filter: (
543
+ tokenOrComment: AST.Token | ESTree.Comment,
544
+ ) => tokenOrComment is T;
545
+ includeComments: boolean;
546
+ count?: number | undefined;
547
+ },
548
+ ): T[];
549
+ (
550
+ node: ESTree.Node | AST.Token | ESTree.Comment,
551
+ options?:
552
+ | {
553
+ filter?: ((token: AST.Token) => boolean) | undefined;
554
+ includeComments?: false | undefined;
555
+ count?: number | undefined;
556
+ }
557
+ | ((token: AST.Token) => boolean)
558
+ | number,
559
+ ): AST.Token[];
560
+ (
561
+ node: ESTree.Node | AST.Token | ESTree.Comment,
562
+ options: {
563
+ filter?:
564
+ | ((token: AST.Token | ESTree.Comment) => boolean)
565
+ | undefined;
566
+ includeComments: boolean;
567
+ count?: number | undefined;
568
+ },
569
+ ): Array<AST.Token | ESTree.Comment>;
570
+ }
571
+
572
+ interface BinaryCursorWithSkipOptions {
573
+ <T extends AST.Token>(
574
+ left: ESTree.Node | AST.Token | ESTree.Comment,
575
+ right: ESTree.Node | AST.Token | ESTree.Comment,
576
+ options:
577
+ | ((token: AST.Token) => token is T)
578
+ | {
579
+ filter: (token: AST.Token) => token is T;
580
+ includeComments?: false | undefined;
581
+ skip?: number | undefined;
582
+ },
583
+ ): T | null;
584
+ <T extends AST.Token | ESTree.Comment>(
585
+ left: ESTree.Node | AST.Token | ESTree.Comment,
586
+ right: ESTree.Node | AST.Token | ESTree.Comment,
587
+ options: {
588
+ filter: (
589
+ tokenOrComment: AST.Token | ESTree.Comment,
590
+ ) => tokenOrComment is T;
591
+ includeComments: boolean;
592
+ skip?: number | undefined;
593
+ },
594
+ ): T | null;
595
+ (
596
+ left: ESTree.Node | AST.Token | ESTree.Comment,
597
+ right: ESTree.Node | AST.Token | ESTree.Comment,
598
+ options?:
599
+ | {
600
+ filter?: ((token: AST.Token) => boolean) | undefined;
601
+ includeComments?: false | undefined;
602
+ skip?: number | undefined;
603
+ }
604
+ | ((token: AST.Token) => boolean)
605
+ | number,
606
+ ): AST.Token | null;
607
+ (
608
+ left: ESTree.Node | AST.Token | ESTree.Comment,
609
+ right: ESTree.Node | AST.Token | ESTree.Comment,
610
+ options: {
611
+ filter?:
612
+ | ((token: AST.Token | ESTree.Comment) => boolean)
613
+ | undefined;
614
+ includeComments: boolean;
615
+ skip?: number | undefined;
616
+ },
617
+ ): AST.Token | ESTree.Comment | null;
618
+ }
619
+
620
+ interface BinaryCursorWithCountOptions {
621
+ <T extends AST.Token>(
622
+ left: ESTree.Node | AST.Token | ESTree.Comment,
623
+ right: ESTree.Node | AST.Token | ESTree.Comment,
624
+ options:
625
+ | ((token: AST.Token) => token is T)
626
+ | {
627
+ filter: (token: AST.Token) => token is T;
628
+ includeComments?: false | undefined;
629
+ count?: number | undefined;
630
+ },
631
+ ): T[];
632
+ <T extends AST.Token | ESTree.Comment>(
633
+ left: ESTree.Node | AST.Token | ESTree.Comment,
634
+ right: ESTree.Node | AST.Token | ESTree.Comment,
635
+ options: {
636
+ filter: (
637
+ tokenOrComment: AST.Token | ESTree.Comment,
638
+ ) => tokenOrComment is T;
639
+ includeComments: boolean;
640
+ count?: number | undefined;
641
+ },
642
+ ): T[];
643
+ (
644
+ left: ESTree.Node | AST.Token | ESTree.Comment,
645
+ right: ESTree.Node | AST.Token | ESTree.Comment,
646
+ options?:
647
+ | {
648
+ filter?: ((token: AST.Token) => boolean) | undefined;
649
+ includeComments?: false | undefined;
650
+ count?: number | undefined;
651
+ }
652
+ | ((token: AST.Token) => boolean)
653
+ | number,
654
+ ): AST.Token[];
655
+ (
656
+ left: ESTree.Node | AST.Token | ESTree.Comment,
657
+ right: ESTree.Node | AST.Token | ESTree.Comment,
658
+ options: {
659
+ filter?:
660
+ | ((token: AST.Token | ESTree.Comment) => boolean)
661
+ | undefined;
662
+ includeComments: boolean;
663
+ count?: number | undefined;
664
+ },
665
+ ): Array<AST.Token | ESTree.Comment>;
666
+ }
667
+ }
668
+
669
+ // #endregion
670
+
671
+ export type JSSyntaxElement = {
672
+ type: string;
673
+ loc?: ESTree.SourceLocation | null | undefined;
674
+ };
675
+
676
+ export namespace Rule {
677
+ interface RuleModule
678
+ extends RuleDefinition<{
679
+ LangOptions: Linter.LanguageOptions;
680
+ Code: SourceCode;
681
+ RuleOptions: any[];
682
+ Visitor: RuleListener;
683
+ Node: JSSyntaxElement;
684
+ MessageIds: string;
685
+ ExtRuleDocs: {};
686
+ }> {
687
+ create(context: RuleContext): RuleListener;
688
+ }
689
+
690
+ type NodeTypes = ESTree.Node["type"];
691
+
692
+ interface NodeListener
693
+ extends WithExit<
694
+ {
695
+ [Node in Rule.Node as Node["type"]]?:
696
+ | ((node: Node) => void)
697
+ | undefined;
698
+ } & {
699
+ // A `Program` visitor's node type has no `parent` property.
700
+ Program?: ((node: AST.Program) => void) | undefined;
701
+ }
702
+ > {}
703
+
704
+ interface NodeParentExtension {
705
+ parent: Node;
706
+ }
707
+
708
+ type Node =
709
+ | (AST.Program & { parent: null })
710
+ | (Exclude<ESTree.Node, ESTree.Program> & NodeParentExtension);
711
+
712
+ interface RuleListener extends NodeListener {
713
+ onCodePathStart?(codePath: CodePath, node: Node): void;
714
+
715
+ onCodePathEnd?(codePath: CodePath, node: Node): void;
716
+
717
+ onCodePathSegmentStart?(segment: CodePathSegment, node: Node): void;
718
+
719
+ onCodePathSegmentEnd?(segment: CodePathSegment, node: Node): void;
720
+
721
+ onUnreachableCodePathSegmentStart?(
722
+ segment: CodePathSegment,
723
+ node: Node,
724
+ ): void;
725
+
726
+ onUnreachableCodePathSegmentEnd?(
727
+ segment: CodePathSegment,
728
+ node: Node,
729
+ ): void;
730
+
731
+ onCodePathSegmentLoop?(
732
+ fromSegment: CodePathSegment,
733
+ toSegment: CodePathSegment,
734
+ node: Node,
735
+ ): void;
736
+
737
+ [key: string]:
738
+ | ((codePath: CodePath, node: Node) => void)
739
+ | ((segment: CodePathSegment, node: Node) => void)
740
+ | ((
741
+ fromSegment: CodePathSegment,
742
+ toSegment: CodePathSegment,
743
+ node: Node,
744
+ ) => void)
745
+ | ((node: Node) => void)
746
+ | NodeListener[keyof NodeListener]
747
+ | undefined;
748
+ }
749
+
750
+ type CodePathOrigin =
751
+ | "program"
752
+ | "function"
753
+ | "class-field-initializer"
754
+ | "class-static-block";
755
+
756
+ interface CodePath {
757
+ id: string;
758
+ origin: CodePathOrigin;
759
+ initialSegment: CodePathSegment;
760
+ finalSegments: CodePathSegment[];
761
+ returnedSegments: CodePathSegment[];
762
+ thrownSegments: CodePathSegment[];
763
+ upper: CodePath | null;
764
+ childCodePaths: CodePath[];
765
+ }
766
+
767
+ interface CodePathSegment {
768
+ id: string;
769
+ nextSegments: CodePathSegment[];
770
+ prevSegments: CodePathSegment[];
771
+ reachable: boolean;
772
+ }
773
+
774
+ type RuleMetaData = RulesMeta;
775
+
776
+ interface RuleContext
777
+ extends CoreRuleContext<{
778
+ LangOptions: Linter.LanguageOptions;
779
+ Code: SourceCode;
780
+ RuleOptions: any[];
781
+ Node: JSSyntaxElement;
782
+ MessageIds: string;
783
+ }> {}
784
+
785
+ type ReportFixer = CoreRuleFixer;
786
+
787
+ /** @deprecated Use `ReportDescriptorOptions` instead. */
788
+ type ReportDescriptorOptionsBase = ViolationReportBase;
789
+
790
+ type SuggestionReportOptions = SuggestedEditBase;
791
+ type SuggestionDescriptorMessage = SuggestionMessage;
792
+ type SuggestionReportDescriptor = SuggestedEdit;
793
+
794
+ // redundant with ReportDescriptorOptionsBase but kept for clarity
795
+ type ReportDescriptorOptions = ViolationReportBase;
796
+
797
+ type ReportDescriptor = ViolationReport<ESTree.Node>;
798
+ type ReportDescriptorMessage = ViolationMessage;
799
+ type ReportDescriptorLocation = ViolationLocation<ESTree.Node>;
800
+
801
+ type RuleFixer = RuleTextEditor<ESTree.Node | AST.Token>;
802
+ type Fix = RuleTextEdit;
803
+ }
804
+
805
+ export type JSRuleDefinitionTypeOptions = CustomRuleTypeDefinitions;
806
+
807
+ export type JSRuleDefinition<
808
+ Options extends Partial<JSRuleDefinitionTypeOptions> = {},
809
+ > = CustomRuleDefinitionType<
810
+ {
811
+ LangOptions: Linter.LanguageOptions;
812
+ Code: SourceCode;
813
+ Visitor: Rule.RuleListener;
814
+ Node: JSSyntaxElement;
815
+ },
816
+ Options
817
+ >;
818
+
819
+ // #region Linter
820
+
821
+ export class Linter {
822
+ static readonly version: string;
823
+
824
+ version: string;
825
+
826
+ constructor(options?: {
827
+ cwd?: string | undefined;
828
+ configType?: "flat" | "eslintrc";
829
+ });
830
+
831
+ verify(
832
+ code: SourceCode | string,
833
+ config: Linter.LegacyConfig | Linter.Config | Linter.Config[],
834
+ filename?: string,
835
+ ): Linter.LintMessage[];
836
+ verify(
837
+ code: SourceCode | string,
838
+ config: Linter.LegacyConfig | Linter.Config | Linter.Config[],
839
+ options: Linter.LintOptions,
840
+ ): Linter.LintMessage[];
841
+
842
+ verifyAndFix(
843
+ code: string,
844
+ config: Linter.LegacyConfig | Linter.Config | Linter.Config[],
845
+ filename?: string,
846
+ ): Linter.FixReport;
847
+ verifyAndFix(
848
+ code: string,
849
+ config: Linter.LegacyConfig | Linter.Config | Linter.Config[],
850
+ options: Linter.FixOptions,
851
+ ): Linter.FixReport;
852
+
853
+ getSourceCode(): SourceCode;
854
+
855
+ defineRule(name: string, rule: Rule.RuleModule): void;
856
+
857
+ defineRules(rules: { [name: string]: Rule.RuleModule }): void;
858
+
859
+ getRules(): Map<string, Rule.RuleModule>;
860
+
861
+ defineParser(name: string, parser: Linter.Parser): void;
862
+
863
+ getTimes(): Linter.Stats["times"];
864
+
865
+ getFixPassCount(): Linter.Stats["fixPasses"];
866
+ }
867
+
868
+ export namespace Linter {
869
+ /**
870
+ * The numeric severity level for a rule.
871
+ *
872
+ * - `0` means off.
873
+ * - `1` means warn.
874
+ * - `2` means error.
875
+ *
876
+ * @see [Rule Severities](https://eslint.org/docs/latest/use/configure/rules#rule-severities)
877
+ */
878
+ type Severity = SeverityLevel;
879
+
880
+ /**
881
+ * The human readable severity level for a rule.
882
+ *
883
+ * @see [Rule Severities](https://eslint.org/docs/latest/use/configure/rules#rule-severities)
884
+ */
885
+ type StringSeverity = SeverityName;
886
+
887
+ /**
888
+ * The numeric or human readable severity level for a rule.
889
+ *
890
+ * @see [Rule Severities](https://eslint.org/docs/latest/use/configure/rules#rule-severities)
891
+ */
892
+ type RuleSeverity = CoreSeverity;
893
+
894
+ /**
895
+ * An array containing the rule severity level, followed by the rule options.
896
+ *
897
+ * @see [Rules](https://eslint.org/docs/latest/use/configure/rules)
898
+ */
899
+ type RuleSeverityAndOptions<Options extends any[] = any[]> = [
900
+ RuleSeverity,
901
+ ...Partial<Options>,
902
+ ];
903
+
904
+ /**
905
+ * The severity level for the rule or an array containing the rule severity level, followed by the rule options.
906
+ *
907
+ * @see [Rules](https://eslint.org/docs/latest/use/configure/rules)
908
+ */
909
+ type RuleEntry<Options extends any[] = any[]> = RuleConfig<Options>;
910
+
911
+ /**
912
+ * The rules config object is a key/value map of rule names and their severity and options.
913
+ */
914
+ type RulesRecord = RulesConfig;
915
+
916
+ /**
917
+ * A configuration object that may have a `rules` block.
918
+ */
919
+ type HasRules<Rules extends RulesConfig = RulesConfig> =
920
+ CoreHasRules<Rules>;
921
+
922
+ /**
923
+ * The ECMAScript version of the code being linted.
924
+ */
925
+ type EcmaVersion = CoreEcmaVersion;
926
+
927
+ /**
928
+ * The type of JavaScript source code.
929
+ */
930
+ type SourceType = JavaScriptSourceType;
931
+
932
+ /**
933
+ * ESLint legacy configuration.
934
+ *
935
+ * @see [ESLint Legacy Configuration](https://eslint.org/docs/latest/use/configure/)
936
+ */
937
+ type BaseConfig<
938
+ Rules extends RulesConfig = RulesConfig,
939
+ OverrideRules extends RulesConfig = Rules,
940
+ > = CoreBaseConfig<Rules, OverrideRules>;
941
+
942
+ /**
943
+ * The overwrites that apply more differing configuration to specific files or directories.
944
+ */
945
+ type ConfigOverride<Rules extends RulesConfig = RulesConfig> =
946
+ CoreConfigOverride<Rules>;
947
+
948
+ /**
949
+ * ESLint legacy configuration.
950
+ *
951
+ * @see [ESLint Legacy Configuration](https://eslint.org/docs/latest/use/configure/)
952
+ */
953
+ // https://github.com/eslint/eslint/blob/v8.57.0/conf/config-schema.js
954
+ type LegacyConfig<
955
+ Rules extends RulesConfig = RulesConfig,
956
+ OverrideRules extends RulesConfig = Rules,
957
+ > = LegacyConfigObject<Rules, OverrideRules>;
958
+
959
+ /**
960
+ * Parser options.
961
+ *
962
+ * @see [Specifying Parser Options](https://eslint.org/docs/latest/use/configure/language-options#specifying-parser-options)
963
+ */
964
+ type ParserOptions = JavaScriptParserOptionsConfig;
965
+
966
+ /**
967
+ * Options used for linting code with `Linter#verify` and `Linter#verifyAndFix`.
968
+ */
969
+ interface LintOptions {
970
+ filename?: string | undefined;
971
+ preprocess?: ((code: string) => string[]) | undefined;
972
+ postprocess?:
973
+ | ((problemLists: LintMessage[][]) => LintMessage[])
974
+ | undefined;
975
+ filterCodeBlock?:
976
+ | ((filename: string, text: string) => boolean)
977
+ | undefined;
978
+ disableFixes?: boolean | undefined;
979
+ allowInlineConfig?: boolean | undefined;
980
+ reportUnusedDisableDirectives?: boolean | undefined;
981
+ }
982
+
983
+ type LintSuggestion = CoreLintSuggestion;
984
+ type LintMessage = CoreLintMessage;
985
+
986
+ interface LintSuppression {
987
+ kind: string;
988
+ justification: string;
989
+ }
990
+
991
+ interface SuppressedLintMessage extends LintMessage {
992
+ /** The suppression info. */
993
+ suppressions: LintSuppression[];
994
+ }
995
+
996
+ interface FixOptions extends LintOptions {
997
+ fix?: boolean | undefined;
998
+ }
999
+
1000
+ interface FixReport {
1001
+ fixed: boolean;
1002
+ output: string;
1003
+ messages: LintMessage[];
1004
+ }
1005
+
1006
+ // Temporarily loosen type for just flat config files (see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/68232)
1007
+ type NonESTreeParser = ESLint.ObjectMetaProperties &
1008
+ (
1009
+ | {
1010
+ parse(text: string, options?: any): unknown;
1011
+ }
1012
+ | {
1013
+ parseForESLint(
1014
+ text: string,
1015
+ options?: any,
1016
+ ): Omit<ESLintParseResult, "ast" | "scopeManager"> & {
1017
+ ast: unknown;
1018
+ scopeManager?: unknown;
1019
+ };
1020
+ }
1021
+ );
1022
+
1023
+ type ESTreeParser = ESLint.ObjectMetaProperties &
1024
+ (
1025
+ | { parse(text: string, options?: any): AST.Program }
1026
+ | { parseForESLint(text: string, options?: any): ESLintParseResult }
1027
+ );
1028
+
1029
+ type Parser = NonESTreeParser | ESTreeParser;
1030
+
1031
+ interface ESLintParseResult {
1032
+ /** The AST object. */
1033
+ ast: AST.Program;
1034
+
1035
+ /** The services that the parser provides. */
1036
+ services?: SourceCode.ParserServices | undefined;
1037
+
1038
+ /** The scope manager of the AST. */
1039
+ scopeManager?: Scope.ScopeManager | undefined;
1040
+
1041
+ /** The visitor keys of the AST. */
1042
+ visitorKeys?: SourceCode.VisitorKeys | undefined;
1043
+ }
1044
+
1045
+ type ProcessorFile = CoreProcessorFile;
1046
+
1047
+ // https://eslint.org/docs/latest/extend/plugins#processors-in-plugins
1048
+ type Processor<T extends string | ProcessorFile = string | ProcessorFile> =
1049
+ CoreProcessor<T>;
1050
+
1051
+ type Config<Rules extends RulesConfig = RulesConfig> = ConfigObject<Rules>;
1052
+
1053
+ /** @deprecated Use `Config` instead of `FlatConfig` */
1054
+ type FlatConfig<Rules extends RulesConfig = RulesConfig> = Config<Rules>;
1055
+
1056
+ type GlobalConf = GlobalAccess;
1057
+ type Globals = GlobalsConfig;
1058
+
1059
+ interface LanguageOptions extends GenericLanguageOptions {
1060
+ /**
1061
+ * The version of ECMAScript to support. May be any year (i.e., 2022) or
1062
+ * version (i.e., 5). Set to "latest" for the most recent supported version.
1063
+ * @default "latest"
1064
+ */
1065
+ ecmaVersion?: EcmaVersion | undefined;
1066
+
1067
+ /**
1068
+ * The type of JavaScript source code. Possible values are "script" for
1069
+ * traditional script files, "module" for ECMAScript modules (ESM), and
1070
+ * "commonjs" for CommonJS files. (default: "module" for .js and .mjs
1071
+ * files; "commonjs" for .cjs files)
1072
+ */
1073
+ sourceType?: SourceType | undefined;
1074
+
1075
+ /**
1076
+ * An object specifying additional objects that should be added to the
1077
+ * global scope during linting.
1078
+ */
1079
+ globals?: Globals | undefined;
1080
+
1081
+ /**
1082
+ * An object containing a parse() or parseForESLint() method.
1083
+ * If not configured, the default ESLint parser (Espree) will be used.
1084
+ */
1085
+ parser?: Parser | undefined;
1086
+
1087
+ /**
1088
+ * An object specifying additional options that are passed directly to the
1089
+ * parser() method on the parser. The available options are parser-dependent
1090
+ */
1091
+ parserOptions?: Linter.ParserOptions | undefined;
1092
+ }
1093
+
1094
+ type LinterOptions = LinterOptionsConfig;
1095
+
1096
+ /**
1097
+ * Performance statistics.
1098
+ */
1099
+ interface Stats {
1100
+ /**
1101
+ * The number of times ESLint has applied at least one fix after linting.
1102
+ */
1103
+ fixPasses: number;
1104
+
1105
+ /**
1106
+ * The times spent on (parsing, fixing, linting) a file, where the linting refers to the timing information for each rule.
1107
+ */
1108
+ times: { passes: TimePass[] };
1109
+ }
1110
+
1111
+ interface TimePass {
1112
+ /**
1113
+ * The parse object containing all parse time information.
1114
+ */
1115
+ parse: { total: number };
1116
+
1117
+ /**
1118
+ * The rules object containing all lint time information for each rule.
1119
+ */
1120
+ rules?: Record<string, { total: number }>;
1121
+
1122
+ /**
1123
+ * The fix object containing all fix time information.
1124
+ */
1125
+ fix: { total: number };
1126
+
1127
+ /**
1128
+ * The total time that is spent on (parsing, fixing, linting) a file.
1129
+ */
1130
+ total: number;
1131
+ }
1132
+ }
1133
+
1134
+ // #endregion
1135
+
1136
+ // #region ESLint
1137
+
1138
+ export class ESLint {
1139
+ static configType: "flat";
1140
+
1141
+ static readonly version: string;
1142
+
1143
+ /**
1144
+ * The default configuration that ESLint uses internally. This is provided for tooling that wants to calculate configurations using the same defaults as ESLint.
1145
+ * Keep in mind that the default configuration may change from version to version, so you shouldn't rely on any particular keys or values to be present.
1146
+ */
1147
+ static readonly defaultConfig: Linter.Config[];
1148
+
1149
+ static outputFixes(results: ESLint.LintResult[]): Promise<void>;
1150
+
1151
+ static getErrorResults(results: ESLint.LintResult[]): ESLint.LintResult[];
1152
+
1153
+ constructor(options?: ESLint.Options);
1154
+
1155
+ lintFiles(patterns: string | string[]): Promise<ESLint.LintResult[]>;
1156
+
1157
+ lintText(
1158
+ code: string,
1159
+ options?: {
1160
+ filePath?: string | undefined;
1161
+ warnIgnored?: boolean | undefined;
1162
+ },
1163
+ ): Promise<ESLint.LintResult[]>;
1164
+
1165
+ getRulesMetaForResults(
1166
+ results: ESLint.LintResult[],
1167
+ ): ESLint.LintResultData["rulesMeta"];
1168
+
1169
+ hasFlag(flag: string): boolean;
1170
+
1171
+ calculateConfigForFile(filePath: string): Promise<any>;
1172
+
1173
+ findConfigFile(filePath?: string): Promise<string | undefined>;
1174
+
1175
+ isPathIgnored(filePath: string): Promise<boolean>;
1176
+
1177
+ loadFormatter(nameOrPath?: string): Promise<ESLint.LoadedFormatter>;
1178
+
1179
+ static fromOptionsModule(optionsURL: {
1180
+ readonly href: string;
1181
+ }): Promise<ESLint>;
1182
+ }
1183
+
1184
+ export namespace ESLint {
1185
+ type ConfigData<Rules extends Linter.RulesRecord = RulesConfig> = Omit<
1186
+ Linter.LegacyConfig<Rules>,
1187
+ "$schema"
1188
+ >;
1189
+
1190
+ type Environment = EnvironmentConfig;
1191
+ type ObjectMetaProperties = CoreObjectMetaProperties;
1192
+ type Plugin = CorePlugin;
1193
+
1194
+ type FixType = "directive" | "problem" | "suggestion" | "layout";
1195
+
1196
+ type CacheStrategy = "content" | "metadata";
1197
+
1198
+ interface Options {
1199
+ // File enumeration
1200
+ cwd?: string | undefined;
1201
+ errorOnUnmatchedPattern?: boolean | undefined;
1202
+ globInputPaths?: boolean | undefined;
1203
+ ignore?: boolean | undefined;
1204
+ ignorePatterns?: string[] | null | undefined;
1205
+ passOnNoPatterns?: boolean | undefined;
1206
+ warnIgnored?: boolean | undefined;
1207
+
1208
+ // Linting
1209
+ allowInlineConfig?: boolean | undefined;
1210
+ baseConfig?: Linter.Config | Linter.Config[] | null | undefined;
1211
+ overrideConfig?: Linter.Config | Linter.Config[] | null | undefined;
1212
+ overrideConfigFile?: string | true | null | undefined;
1213
+ plugins?: Record<string, Plugin> | null | undefined;
1214
+ ruleFilter?:
1215
+ | ((arg: {
1216
+ ruleId: string;
1217
+ severity: Exclude<Linter.Severity, 0>;
1218
+ }) => boolean)
1219
+ | undefined;
1220
+ stats?: boolean | undefined;
1221
+
1222
+ // Autofix
1223
+ fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
1224
+ fixTypes?: FixType[] | null | undefined;
1225
+
1226
+ // Cache-related
1227
+ cache?: boolean | undefined;
1228
+ cacheLocation?: string | undefined;
1229
+ cacheStrategy?: CacheStrategy | undefined;
1230
+
1231
+ // Other Options
1232
+ concurrency?: number | "auto" | "off" | undefined;
1233
+ flags?: string[] | undefined;
1234
+ }
1235
+
1236
+ interface LegacyOptions {
1237
+ // File enumeration
1238
+ cwd?: string | undefined;
1239
+ errorOnUnmatchedPattern?: boolean | undefined;
1240
+ extensions?: string[] | undefined;
1241
+ globInputPaths?: boolean | undefined;
1242
+ ignore?: boolean | undefined;
1243
+ ignorePath?: string | undefined;
1244
+
1245
+ // Linting
1246
+ allowInlineConfig?: boolean | undefined;
1247
+ baseConfig?: Linter.LegacyConfig | undefined;
1248
+ overrideConfig?: Linter.LegacyConfig | undefined;
1249
+ overrideConfigFile?: string | undefined;
1250
+ plugins?: Record<string, Plugin> | undefined;
1251
+ reportUnusedDisableDirectives?: Linter.StringSeverity | undefined;
1252
+ resolvePluginsRelativeTo?: string | undefined;
1253
+ rulePaths?: string[] | undefined;
1254
+ useEslintrc?: boolean | undefined;
1255
+
1256
+ // Autofix
1257
+ fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
1258
+ fixTypes?: FixType[] | null | undefined;
1259
+
1260
+ // Cache-related
1261
+ cache?: boolean | undefined;
1262
+ cacheLocation?: string | undefined;
1263
+ cacheStrategy?: CacheStrategy | undefined;
1264
+
1265
+ // Other Options
1266
+ flags?: string[] | undefined;
1267
+ }
1268
+
1269
+ /** A linting result. */
1270
+ interface LintResult {
1271
+ /** The path to the file that was linted. */
1272
+ filePath: string;
1273
+
1274
+ /** All of the messages for the result. */
1275
+ messages: Linter.LintMessage[];
1276
+
1277
+ /** All of the suppressed messages for the result. */
1278
+ suppressedMessages: Linter.SuppressedLintMessage[];
1279
+
1280
+ /** Number of errors for the result. */
1281
+ errorCount: number;
1282
+
1283
+ /** Number of fatal errors for the result. */
1284
+ fatalErrorCount: number;
1285
+
1286
+ /** Number of warnings for the result. */
1287
+ warningCount: number;
1288
+
1289
+ /** Number of fixable errors for the result. */
1290
+ fixableErrorCount: number;
1291
+
1292
+ /** Number of fixable warnings for the result. */
1293
+ fixableWarningCount: number;
1294
+
1295
+ /** The source code of the file that was linted, with as many fixes applied as possible. */
1296
+ output?: string | undefined;
1297
+
1298
+ /** The source code of the file that was linted. */
1299
+ source?: string | undefined;
1300
+
1301
+ /** The performance statistics collected with the `stats` flag. */
1302
+ stats?: Linter.Stats | undefined;
1303
+
1304
+ /** The list of used deprecated rules. */
1305
+ usedDeprecatedRules: DeprecatedRuleUse[];
1306
+ }
1307
+
1308
+ /**
1309
+ * Information provided when the maximum warning threshold is exceeded.
1310
+ */
1311
+ interface MaxWarningsExceeded {
1312
+ /**
1313
+ * Number of warnings to trigger nonzero exit code.
1314
+ */
1315
+ maxWarnings: number;
1316
+
1317
+ /**
1318
+ * Number of warnings found while linting.
1319
+ */
1320
+ foundWarnings: number;
1321
+ }
1322
+
1323
+ interface LintResultData {
1324
+ cwd: string;
1325
+ maxWarningsExceeded?: MaxWarningsExceeded | undefined;
1326
+ rulesMeta: {
1327
+ [ruleId: string]: Rule.RuleMetaData;
1328
+ };
1329
+ }
1330
+
1331
+ /**
1332
+ * Information about deprecated rules.
1333
+ */
1334
+ interface DeprecatedRuleUse {
1335
+ /**
1336
+ * The rule ID.
1337
+ */
1338
+ ruleId: string;
1339
+
1340
+ /**
1341
+ * The rule IDs that replace this deprecated rule.
1342
+ */
1343
+ replacedBy: string[];
1344
+
1345
+ /**
1346
+ * The raw deprecated info provided by the rule.
1347
+ * - Undefined if the rule's `meta.deprecated` property is a boolean.
1348
+ * - Unset when using the legacy eslintrc configuration.
1349
+ */
1350
+ info?: DeprecatedInfo | undefined;
1351
+ }
1352
+
1353
+ /**
1354
+ * Metadata about results for formatters.
1355
+ */
1356
+ interface ResultsMeta {
1357
+ /**
1358
+ * Present if the maxWarnings threshold was exceeded.
1359
+ */
1360
+ maxWarningsExceeded?: MaxWarningsExceeded | undefined;
1361
+ }
1362
+
1363
+ /** The type of an object resolved by {@link ESLint.loadFormatter}. */
1364
+ interface LoadedFormatter {
1365
+ /**
1366
+ * Used to call the underlying formatter.
1367
+ * @param results An array of lint results to format.
1368
+ * @param resultsMeta An object with an optional `maxWarningsExceeded` property that will be
1369
+ * passed to the underlying formatter function along with other properties set by ESLint.
1370
+ * This argument can be omitted if `maxWarningsExceeded` is not needed.
1371
+ * @return The formatter output.
1372
+ */
1373
+ format(
1374
+ results: LintResult[],
1375
+ resultsMeta?: ResultsMeta,
1376
+ ): string | Promise<string>;
1377
+ }
1378
+
1379
+ // The documented type name is `LoadedFormatter`, but `Formatter` has been historically more used.
1380
+ type Formatter = LoadedFormatter;
1381
+
1382
+ /**
1383
+ * The expected signature of a custom formatter.
1384
+ * @param results An array of lint results to format.
1385
+ * @param context Additional information for the formatter.
1386
+ * @return The formatter output.
1387
+ */
1388
+ type FormatterFunction = (
1389
+ results: LintResult[],
1390
+ context: LintResultData,
1391
+ ) => string | Promise<string>;
1392
+
1393
+ // Docs reference the types by those name
1394
+ type EditInfo = Rule.Fix;
1395
+ }
1396
+
1397
+ // #endregion
1398
+
1399
+ export function loadESLint(options: {
1400
+ useFlatConfig: true;
1401
+ }): Promise<typeof ESLint>;
1402
+ export function loadESLint(options: {
1403
+ useFlatConfig: false;
1404
+ }): Promise<typeof LegacyESLint>;
1405
+ export function loadESLint(options?: {
1406
+ useFlatConfig?: boolean | undefined;
1407
+ }): Promise<typeof ESLint | typeof LegacyESLint>;
1408
+
1409
+ // #region RuleTester
1410
+
1411
+ export class RuleTester {
1412
+ static describe: ((...args: any) => any) | null;
1413
+ static it: ((...args: any) => any) | null;
1414
+ static itOnly: ((...args: any) => any) | null;
1415
+
1416
+ constructor(config?: Linter.Config);
1417
+
1418
+ run(
1419
+ name: string,
1420
+ rule: RuleDefinition,
1421
+ tests: {
1422
+ valid: Array<string | RuleTester.ValidTestCase>;
1423
+ invalid: RuleTester.InvalidTestCase[];
1424
+ },
1425
+ ): void;
1426
+
1427
+ static only(
1428
+ item: string | RuleTester.ValidTestCase | RuleTester.InvalidTestCase,
1429
+ ): RuleTester.ValidTestCase | RuleTester.InvalidTestCase;
1430
+ }
1431
+
1432
+ export namespace RuleTester {
1433
+ interface ValidTestCase {
1434
+ name?: string;
1435
+ code: string;
1436
+ options?: any;
1437
+ filename?: string | undefined;
1438
+ only?: boolean;
1439
+ languageOptions?: Linter.LanguageOptions | undefined;
1440
+ settings?: { [name: string]: any } | undefined;
1441
+ before?: () => void;
1442
+ after?: () => void;
1443
+ }
1444
+
1445
+ interface SuggestionOutput {
1446
+ messageId?: string;
1447
+ desc?: string;
1448
+ data?: Record<string, unknown> | undefined;
1449
+ output: string;
1450
+ }
1451
+
1452
+ interface InvalidTestCase extends ValidTestCase {
1453
+ errors: number | Array<TestCaseError | string>;
1454
+ output?: string | null | undefined;
1455
+ }
1456
+
1457
+ interface TestCaseError {
1458
+ message?: string | RegExp;
1459
+ messageId?: string;
1460
+ /**
1461
+ * @deprecated `type` is deprecated and will be removed in the next major version.
1462
+ */
1463
+ type?: string | undefined;
1464
+ data?: any;
1465
+ line?: number | undefined;
1466
+ column?: number | undefined;
1467
+ endLine?: number | undefined;
1468
+ endColumn?: number | undefined;
1469
+ suggestions?: SuggestionOutput[] | undefined;
1470
+ }
1471
+ }
1472
+
1473
+ // #endregion