eslint 9.22.0 → 9.24.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 (417) hide show
  1. package/README.md +48 -46
  2. package/bin/eslint.js +92 -90
  3. package/conf/default-cli-options.js +22 -22
  4. package/conf/ecma-version.js +1 -1
  5. package/conf/globals.js +97 -98
  6. package/conf/replacements.json +24 -20
  7. package/conf/rule-type-list.json +88 -92
  8. package/lib/api.js +12 -12
  9. package/lib/cli-engine/cli-engine.js +830 -810
  10. package/lib/cli-engine/file-enumerator.js +381 -387
  11. package/lib/cli-engine/formatters/formatters-meta.json +16 -16
  12. package/lib/cli-engine/formatters/html.js +107 -99
  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 +96 -75
  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 +144 -145
  19. package/lib/cli-engine/load-rules.js +16 -16
  20. package/lib/cli.js +638 -457
  21. package/lib/config/config-loader.js +726 -622
  22. package/lib/config/config.js +247 -221
  23. package/lib/config/default-config.js +54 -45
  24. package/lib/config/flat-config-array.js +167 -172
  25. package/lib/config/flat-config-helpers.js +72 -72
  26. package/lib/config/flat-config-schema.js +375 -368
  27. package/lib/config/rule-validator.js +139 -144
  28. package/lib/config-api.js +2 -2
  29. package/lib/eslint/eslint-helpers.js +756 -681
  30. package/lib/eslint/eslint.js +934 -912
  31. package/lib/eslint/index.js +2 -2
  32. package/lib/eslint/legacy-eslint.js +577 -533
  33. package/lib/languages/js/index.js +263 -264
  34. package/lib/languages/js/source-code/index.js +1 -1
  35. package/lib/languages/js/source-code/source-code.js +1128 -1057
  36. package/lib/languages/js/source-code/token-store/backward-token-comment-cursor.js +39 -35
  37. package/lib/languages/js/source-code/token-store/backward-token-cursor.js +35 -36
  38. package/lib/languages/js/source-code/token-store/cursor.js +36 -36
  39. package/lib/languages/js/source-code/token-store/cursors.js +80 -52
  40. package/lib/languages/js/source-code/token-store/decorative-cursor.js +17 -18
  41. package/lib/languages/js/source-code/token-store/filter-cursor.js +19 -20
  42. package/lib/languages/js/source-code/token-store/forward-token-comment-cursor.js +40 -32
  43. package/lib/languages/js/source-code/token-store/forward-token-cursor.js +40 -41
  44. package/lib/languages/js/source-code/token-store/index.js +592 -498
  45. package/lib/languages/js/source-code/token-store/limit-cursor.js +17 -18
  46. package/lib/languages/js/source-code/token-store/padded-token-cursor.js +23 -16
  47. package/lib/languages/js/source-code/token-store/skip-cursor.js +19 -20
  48. package/lib/languages/js/source-code/token-store/utils.js +63 -60
  49. package/lib/languages/js/validate-language-options.js +104 -89
  50. package/lib/linter/apply-disable-directives.js +467 -383
  51. package/lib/linter/code-path-analysis/code-path-analyzer.js +650 -672
  52. package/lib/linter/code-path-analysis/code-path-segment.js +215 -216
  53. package/lib/linter/code-path-analysis/code-path-state.js +2118 -2096
  54. package/lib/linter/code-path-analysis/code-path.js +307 -319
  55. package/lib/linter/code-path-analysis/debug-helpers.js +183 -163
  56. package/lib/linter/code-path-analysis/fork-context.js +296 -271
  57. package/lib/linter/code-path-analysis/id-generator.js +22 -23
  58. package/lib/linter/file-context.js +119 -120
  59. package/lib/linter/index.js +3 -3
  60. package/lib/linter/interpolate.js +16 -16
  61. package/lib/linter/linter.js +2403 -2045
  62. package/lib/linter/node-event-generator.js +284 -225
  63. package/lib/linter/report-translator.js +256 -219
  64. package/lib/linter/rule-fixer.js +122 -124
  65. package/lib/linter/rules.js +36 -36
  66. package/lib/linter/safe-emitter.js +18 -18
  67. package/lib/linter/source-code-fixer.js +94 -92
  68. package/lib/linter/timing.js +104 -101
  69. package/lib/linter/vfile.js +70 -73
  70. package/lib/options.js +404 -361
  71. package/lib/rule-tester/index.js +1 -1
  72. package/lib/rule-tester/rule-tester.js +1308 -1046
  73. package/lib/rules/accessor-pairs.js +298 -263
  74. package/lib/rules/array-bracket-newline.js +250 -238
  75. package/lib/rules/array-bracket-spacing.js +263 -224
  76. package/lib/rules/array-callback-return.js +402 -356
  77. package/lib/rules/array-element-newline.js +358 -313
  78. package/lib/rules/arrow-body-style.js +400 -281
  79. package/lib/rules/arrow-parens.js +206 -173
  80. package/lib/rules/arrow-spacing.js +169 -163
  81. package/lib/rules/block-scoped-var.js +125 -123
  82. package/lib/rules/block-spacing.js +186 -176
  83. package/lib/rules/brace-style.js +262 -199
  84. package/lib/rules/callback-return.js +203 -190
  85. package/lib/rules/camelcase.js +403 -392
  86. package/lib/rules/capitalized-comments.js +253 -232
  87. package/lib/rules/class-methods-use-this.js +224 -172
  88. package/lib/rules/comma-dangle.js +379 -346
  89. package/lib/rules/comma-spacing.js +193 -195
  90. package/lib/rules/comma-style.js +375 -316
  91. package/lib/rules/complexity.js +173 -169
  92. package/lib/rules/computed-property-spacing.js +236 -211
  93. package/lib/rules/consistent-return.js +181 -170
  94. package/lib/rules/consistent-this.js +167 -147
  95. package/lib/rules/constructor-super.js +412 -404
  96. package/lib/rules/curly.js +407 -332
  97. package/lib/rules/default-case-last.js +38 -31
  98. package/lib/rules/default-case.js +89 -85
  99. package/lib/rules/default-param-last.js +69 -54
  100. package/lib/rules/dot-location.js +122 -110
  101. package/lib/rules/dot-notation.js +192 -156
  102. package/lib/rules/eol-last.js +122 -120
  103. package/lib/rules/eqeqeq.js +168 -155
  104. package/lib/rules/for-direction.js +146 -121
  105. package/lib/rules/func-call-spacing.js +261 -231
  106. package/lib/rules/func-name-matching.js +293 -209
  107. package/lib/rules/func-names.js +165 -164
  108. package/lib/rules/func-style.js +159 -127
  109. package/lib/rules/function-call-argument-newline.js +152 -129
  110. package/lib/rules/function-paren-newline.js +349 -291
  111. package/lib/rules/generator-star-spacing.js +229 -210
  112. package/lib/rules/getter-return.js +208 -172
  113. package/lib/rules/global-require.js +85 -74
  114. package/lib/rules/grouped-accessor-pairs.js +170 -150
  115. package/lib/rules/guard-for-in.js +72 -63
  116. package/lib/rules/handle-callback-err.js +108 -103
  117. package/lib/rules/id-blacklist.js +182 -199
  118. package/lib/rules/id-denylist.js +168 -187
  119. package/lib/rules/id-length.js +197 -171
  120. package/lib/rules/id-match.js +344 -289
  121. package/lib/rules/implicit-arrow-linebreak.js +102 -79
  122. package/lib/rules/indent-legacy.js +1344 -1118
  123. package/lib/rules/indent.js +2272 -1759
  124. package/lib/rules/index.js +317 -292
  125. package/lib/rules/init-declarations.js +137 -107
  126. package/lib/rules/jsx-quotes.js +94 -82
  127. package/lib/rules/key-spacing.js +750 -633
  128. package/lib/rules/keyword-spacing.js +648 -605
  129. package/lib/rules/line-comment-position.js +142 -128
  130. package/lib/rules/linebreak-style.js +107 -106
  131. package/lib/rules/lines-around-comment.js +540 -448
  132. package/lib/rules/lines-around-directive.js +233 -203
  133. package/lib/rules/lines-between-class-members.js +305 -234
  134. package/lib/rules/logical-assignment-operators.js +582 -399
  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 -434
  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 +78 -76
  142. package/lib/rules/max-statements-per-line.js +205 -198
  143. package/lib/rules/max-statements.js +168 -164
  144. package/lib/rules/multiline-comment-style.js +637 -479
  145. package/lib/rules/multiline-ternary.js +241 -176
  146. package/lib/rules/new-cap.js +233 -213
  147. package/lib/rules/new-parens.js +88 -79
  148. package/lib/rules/newline-after-var.js +287 -250
  149. package/lib/rules/newline-before-return.js +229 -222
  150. package/lib/rules/newline-per-chained-call.js +142 -127
  151. package/lib/rules/no-alert.js +90 -79
  152. package/lib/rules/no-array-constructor.js +125 -113
  153. package/lib/rules/no-async-promise-executor.js +30 -24
  154. package/lib/rules/no-await-in-loop.js +69 -71
  155. package/lib/rules/no-bitwise.js +124 -100
  156. package/lib/rules/no-buffer-constructor.js +55 -47
  157. package/lib/rules/no-caller.js +39 -33
  158. package/lib/rules/no-case-declarations.js +61 -57
  159. package/lib/rules/no-catch-shadow.js +76 -73
  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 -81
  164. package/lib/rules/no-console.js +202 -199
  165. package/lib/rules/no-const-assign.js +47 -41
  166. package/lib/rules/no-constant-binary-expression.js +500 -405
  167. package/lib/rules/no-constant-condition.js +158 -143
  168. package/lib/rules/no-constructor-return.js +49 -49
  169. package/lib/rules/no-continue.js +25 -27
  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 -41
  174. package/lib/rules/no-dupe-args.js +68 -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 +179 -176
  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 +127 -128
  183. package/lib/rules/no-empty-pattern.js +63 -58
  184. package/lib/rules/no-empty-static-block.js +37 -35
  185. package/lib/rules/no-empty.js +98 -86
  186. package/lib/rules/no-eq-null.js +37 -32
  187. package/lib/rules/no-eval.js +256 -250
  188. package/lib/rules/no-ex-assign.js +42 -39
  189. package/lib/rules/no-extend-native.js +161 -159
  190. package/lib/rules/no-extra-bind.js +201 -190
  191. package/lib/rules/no-extra-boolean-cast.js +398 -348
  192. package/lib/rules/no-extra-label.js +150 -131
  193. package/lib/rules/no-extra-parens.js +1654 -1325
  194. package/lib/rules/no-extra-semi.js +146 -144
  195. package/lib/rules/no-fallthrough.js +199 -157
  196. package/lib/rules/no-floating-decimal.js +74 -66
  197. package/lib/rules/no-func-assign.js +54 -55
  198. package/lib/rules/no-global-assign.js +78 -73
  199. package/lib/rules/no-implicit-coercion.js +349 -293
  200. package/lib/rules/no-implicit-globals.js +158 -135
  201. package/lib/rules/no-implied-eval.js +140 -112
  202. package/lib/rules/no-import-assign.js +145 -159
  203. package/lib/rules/no-inline-comments.js +101 -95
  204. package/lib/rules/no-inner-declarations.js +115 -101
  205. package/lib/rules/no-invalid-regexp.js +222 -190
  206. package/lib/rules/no-invalid-this.js +123 -117
  207. package/lib/rules/no-irregular-whitespace.js +266 -252
  208. package/lib/rules/no-iterator.js +29 -33
  209. package/lib/rules/no-label-var.js +59 -62
  210. package/lib/rules/no-labels.js +138 -133
  211. package/lib/rules/no-lone-blocks.js +127 -123
  212. package/lib/rules/no-lonely-if.js +108 -77
  213. package/lib/rules/no-loop-func.js +238 -213
  214. package/lib/rules/no-loss-of-precision.js +218 -201
  215. package/lib/rules/no-magic-numbers.js +246 -218
  216. package/lib/rules/no-misleading-character-class.js +499 -446
  217. package/lib/rules/no-mixed-operators.js +188 -182
  218. package/lib/rules/no-mixed-requires.js +253 -240
  219. package/lib/rules/no-mixed-spaces-and-tabs.js +134 -121
  220. package/lib/rules/no-multi-assign.js +46 -44
  221. package/lib/rules/no-multi-spaces.js +163 -143
  222. package/lib/rules/no-multi-str.js +42 -41
  223. package/lib/rules/no-multiple-empty-lines.js +196 -158
  224. package/lib/rules/no-native-reassign.js +90 -85
  225. package/lib/rules/no-negated-condition.js +79 -75
  226. package/lib/rules/no-negated-in-lhs.js +45 -43
  227. package/lib/rules/no-nested-ternary.js +33 -32
  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 -48
  231. package/lib/rules/no-new-require.js +48 -47
  232. package/lib/rules/no-new-symbol.js +52 -50
  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 +141 -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 +32 -32
  240. package/lib/rules/no-param-reassign.js +235 -217
  241. package/lib/rules/no-path-concat.js +66 -67
  242. package/lib/rules/no-plusplus.js +60 -61
  243. package/lib/rules/no-process-env.js +49 -48
  244. package/lib/rules/no-process-exit.js +54 -50
  245. package/lib/rules/no-promise-executor-return.js +214 -182
  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 -152
  249. package/lib/rules/no-regex-spaces.js +183 -161
  250. package/lib/rules/no-restricted-exports.js +208 -185
  251. package/lib/rules/no-restricted-globals.js +111 -112
  252. package/lib/rules/no-restricted-imports.js +657 -537
  253. package/lib/rules/no-restricted-modules.js +222 -202
  254. package/lib/rules/no-restricted-properties.js +181 -153
  255. package/lib/rules/no-restricted-syntax.js +56 -52
  256. package/lib/rules/no-return-assign.js +55 -50
  257. package/lib/rules/no-return-await.js +148 -124
  258. package/lib/rules/no-script-url.js +52 -45
  259. package/lib/rules/no-self-assign.js +148 -146
  260. package/lib/rules/no-self-compare.js +63 -46
  261. package/lib/rules/no-sequences.js +135 -116
  262. package/lib/rules/no-setter-return.js +185 -152
  263. package/lib/rules/no-shadow-restricted-names.js +61 -46
  264. package/lib/rules/no-shadow.js +342 -316
  265. package/lib/rules/no-spaced-func.js +82 -77
  266. package/lib/rules/no-sparse-arrays.js +54 -59
  267. package/lib/rules/no-sync.js +61 -60
  268. package/lib/rules/no-tabs.js +83 -72
  269. package/lib/rules/no-template-curly-in-string.js +33 -32
  270. package/lib/rules/no-ternary.js +25 -29
  271. package/lib/rules/no-this-before-super.js +321 -319
  272. package/lib/rules/no-throw-literal.js +31 -36
  273. package/lib/rules/no-trailing-spaces.js +199 -191
  274. package/lib/rules/no-undef-init.js +76 -61
  275. package/lib/rules/no-undef.js +51 -48
  276. package/lib/rules/no-undefined.js +73 -75
  277. package/lib/rules/no-underscore-dangle.js +370 -327
  278. package/lib/rules/no-unexpected-multiline.js +112 -102
  279. package/lib/rules/no-unmodified-loop-condition.js +254 -254
  280. package/lib/rules/no-unneeded-ternary.js +212 -147
  281. package/lib/rules/no-unreachable-loop.js +145 -142
  282. package/lib/rules/no-unreachable.js +255 -248
  283. package/lib/rules/no-unsafe-finally.js +93 -85
  284. package/lib/rules/no-unsafe-negation.js +105 -83
  285. package/lib/rules/no-unsafe-optional-chaining.js +192 -178
  286. package/lib/rules/no-unused-expressions.js +178 -162
  287. package/lib/rules/no-unused-labels.js +139 -124
  288. package/lib/rules/no-unused-private-class-members.js +206 -182
  289. package/lib/rules/no-unused-vars.js +1669 -1449
  290. package/lib/rules/no-use-before-define.js +229 -231
  291. package/lib/rules/no-useless-assignment.js +590 -511
  292. package/lib/rules/no-useless-backreference.js +212 -193
  293. package/lib/rules/no-useless-call.js +58 -53
  294. package/lib/rules/no-useless-catch.js +40 -40
  295. package/lib/rules/no-useless-computed-key.js +144 -115
  296. package/lib/rules/no-useless-concat.js +65 -60
  297. package/lib/rules/no-useless-constructor.js +158 -111
  298. package/lib/rules/no-useless-escape.js +342 -291
  299. package/lib/rules/no-useless-rename.js +183 -156
  300. package/lib/rules/no-useless-return.js +344 -312
  301. package/lib/rules/no-var.js +233 -212
  302. package/lib/rules/no-void.js +50 -48
  303. package/lib/rules/no-warning-comments.js +191 -186
  304. package/lib/rules/no-whitespace-before-property.js +131 -115
  305. package/lib/rules/no-with.js +24 -26
  306. package/lib/rules/nonblock-statement-body-position.js +149 -130
  307. package/lib/rules/object-curly-newline.js +306 -265
  308. package/lib/rules/object-curly-spacing.js +360 -314
  309. package/lib/rules/object-property-newline.js +137 -106
  310. package/lib/rules/object-shorthand.js +607 -502
  311. package/lib/rules/one-var-declaration-per-line.js +104 -100
  312. package/lib/rules/one-var.js +653 -537
  313. package/lib/rules/operator-assignment.js +219 -161
  314. package/lib/rules/operator-linebreak.js +295 -251
  315. package/lib/rules/padded-blocks.js +346 -308
  316. package/lib/rules/padding-line-between-statements.js +443 -439
  317. package/lib/rules/prefer-arrow-callback.js +362 -313
  318. package/lib/rules/prefer-const.js +418 -377
  319. package/lib/rules/prefer-destructuring.js +301 -279
  320. package/lib/rules/prefer-exponentiation-operator.js +176 -133
  321. package/lib/rules/prefer-named-capture-group.js +153 -140
  322. package/lib/rules/prefer-numeric-literals.js +121 -113
  323. package/lib/rules/prefer-object-has-own.js +116 -82
  324. package/lib/rules/prefer-object-spread.js +213 -193
  325. package/lib/rules/prefer-promise-reject-errors.js +140 -122
  326. package/lib/rules/prefer-reflect.js +127 -107
  327. package/lib/rules/prefer-regex-literals.js +578 -466
  328. package/lib/rules/prefer-rest-params.js +79 -80
  329. package/lib/rules/prefer-spread.js +47 -44
  330. package/lib/rules/prefer-template.js +266 -195
  331. package/lib/rules/quote-props.js +373 -307
  332. package/lib/rules/quotes.js +374 -326
  333. package/lib/rules/radix.js +152 -136
  334. package/lib/rules/require-atomic-updates.js +316 -285
  335. package/lib/rules/require-await.js +144 -116
  336. package/lib/rules/require-unicode-regexp.js +282 -177
  337. package/lib/rules/require-yield.js +53 -54
  338. package/lib/rules/rest-spread-spacing.js +128 -116
  339. package/lib/rules/semi-spacing.js +281 -250
  340. package/lib/rules/semi-style.js +176 -134
  341. package/lib/rules/semi.js +456 -436
  342. package/lib/rules/sort-imports.js +306 -233
  343. package/lib/rules/sort-keys.js +219 -188
  344. package/lib/rules/sort-vars.js +127 -93
  345. package/lib/rules/space-before-blocks.js +199 -189
  346. package/lib/rules/space-before-function-paren.js +186 -166
  347. package/lib/rules/space-in-parens.js +359 -288
  348. package/lib/rules/space-infix-ops.js +237 -201
  349. package/lib/rules/space-unary-ops.js +356 -298
  350. package/lib/rules/spaced-comment.js +363 -319
  351. package/lib/rules/strict.js +265 -230
  352. package/lib/rules/switch-colon-spacing.js +130 -122
  353. package/lib/rules/symbol-description.js +45 -48
  354. package/lib/rules/template-curly-spacing.js +148 -142
  355. package/lib/rules/template-tag-spacing.js +98 -88
  356. package/lib/rules/unicode-bom.js +54 -56
  357. package/lib/rules/use-isnan.js +237 -206
  358. package/lib/rules/utils/ast-utils.js +2039 -1860
  359. package/lib/rules/utils/char-source.js +162 -155
  360. package/lib/rules/utils/fix-tracker.js +83 -80
  361. package/lib/rules/utils/keywords.js +59 -59
  362. package/lib/rules/utils/lazy-loading-rule-map.js +79 -76
  363. package/lib/rules/utils/regular-expressions.js +32 -24
  364. package/lib/rules/utils/unicode/index.js +4 -4
  365. package/lib/rules/utils/unicode/is-combining-character.js +1 -1
  366. package/lib/rules/utils/unicode/is-emoji-modifier.js +1 -1
  367. package/lib/rules/utils/unicode/is-regional-indicator-symbol.js +1 -1
  368. package/lib/rules/utils/unicode/is-surrogate-pair.js +1 -1
  369. package/lib/rules/valid-typeof.js +153 -111
  370. package/lib/rules/vars-on-top.js +152 -145
  371. package/lib/rules/wrap-iife.js +204 -191
  372. package/lib/rules/wrap-regex.js +70 -58
  373. package/lib/rules/yield-star-spacing.js +145 -134
  374. package/lib/rules/yoda.js +283 -272
  375. package/lib/services/parser-service.js +35 -35
  376. package/lib/services/processor-service.js +66 -73
  377. package/lib/services/suppressions-service.js +289 -0
  378. package/lib/shared/ajv.js +14 -14
  379. package/lib/shared/assert.js +3 -4
  380. package/lib/shared/ast-utils.js +7 -6
  381. package/lib/shared/deep-merge-arrays.js +24 -22
  382. package/lib/shared/directives.js +3 -2
  383. package/lib/shared/flags.js +50 -17
  384. package/lib/shared/logging.js +24 -25
  385. package/lib/shared/option-utils.js +43 -36
  386. package/lib/shared/runtime-info.js +136 -127
  387. package/lib/shared/serialization.js +27 -27
  388. package/lib/shared/severity.js +22 -22
  389. package/lib/shared/stats.js +5 -5
  390. package/lib/shared/string-utils.js +16 -16
  391. package/lib/shared/text-table.js +28 -27
  392. package/lib/shared/traverser.js +153 -146
  393. package/lib/shared/types.js +4 -27
  394. package/lib/types/index.d.ts +2010 -1559
  395. package/lib/types/rules.d.ts +5253 -5140
  396. package/lib/types/use-at-your-own-risk.d.ts +32 -30
  397. package/lib/unsupported-api.js +5 -5
  398. package/messages/all-files-ignored.js +3 -3
  399. package/messages/all-matched-files-ignored.js +3 -3
  400. package/messages/config-file-missing.js +2 -2
  401. package/messages/config-plugin-missing.js +3 -3
  402. package/messages/config-serialize-function.js +9 -7
  403. package/messages/eslintrc-incompat.js +13 -15
  404. package/messages/eslintrc-plugins.js +3 -4
  405. package/messages/extend-config-missing.js +3 -3
  406. package/messages/failed-to-read-json.js +3 -3
  407. package/messages/file-not-found.js +3 -3
  408. package/messages/invalid-rule-options.js +2 -2
  409. package/messages/invalid-rule-severity.js +2 -2
  410. package/messages/no-config-found.js +3 -3
  411. package/messages/plugin-conflict.js +8 -8
  412. package/messages/plugin-invalid.js +3 -3
  413. package/messages/plugin-missing.js +3 -3
  414. package/messages/print-config-with-directory-path.js +2 -2
  415. package/messages/shared.js +6 -1
  416. package/messages/whitespace-found.js +3 -3
  417. package/package.json +14 -20
@@ -28,6 +28,12 @@ const MINIMATCH_OPTIONS = { dot: true };
28
28
  // Types
29
29
  //-----------------------------------------------------------------------------
30
30
 
31
+ /**
32
+ * @import { ESLintOptions } from "./eslint.js";
33
+ * @import { LintMessage, LintResult } from "../shared/types.js";
34
+ * @import { ConfigLoader, LegacyConfigLoader } from "../config/config-loader.js";
35
+ */
36
+
31
37
  /**
32
38
  * @typedef {Object} GlobSearch
33
39
  * @property {Array<string>} patterns The normalized patterns to use for a search.
@@ -43,58 +49,58 @@ const MINIMATCH_OPTIONS = { dot: true };
43
49
  * The error type when no files match a glob.
44
50
  */
45
51
  class NoFilesFoundError extends Error {
46
-
47
- /**
48
- * @param {string} pattern The glob pattern which was not found.
49
- * @param {boolean} globEnabled If `false` then the pattern was a glob pattern, but glob was disabled.
50
- */
51
- constructor(pattern, globEnabled) {
52
- super(`No files matching '${pattern}' were found${!globEnabled ? " (glob was disabled)" : ""}.`);
53
- this.messageTemplate = "file-not-found";
54
- this.messageData = { pattern, globDisabled: !globEnabled };
55
- }
52
+ /**
53
+ * @param {string} pattern The glob pattern which was not found.
54
+ * @param {boolean} globEnabled If `false` then the pattern was a glob pattern, but glob was disabled.
55
+ */
56
+ constructor(pattern, globEnabled) {
57
+ super(
58
+ `No files matching '${pattern}' were found${!globEnabled ? " (glob was disabled)" : ""}.`,
59
+ );
60
+ this.messageTemplate = "file-not-found";
61
+ this.messageData = { pattern, globDisabled: !globEnabled };
62
+ }
56
63
  }
57
64
 
58
65
  /**
59
66
  * The error type when a search fails to match multiple patterns.
60
67
  */
61
68
  class UnmatchedSearchPatternsError extends Error {
62
-
63
- /**
64
- * @param {Object} options The options for the error.
65
- * @param {string} options.basePath The directory that was searched.
66
- * @param {Array<string>} options.unmatchedPatterns The glob patterns
67
- * which were not found.
68
- * @param {Array<string>} options.patterns The glob patterns that were
69
- * searched.
70
- * @param {Array<string>} options.rawPatterns The raw glob patterns that
71
- * were searched.
72
- */
73
- constructor({ basePath, unmatchedPatterns, patterns, rawPatterns }) {
74
- super(`No files matching '${rawPatterns}' in '${basePath}' were found.`);
75
- this.basePath = basePath;
76
- this.unmatchedPatterns = unmatchedPatterns;
77
- this.patterns = patterns;
78
- this.rawPatterns = rawPatterns;
79
- }
69
+ /**
70
+ * @param {Object} options The options for the error.
71
+ * @param {string} options.basePath The directory that was searched.
72
+ * @param {Array<string>} options.unmatchedPatterns The glob patterns
73
+ * which were not found.
74
+ * @param {Array<string>} options.patterns The glob patterns that were
75
+ * searched.
76
+ * @param {Array<string>} options.rawPatterns The raw glob patterns that
77
+ * were searched.
78
+ */
79
+ constructor({ basePath, unmatchedPatterns, patterns, rawPatterns }) {
80
+ super(
81
+ `No files matching '${rawPatterns}' in '${basePath}' were found.`,
82
+ );
83
+ this.basePath = basePath;
84
+ this.unmatchedPatterns = unmatchedPatterns;
85
+ this.patterns = patterns;
86
+ this.rawPatterns = rawPatterns;
87
+ }
80
88
  }
81
89
 
82
90
  /**
83
91
  * The error type when there are files matched by a glob, but all of them have been ignored.
84
92
  */
85
93
  class AllFilesIgnoredError extends Error {
86
-
87
- /**
88
- * @param {string} pattern The glob pattern which was not found.
89
- */
90
- constructor(pattern) {
91
- super(`All files matched by '${pattern}' are ignored.`);
92
- this.messageTemplate = "all-matched-files-ignored";
93
- this.messageData = { pattern };
94
- }
94
+ /**
95
+ * @param {string} pattern The glob pattern which was not found.
96
+ */
97
+ constructor(pattern) {
98
+ super(`All files matched by '${pattern}' are ignored.`);
99
+ this.messageTemplate = "all-matched-files-ignored";
100
+ this.messageData = { pattern };
101
+ }
95
102
  }
96
103
 
97
-
98
104
  //-----------------------------------------------------------------------------
99
105
  // General Helpers
100
106
  //-----------------------------------------------------------------------------
@@ -105,7 +111,7 @@ class AllFilesIgnoredError extends Error {
105
111
  * @returns {boolean} `true` if `value` is a non-empty string.
106
112
  */
107
113
  function isNonEmptyString(value) {
108
- return typeof value === "string" && value.trim() !== "";
114
+ return typeof value === "string" && value.trim() !== "";
109
115
  }
110
116
 
111
117
  /**
@@ -114,7 +120,9 @@ function isNonEmptyString(value) {
114
120
  * @returns {boolean} `true` if `value` is an array of non-empty strings.
115
121
  */
116
122
  function isArrayOfNonEmptyString(value) {
117
- return Array.isArray(value) && value.length && value.every(isNonEmptyString);
123
+ return (
124
+ Array.isArray(value) && !!value.length && value.every(isNonEmptyString)
125
+ );
118
126
  }
119
127
 
120
128
  /**
@@ -124,7 +132,7 @@ function isArrayOfNonEmptyString(value) {
124
132
  * strings.
125
133
  */
126
134
  function isEmptyArrayOrArrayOfNonEmptyString(value) {
127
- return Array.isArray(value) && value.every(isNonEmptyString);
135
+ return Array.isArray(value) && value.every(isNonEmptyString);
128
136
  }
129
137
 
130
138
  //-----------------------------------------------------------------------------
@@ -137,7 +145,7 @@ function isEmptyArrayOrArrayOfNonEmptyString(value) {
137
145
  * @returns {string} The pattern with slashes normalized.
138
146
  */
139
147
  function normalizeToPosix(pattern) {
140
- return pattern.replace(/\\/gu, "/");
148
+ return pattern.replace(/\\/gu, "/");
141
149
  }
142
150
 
143
151
  /**
@@ -146,10 +154,9 @@ function normalizeToPosix(pattern) {
146
154
  * @returns {boolean} `true` if the string is a glob pattern.
147
155
  */
148
156
  function isGlobPattern(pattern) {
149
- return isGlob(path.sep === "\\" ? normalizeToPosix(pattern) : pattern);
157
+ return isGlob(path.sep === "\\" ? normalizeToPosix(pattern) : pattern);
150
158
  }
151
159
 
152
-
153
160
  /**
154
161
  * Determines if a given glob pattern will return any results.
155
162
  * Used primarily to help with useful error messages.
@@ -159,38 +166,39 @@ function isGlobPattern(pattern) {
159
166
  * @returns {Promise<boolean>} True if there is a glob match, false if not.
160
167
  */
161
168
  async function globMatch({ basePath, pattern }) {
162
-
163
- let found = false;
164
- const { hfs } = await import("@humanfs/node");
165
- const patternToUse = normalizeToPosix(path.relative(basePath, pattern));
166
-
167
- const matcher = new Minimatch(patternToUse, MINIMATCH_OPTIONS);
168
-
169
- const walkSettings = {
170
-
171
- directoryFilter(entry) {
172
- return !found && matcher.match(entry.path, true);
173
- },
174
-
175
- entryFilter(entry) {
176
- if (found || entry.isDirectory) {
177
- return false;
178
- }
179
-
180
- if (matcher.match(entry.path)) {
181
- found = true;
182
- return true;
183
- }
184
-
185
- return false;
186
- }
187
- };
188
-
189
- if (await hfs.isDirectory(basePath)) {
190
- return hfs.walk(basePath, walkSettings).next().then(() => found);
191
- }
192
-
193
- return found;
169
+ let found = false;
170
+ const { hfs } = await import("@humanfs/node");
171
+ const patternToUse = normalizeToPosix(path.relative(basePath, pattern));
172
+
173
+ const matcher = new Minimatch(patternToUse, MINIMATCH_OPTIONS);
174
+
175
+ const walkSettings = {
176
+ directoryFilter(entry) {
177
+ return !found && matcher.match(entry.path, true);
178
+ },
179
+
180
+ entryFilter(entry) {
181
+ if (found || entry.isDirectory) {
182
+ return false;
183
+ }
184
+
185
+ if (matcher.match(entry.path)) {
186
+ found = true;
187
+ return true;
188
+ }
189
+
190
+ return false;
191
+ },
192
+ };
193
+
194
+ if (await hfs.isDirectory(basePath)) {
195
+ return hfs
196
+ .walk(basePath, walkSettings)
197
+ .next()
198
+ .then(() => found);
199
+ }
200
+
201
+ return found;
194
202
  }
195
203
 
196
204
  /**
@@ -214,130 +222,128 @@ async function globMatch({ basePath, pattern }) {
214
222
  * match any files.
215
223
  */
216
224
  async function globSearch({
217
- basePath,
218
- patterns,
219
- rawPatterns,
220
- configLoader,
221
- errorOnUnmatchedPattern
225
+ basePath,
226
+ patterns,
227
+ rawPatterns,
228
+ configLoader,
229
+ errorOnUnmatchedPattern,
222
230
  }) {
223
-
224
- if (patterns.length === 0) {
225
- return [];
226
- }
227
-
228
- /*
229
- * In this section we are converting the patterns into Minimatch
230
- * instances for performance reasons. Because we are doing the same
231
- * matches repeatedly, it's best to compile those patterns once and
232
- * reuse them multiple times.
233
- *
234
- * To do that, we convert any patterns with an absolute path into a
235
- * relative path and normalize it to Posix-style slashes. We also keep
236
- * track of the relative patterns to map them back to the original
237
- * patterns, which we need in order to throw an error if there are any
238
- * unmatched patterns.
239
- */
240
- const relativeToPatterns = new Map();
241
- const matchers = patterns.map((pattern, i) => {
242
- const patternToUse = normalizeToPosix(path.relative(basePath, pattern));
243
-
244
- relativeToPatterns.set(patternToUse, patterns[i]);
245
-
246
- return new Minimatch(patternToUse, MINIMATCH_OPTIONS);
247
- });
248
-
249
- /*
250
- * We track unmatched patterns because we may want to throw an error when
251
- * they occur. To start, this set is initialized with all of the patterns.
252
- * Every time a match occurs, the pattern is removed from the set, making
253
- * it easy to tell if we have any unmatched patterns left at the end of
254
- * search.
255
- */
256
- const unmatchedPatterns = new Set([...relativeToPatterns.keys()]);
257
- const { hfs } = await import("@humanfs/node");
258
-
259
- const walk = hfs.walk(
260
- basePath,
261
- {
262
- async directoryFilter(entry) {
263
-
264
- if (!matchers.some(matcher => matcher.match(entry.path, true))) {
265
- return false;
266
- }
267
-
268
- const absolutePath = path.resolve(basePath, entry.path);
269
- const configs = await configLoader.loadConfigArrayForDirectory(absolutePath);
270
-
271
- return !configs.isDirectoryIgnored(absolutePath);
272
- },
273
- async entryFilter(entry) {
274
- const absolutePath = path.resolve(basePath, entry.path);
275
-
276
- // entries may be directories or files so filter out directories
277
- if (entry.isDirectory) {
278
- return false;
279
- }
280
-
281
- const configs = await configLoader.loadConfigArrayForFile(absolutePath);
282
- const config = configs.getConfig(absolutePath);
283
-
284
- /*
285
- * Optimization: We need to track when patterns are left unmatched
286
- * and so we use `unmatchedPatterns` to do that. There is a bit of
287
- * complexity here because the same file can be matched by more than
288
- * one pattern. So, when we start, we actually need to test every
289
- * pattern against every file. Once we know there are no remaining
290
- * unmatched patterns, then we can switch to just looking for the
291
- * first matching pattern for improved speed.
292
- */
293
- const matchesPattern = unmatchedPatterns.size > 0
294
- ? matchers.reduce((previousValue, matcher) => {
295
- const pathMatches = matcher.match(entry.path);
296
-
297
- /*
298
- * We updated the unmatched patterns set only if the path
299
- * matches and the file has a config. If the file has no
300
- * config, that means there wasn't a match for the
301
- * pattern so it should not be removed.
302
- *
303
- * Performance note: `getConfig()` aggressively caches
304
- * results so there is no performance penalty for calling
305
- * it multiple times with the same argument.
306
- */
307
- if (pathMatches && config) {
308
- unmatchedPatterns.delete(matcher.pattern);
309
- }
310
-
311
- return pathMatches || previousValue;
312
- }, false)
313
- : matchers.some(matcher => matcher.match(entry.path));
314
-
315
- return matchesPattern && config !== void 0;
316
- }
317
- }
318
- );
319
-
320
- const filePaths = [];
321
-
322
- if (await hfs.isDirectory(basePath)) {
323
- for await (const entry of walk) {
324
- filePaths.push(path.resolve(basePath, entry.path));
325
- }
326
- }
327
-
328
- // now check to see if we have any unmatched patterns
329
- if (errorOnUnmatchedPattern && unmatchedPatterns.size > 0) {
330
- throw new UnmatchedSearchPatternsError({
331
- basePath,
332
- unmatchedPatterns: [...unmatchedPatterns].map(
333
- pattern => relativeToPatterns.get(pattern)
334
- ),
335
- patterns,
336
- rawPatterns
337
- });
338
- }
339
-
340
- return filePaths;
231
+ if (patterns.length === 0) {
232
+ return [];
233
+ }
234
+
235
+ /*
236
+ * In this section we are converting the patterns into Minimatch
237
+ * instances for performance reasons. Because we are doing the same
238
+ * matches repeatedly, it's best to compile those patterns once and
239
+ * reuse them multiple times.
240
+ *
241
+ * To do that, we convert any patterns with an absolute path into a
242
+ * relative path and normalize it to Posix-style slashes. We also keep
243
+ * track of the relative patterns to map them back to the original
244
+ * patterns, which we need in order to throw an error if there are any
245
+ * unmatched patterns.
246
+ */
247
+ const relativeToPatterns = new Map();
248
+ const matchers = patterns.map((pattern, i) => {
249
+ const patternToUse = normalizeToPosix(path.relative(basePath, pattern));
250
+
251
+ relativeToPatterns.set(patternToUse, patterns[i]);
252
+
253
+ return new Minimatch(patternToUse, MINIMATCH_OPTIONS);
254
+ });
255
+
256
+ /*
257
+ * We track unmatched patterns because we may want to throw an error when
258
+ * they occur. To start, this set is initialized with all of the patterns.
259
+ * Every time a match occurs, the pattern is removed from the set, making
260
+ * it easy to tell if we have any unmatched patterns left at the end of
261
+ * search.
262
+ */
263
+ const unmatchedPatterns = new Set([...relativeToPatterns.keys()]);
264
+ const { hfs } = await import("@humanfs/node");
265
+
266
+ const walk = hfs.walk(basePath, {
267
+ async directoryFilter(entry) {
268
+ if (!matchers.some(matcher => matcher.match(entry.path, true))) {
269
+ return false;
270
+ }
271
+
272
+ const absolutePath = path.resolve(basePath, entry.path);
273
+ const configs =
274
+ await configLoader.loadConfigArrayForDirectory(absolutePath);
275
+
276
+ return !configs.isDirectoryIgnored(absolutePath);
277
+ },
278
+ async entryFilter(entry) {
279
+ const absolutePath = path.resolve(basePath, entry.path);
280
+
281
+ // entries may be directories or files so filter out directories
282
+ if (entry.isDirectory) {
283
+ return false;
284
+ }
285
+
286
+ const configs =
287
+ await configLoader.loadConfigArrayForFile(absolutePath);
288
+ const config = configs.getConfig(absolutePath);
289
+
290
+ /*
291
+ * Optimization: We need to track when patterns are left unmatched
292
+ * and so we use `unmatchedPatterns` to do that. There is a bit of
293
+ * complexity here because the same file can be matched by more than
294
+ * one pattern. So, when we start, we actually need to test every
295
+ * pattern against every file. Once we know there are no remaining
296
+ * unmatched patterns, then we can switch to just looking for the
297
+ * first matching pattern for improved speed.
298
+ */
299
+ const matchesPattern =
300
+ unmatchedPatterns.size > 0
301
+ ? matchers.reduce((previousValue, matcher) => {
302
+ const pathMatches = matcher.match(entry.path);
303
+
304
+ /*
305
+ * We updated the unmatched patterns set only if the path
306
+ * matches and the file has a config. If the file has no
307
+ * config, that means there wasn't a match for the
308
+ * pattern so it should not be removed.
309
+ *
310
+ * Performance note: `getConfig()` aggressively caches
311
+ * results so there is no performance penalty for calling
312
+ * it multiple times with the same argument.
313
+ */
314
+ if (pathMatches && config) {
315
+ unmatchedPatterns.delete(matcher.pattern);
316
+ }
317
+
318
+ return pathMatches || previousValue;
319
+ }, false)
320
+ : matchers.some(matcher => matcher.match(entry.path));
321
+
322
+ return matchesPattern && config !== void 0;
323
+ },
324
+ });
325
+
326
+ const filePaths = [];
327
+
328
+ if (await hfs.isDirectory(basePath)) {
329
+ for await (const entry of walk) {
330
+ filePaths.push(path.resolve(basePath, entry.path));
331
+ }
332
+ }
333
+
334
+ // now check to see if we have any unmatched patterns
335
+ if (errorOnUnmatchedPattern && unmatchedPatterns.size > 0) {
336
+ throw new UnmatchedSearchPatternsError({
337
+ basePath,
338
+ unmatchedPatterns: [...unmatchedPatterns].map(pattern =>
339
+ relativeToPatterns.get(pattern),
340
+ ),
341
+ patterns,
342
+ rawPatterns,
343
+ });
344
+ }
345
+
346
+ return filePaths;
341
347
  }
342
348
 
343
349
  /**
@@ -351,33 +357,32 @@ async function globSearch({
351
357
  * as the user inputted them. Used for errors.
352
358
  * @param {Array<string>} options.unmatchedPatterns A non-empty array of absolute path glob patterns
353
359
  * that were unmatched in the original search.
354
- * @returns {void} Always throws an error.
360
+ * @returns {Promise<never>} Always throws an error.
355
361
  * @throws {NoFilesFoundError} If the first unmatched pattern
356
362
  * doesn't match any files even when there are no ignores.
357
363
  * @throws {AllFilesIgnoredError} If the first unmatched pattern
358
364
  * matches some files when there are no ignores.
359
365
  */
360
366
  async function throwErrorForUnmatchedPatterns({
361
- basePath,
362
- patterns,
363
- rawPatterns,
364
- unmatchedPatterns
367
+ basePath,
368
+ patterns,
369
+ rawPatterns,
370
+ unmatchedPatterns,
365
371
  }) {
372
+ const pattern = unmatchedPatterns[0];
373
+ const rawPattern = rawPatterns[patterns.indexOf(pattern)];
366
374
 
367
- const pattern = unmatchedPatterns[0];
368
- const rawPattern = rawPatterns[patterns.indexOf(pattern)];
369
-
370
- const patternHasMatch = await globMatch({
371
- basePath,
372
- pattern
373
- });
375
+ const patternHasMatch = await globMatch({
376
+ basePath,
377
+ pattern,
378
+ });
374
379
 
375
- if (patternHasMatch) {
376
- throw new AllFilesIgnoredError(rawPattern);
377
- }
380
+ if (patternHasMatch) {
381
+ throw new AllFilesIgnoredError(rawPattern);
382
+ }
378
383
 
379
- // if we get here there are truly no matches
380
- throw new NoFilesFoundError(rawPattern, true);
384
+ // if we get here there are truly no matches
385
+ throw new NoFilesFoundError(rawPattern, true);
381
386
  }
382
387
 
383
388
  /**
@@ -392,69 +397,71 @@ async function throwErrorForUnmatchedPatterns({
392
397
  * @returns {Promise<Array<string>>} An array of matching file paths
393
398
  * or an empty array if there are no matches.
394
399
  */
395
- async function globMultiSearch({ searches, configLoader, errorOnUnmatchedPattern }) {
396
-
397
- /*
398
- * For convenience, we normalized the search map into an array of objects.
399
- * Next, we filter out all searches that have no patterns. This happens
400
- * primarily for the cwd, which is prepopulated in the searches map as an
401
- * optimization. However, if it has no patterns, it means all patterns
402
- * occur outside of the cwd and we can safely filter out that search.
403
- */
404
- const normalizedSearches = [...searches].map(
405
- ([basePath, { patterns, rawPatterns }]) => ({ basePath, patterns, rawPatterns })
406
- ).filter(({ patterns }) => patterns.length > 0);
407
-
408
- const results = await Promise.allSettled(
409
- normalizedSearches.map(
410
- ({ basePath, patterns, rawPatterns }) => globSearch({
411
- basePath,
412
- patterns,
413
- rawPatterns,
414
- configLoader,
415
- errorOnUnmatchedPattern
416
- })
417
- )
418
- );
419
-
420
- /*
421
- * The first loop handles errors from the glob searches. Since we can't
422
- * use `await` inside `flatMap`, we process errors separately in this loop.
423
- * This results in two iterations over `results`, but since the length is
424
- * less than or equal to the number of globs and directories passed on the
425
- * command line, the performance impact should be minimal.
426
- */
427
- for (let i = 0; i < results.length; i++) {
428
-
429
- const result = results[i];
430
- const currentSearch = normalizedSearches[i];
431
-
432
- if (result.status === "fulfilled") {
433
- continue;
434
- }
435
-
436
- // if we make it here then there was an error
437
- const error = result.reason;
438
-
439
- // unexpected errors should be re-thrown
440
- if (!error.basePath) {
441
- throw error;
442
- }
443
-
444
- if (errorOnUnmatchedPattern) {
445
-
446
- await throwErrorForUnmatchedPatterns({
447
- ...currentSearch,
448
- unmatchedPatterns: error.unmatchedPatterns
449
- });
450
-
451
- }
452
-
453
- }
454
-
455
- // second loop for `fulfulled` results
456
- return results.flatMap(result => result.value);
457
-
400
+ async function globMultiSearch({
401
+ searches,
402
+ configLoader,
403
+ errorOnUnmatchedPattern,
404
+ }) {
405
+ /*
406
+ * For convenience, we normalized the search map into an array of objects.
407
+ * Next, we filter out all searches that have no patterns. This happens
408
+ * primarily for the cwd, which is prepopulated in the searches map as an
409
+ * optimization. However, if it has no patterns, it means all patterns
410
+ * occur outside of the cwd and we can safely filter out that search.
411
+ */
412
+ const normalizedSearches = [...searches]
413
+ .map(([basePath, { patterns, rawPatterns }]) => ({
414
+ basePath,
415
+ patterns,
416
+ rawPatterns,
417
+ }))
418
+ .filter(({ patterns }) => patterns.length > 0);
419
+
420
+ const results = await Promise.allSettled(
421
+ normalizedSearches.map(({ basePath, patterns, rawPatterns }) =>
422
+ globSearch({
423
+ basePath,
424
+ patterns,
425
+ rawPatterns,
426
+ configLoader,
427
+ errorOnUnmatchedPattern,
428
+ }),
429
+ ),
430
+ );
431
+
432
+ /*
433
+ * The first loop handles errors from the glob searches. Since we can't
434
+ * use `await` inside `flatMap`, we process errors separately in this loop.
435
+ * This results in two iterations over `results`, but since the length is
436
+ * less than or equal to the number of globs and directories passed on the
437
+ * command line, the performance impact should be minimal.
438
+ */
439
+ for (let i = 0; i < results.length; i++) {
440
+ const result = results[i];
441
+ const currentSearch = normalizedSearches[i];
442
+
443
+ if (result.status === "fulfilled") {
444
+ continue;
445
+ }
446
+
447
+ // if we make it here then there was an error
448
+ const error = result.reason;
449
+
450
+ // unexpected errors should be re-thrown
451
+ if (!error.basePath) {
452
+ throw error;
453
+ }
454
+
455
+ if (errorOnUnmatchedPattern) {
456
+ await throwErrorForUnmatchedPatterns({
457
+ ...currentSearch,
458
+ unmatchedPatterns: error.unmatchedPatterns,
459
+ });
460
+ }
461
+ }
462
+
463
+ // second loop for `fulfilled` results
464
+ return results.flatMap(result => result.value);
458
465
  }
459
466
 
460
467
  /**
@@ -472,130 +479,122 @@ async function globMultiSearch({ searches, configLoader, errorOnUnmatchedPattern
472
479
  * @throws {NoFilesFoundError} If no files matched the given patterns.
473
480
  */
474
481
  async function findFiles({
475
- patterns,
476
- globInputPaths,
477
- cwd,
478
- configLoader,
479
- errorOnUnmatchedPattern
482
+ patterns,
483
+ globInputPaths,
484
+ cwd,
485
+ configLoader,
486
+ errorOnUnmatchedPattern,
480
487
  }) {
481
-
482
- const results = [];
483
- const missingPatterns = [];
484
- let globbyPatterns = [];
485
- let rawPatterns = [];
486
- const searches = new Map([[cwd, { patterns: globbyPatterns, rawPatterns: [] }]]);
487
-
488
- /*
489
- * This part is a bit involved because we need to account for
490
- * the different ways that the patterns can match directories.
491
- * For each different way, we need to decide if we should look
492
- * for a config file or just use the default config. (Directories
493
- * without a config file always use the default config.)
494
- *
495
- * Here are the cases:
496
- *
497
- * 1. A directory is passed directly (e.g., "subdir"). In this case, we
498
- * can assume that the user intends to lint this directory and we should
499
- * not look for a config file in the parent directory, because the only
500
- * reason to do that would be to ignore this directory (which we already
501
- * know we don't want to do). Instead, we use the default config until we
502
- * get to the directory that was passed, at which point we start looking
503
- * for config files again.
504
- *
505
- * 2. A dot (".") or star ("*"). In this case, we want to read
506
- * the config file in the current directory because the user is
507
- * explicitly asking to lint the current directory. Note that "."
508
- * will traverse into subdirectories while "*" will not.
509
- *
510
- * 3. A directory is passed in the form of "subdir/subsubdir".
511
- * In this case, we don't want to look for a config file in the
512
- * parent directory ("subdir"). We can skip looking for a config
513
- * file until `entry.depth` is greater than 1 because there's no
514
- * way that the pattern can match `entry.path` yet.
515
- *
516
- * 4. A directory glob pattern is passed (e.g., "subd*"). We want
517
- * this case to act like case 2 because it's unclear whether or not
518
- * any particular directory is meant to be traversed.
519
- *
520
- * 5. A recursive glob pattern is passed (e.g., "**"). We want this
521
- * case to act like case 2.
522
- */
523
-
524
- // check to see if we have explicit files and directories
525
- const filePaths = patterns.map(filePath => path.resolve(cwd, filePath));
526
- const stats = await Promise.all(
527
- filePaths.map(
528
- filePath => fsp.stat(filePath).catch(() => { })
529
- )
530
- );
531
-
532
- stats.forEach((stat, index) => {
533
-
534
- const filePath = filePaths[index];
535
- const pattern = normalizeToPosix(patterns[index]);
536
-
537
- if (stat) {
538
-
539
- // files are added directly to the list
540
- if (stat.isFile()) {
541
- results.push(filePath);
542
- }
543
-
544
- // directories need extensions attached
545
- if (stat.isDirectory()) {
546
-
547
- if (!searches.has(filePath)) {
548
- searches.set(filePath, { patterns: [], rawPatterns: [] });
549
- }
550
- ({ patterns: globbyPatterns, rawPatterns } = searches.get(filePath));
551
-
552
- globbyPatterns.push(`${normalizeToPosix(filePath)}/**`);
553
- rawPatterns.push(pattern);
554
- }
555
-
556
- return;
557
- }
558
-
559
- // save patterns for later use based on whether globs are enabled
560
- if (globInputPaths && isGlobPattern(pattern)) {
561
-
562
- /*
563
- * We are grouping patterns by their glob parent. This is done to
564
- * make it easier to determine when a config file should be loaded.
565
- */
566
-
567
- const basePath = path.resolve(cwd, globParent(pattern));
568
-
569
- if (!searches.has(basePath)) {
570
- searches.set(basePath, { patterns: [], rawPatterns: [] });
571
- }
572
- ({ patterns: globbyPatterns, rawPatterns } = searches.get(basePath));
573
-
574
- globbyPatterns.push(filePath);
575
- rawPatterns.push(pattern);
576
- } else {
577
- missingPatterns.push(pattern);
578
- }
579
- });
580
-
581
- // there were patterns that didn't match anything, tell the user
582
- if (errorOnUnmatchedPattern && missingPatterns.length) {
583
- throw new NoFilesFoundError(missingPatterns[0], globInputPaths);
584
- }
585
-
586
- // now we are safe to do the search
587
- const globbyResults = await globMultiSearch({
588
- searches,
589
- configLoader,
590
- errorOnUnmatchedPattern
591
- });
592
-
593
- return [
594
- ...new Set([
595
- ...results,
596
- ...globbyResults
597
- ])
598
- ];
488
+ const results = [];
489
+ const missingPatterns = [];
490
+ let globbyPatterns = [];
491
+ let rawPatterns = [];
492
+ const searches = new Map([
493
+ [cwd, { patterns: globbyPatterns, rawPatterns: [] }],
494
+ ]);
495
+
496
+ /*
497
+ * This part is a bit involved because we need to account for
498
+ * the different ways that the patterns can match directories.
499
+ * For each different way, we need to decide if we should look
500
+ * for a config file or just use the default config. (Directories
501
+ * without a config file always use the default config.)
502
+ *
503
+ * Here are the cases:
504
+ *
505
+ * 1. A directory is passed directly (e.g., "subdir"). In this case, we
506
+ * can assume that the user intends to lint this directory and we should
507
+ * not look for a config file in the parent directory, because the only
508
+ * reason to do that would be to ignore this directory (which we already
509
+ * know we don't want to do). Instead, we use the default config until we
510
+ * get to the directory that was passed, at which point we start looking
511
+ * for config files again.
512
+ *
513
+ * 2. A dot (".") or star ("*"). In this case, we want to read
514
+ * the config file in the current directory because the user is
515
+ * explicitly asking to lint the current directory. Note that "."
516
+ * will traverse into subdirectories while "*" will not.
517
+ *
518
+ * 3. A directory is passed in the form of "subdir/subsubdir".
519
+ * In this case, we don't want to look for a config file in the
520
+ * parent directory ("subdir"). We can skip looking for a config
521
+ * file until `entry.depth` is greater than 1 because there's no
522
+ * way that the pattern can match `entry.path` yet.
523
+ *
524
+ * 4. A directory glob pattern is passed (e.g., "subd*"). We want
525
+ * this case to act like case 2 because it's unclear whether or not
526
+ * any particular directory is meant to be traversed.
527
+ *
528
+ * 5. A recursive glob pattern is passed (e.g., "**"). We want this
529
+ * case to act like case 2.
530
+ */
531
+
532
+ // check to see if we have explicit files and directories
533
+ const filePaths = patterns.map(filePath => path.resolve(cwd, filePath));
534
+ const stats = await Promise.all(
535
+ filePaths.map(filePath => fsp.stat(filePath).catch(() => {})),
536
+ );
537
+
538
+ stats.forEach((stat, index) => {
539
+ const filePath = filePaths[index];
540
+ const pattern = normalizeToPosix(patterns[index]);
541
+
542
+ if (stat) {
543
+ // files are added directly to the list
544
+ if (stat.isFile()) {
545
+ results.push(filePath);
546
+ }
547
+
548
+ // directories need extensions attached
549
+ if (stat.isDirectory()) {
550
+ if (!searches.has(filePath)) {
551
+ searches.set(filePath, { patterns: [], rawPatterns: [] });
552
+ }
553
+ ({ patterns: globbyPatterns, rawPatterns } =
554
+ searches.get(filePath));
555
+
556
+ globbyPatterns.push(`${normalizeToPosix(filePath)}/**`);
557
+ rawPatterns.push(pattern);
558
+ }
559
+
560
+ return;
561
+ }
562
+
563
+ // save patterns for later use based on whether globs are enabled
564
+ if (globInputPaths && isGlobPattern(pattern)) {
565
+ /*
566
+ * We are grouping patterns by their glob parent. This is done to
567
+ * make it easier to determine when a config file should be loaded.
568
+ */
569
+
570
+ const basePath = path.resolve(cwd, globParent(pattern));
571
+
572
+ if (!searches.has(basePath)) {
573
+ searches.set(basePath, { patterns: [], rawPatterns: [] });
574
+ }
575
+ ({ patterns: globbyPatterns, rawPatterns } =
576
+ searches.get(basePath));
577
+
578
+ globbyPatterns.push(filePath);
579
+ rawPatterns.push(pattern);
580
+ } else {
581
+ missingPatterns.push(pattern);
582
+ }
583
+ });
584
+
585
+ // there were patterns that didn't match anything, tell the user
586
+ if (errorOnUnmatchedPattern && missingPatterns.length) {
587
+ throw new NoFilesFoundError(missingPatterns[0], globInputPaths);
588
+ }
589
+
590
+ // now we are safe to do the search
591
+ const globbyResults = await globMultiSearch({
592
+ searches,
593
+ configLoader,
594
+ errorOnUnmatchedPattern,
595
+ });
596
+
597
+ return [...new Set([...results, ...globbyResults])];
599
598
  }
600
599
 
601
600
  //-----------------------------------------------------------------------------
@@ -609,7 +608,7 @@ async function findFiles({
609
608
  * @private
610
609
  */
611
610
  function isErrorMessage(message) {
612
- return message.severity === 2;
611
+ return message.severity === 2;
613
612
  }
614
613
 
615
614
  /**
@@ -621,60 +620,108 @@ function isErrorMessage(message) {
621
620
  * @private
622
621
  */
623
622
  function createIgnoreResult(filePath, baseDir, configStatus) {
624
- let message;
625
-
626
- switch (configStatus) {
627
- case "external":
628
- message = "File ignored because outside of base path.";
629
- break;
630
- case "unconfigured":
631
- message = "File ignored because no matching configuration was supplied.";
632
- break;
633
- default:
634
- {
635
- const isInNodeModules = baseDir && path.dirname(path.relative(baseDir, filePath)).split(path.sep).includes("node_modules");
636
-
637
- if (isInNodeModules) {
638
- message = "File ignored by default because it is located under the node_modules directory. Use ignore pattern \"!**/node_modules/\" to disable file ignore settings or use \"--no-warn-ignored\" to suppress this warning.";
639
- } else {
640
- message = "File ignored because of a matching ignore pattern. Use \"--no-ignore\" to disable file ignore settings or use \"--no-warn-ignored\" to suppress this warning.";
641
- }
642
- }
643
- break;
644
- }
645
-
646
- return {
647
- filePath,
648
- messages: [
649
- {
650
- ruleId: null,
651
- fatal: false,
652
- severity: 1,
653
- message,
654
- nodeType: null
655
- }
656
- ],
657
- suppressedMessages: [],
658
- errorCount: 0,
659
- warningCount: 1,
660
- fatalErrorCount: 0,
661
- fixableErrorCount: 0,
662
- fixableWarningCount: 0
663
- };
623
+ let message;
624
+
625
+ switch (configStatus) {
626
+ case "external":
627
+ message = "File ignored because outside of base path.";
628
+ break;
629
+ case "unconfigured":
630
+ message =
631
+ "File ignored because no matching configuration was supplied.";
632
+ break;
633
+ default:
634
+ {
635
+ const isInNodeModules =
636
+ baseDir &&
637
+ path
638
+ .dirname(path.relative(baseDir, filePath))
639
+ .split(path.sep)
640
+ .includes("node_modules");
641
+
642
+ if (isInNodeModules) {
643
+ message =
644
+ 'File ignored by default because it is located under the node_modules directory. Use ignore pattern "!**/node_modules/" to disable file ignore settings or use "--no-warn-ignored" to suppress this warning.';
645
+ } else {
646
+ message =
647
+ 'File ignored because of a matching ignore pattern. Use "--no-ignore" to disable file ignore settings or use "--no-warn-ignored" to suppress this warning.';
648
+ }
649
+ }
650
+ break;
651
+ }
652
+
653
+ return {
654
+ filePath,
655
+ messages: [
656
+ {
657
+ ruleId: null,
658
+ fatal: false,
659
+ severity: 1,
660
+ message,
661
+ nodeType: null,
662
+ },
663
+ ],
664
+ suppressedMessages: [],
665
+ errorCount: 0,
666
+ warningCount: 1,
667
+ fatalErrorCount: 0,
668
+ fixableErrorCount: 0,
669
+ fixableWarningCount: 0,
670
+ };
671
+ }
672
+
673
+ /**
674
+ * It will calculate the error and warning count for collection of messages per file
675
+ * @param {LintMessage[]} messages Collection of messages
676
+ * @returns {Object} Contains the stats
677
+ * @private
678
+ */
679
+ function calculateStatsPerFile(messages) {
680
+ const stat = {
681
+ errorCount: 0,
682
+ fatalErrorCount: 0,
683
+ warningCount: 0,
684
+ fixableErrorCount: 0,
685
+ fixableWarningCount: 0,
686
+ };
687
+
688
+ for (let i = 0; i < messages.length; i++) {
689
+ const message = messages[i];
690
+
691
+ if (message.fatal || message.severity === 2) {
692
+ stat.errorCount++;
693
+ if (message.fatal) {
694
+ stat.fatalErrorCount++;
695
+ }
696
+ if (message.fix) {
697
+ stat.fixableErrorCount++;
698
+ }
699
+ } else {
700
+ stat.warningCount++;
701
+ if (message.fix) {
702
+ stat.fixableWarningCount++;
703
+ }
704
+ }
705
+ }
706
+ return stat;
664
707
  }
665
708
 
666
709
  //-----------------------------------------------------------------------------
667
710
  // Options-related Helpers
668
711
  //-----------------------------------------------------------------------------
669
712
 
670
-
671
713
  /**
672
714
  * Check if a given value is a valid fix type or not.
673
715
  * @param {any} x The value to check.
674
716
  * @returns {boolean} `true` if `x` is valid fix type.
675
717
  */
676
718
  function isFixType(x) {
677
- return x === "directive" || x === "problem" || x === "suggestion" || x === "layout";
719
+ return (
720
+ x === "directive" ||
721
+ x === "problem" ||
722
+ x === "suggestion" ||
723
+ x === "layout"
724
+ );
678
725
  }
679
726
 
680
727
  /**
@@ -683,18 +730,18 @@ function isFixType(x) {
683
730
  * @returns {boolean} `true` if `x` is an array of fix types.
684
731
  */
685
732
  function isFixTypeArray(x) {
686
- return Array.isArray(x) && x.every(isFixType);
733
+ return Array.isArray(x) && x.every(isFixType);
687
734
  }
688
735
 
689
736
  /**
690
737
  * The error for invalid options.
691
738
  */
692
739
  class ESLintInvalidOptionsError extends Error {
693
- constructor(messages) {
694
- super(`Invalid Options:\n- ${messages.join("\n- ")}`);
695
- this.code = "ESLINT_INVALID_OPTIONS";
696
- Error.captureStackTrace(this, ESLintInvalidOptionsError);
697
- }
740
+ constructor(messages) {
741
+ super(`Invalid Options:\n- ${messages.join("\n- ")}`);
742
+ this.code = "ESLINT_INVALID_OPTIONS";
743
+ Error.captureStackTrace(this, ESLintInvalidOptionsError);
744
+ }
698
745
  }
699
746
 
700
747
  /**
@@ -704,171 +751,200 @@ class ESLintInvalidOptionsError extends Error {
704
751
  * @returns {ESLintOptions} The normalized options.
705
752
  */
706
753
  function processOptions({
707
- allowInlineConfig = true, // ← we cannot use `overrideConfig.noInlineConfig` instead because `allowInlineConfig` has side-effect that suppress warnings that show inline configs are ignored.
708
- baseConfig = null,
709
- cache = false,
710
- cacheLocation = ".eslintcache",
711
- cacheStrategy = "metadata",
712
- cwd = process.cwd(),
713
- errorOnUnmatchedPattern = true,
714
- fix = false,
715
- fixTypes = null, // ← should be null by default because if it's an array then it suppresses rules that don't have the `meta.type` property.
716
- flags = [],
717
- globInputPaths = true,
718
- ignore = true,
719
- ignorePatterns = null,
720
- overrideConfig = null,
721
- overrideConfigFile = null,
722
- plugins = {},
723
- stats = false,
724
- warnIgnored = true,
725
- passOnNoPatterns = false,
726
- ruleFilter = () => true,
727
- ...unknownOptions
754
+ allowInlineConfig = true, // ← we cannot use `overrideConfig.noInlineConfig` instead because `allowInlineConfig` has side-effect that suppress warnings that show inline configs are ignored.
755
+ baseConfig = null,
756
+ cache = false,
757
+ cacheLocation = ".eslintcache",
758
+ cacheStrategy = "metadata",
759
+ cwd = process.cwd(),
760
+ errorOnUnmatchedPattern = true,
761
+ fix = false,
762
+ fixTypes = null, // ← should be null by default because if it's an array then it suppresses rules that don't have the `meta.type` property.
763
+ flags = [],
764
+ globInputPaths = true,
765
+ ignore = true,
766
+ ignorePatterns = null,
767
+ overrideConfig = null,
768
+ overrideConfigFile = null,
769
+ plugins = {},
770
+ stats = false,
771
+ warnIgnored = true,
772
+ passOnNoPatterns = false,
773
+ ruleFilter = () => true,
774
+ ...unknownOptions
728
775
  }) {
729
- const errors = [];
730
- const unknownOptionKeys = Object.keys(unknownOptions);
731
-
732
- if (unknownOptionKeys.length >= 1) {
733
- errors.push(`Unknown options: ${unknownOptionKeys.join(", ")}`);
734
- if (unknownOptionKeys.includes("cacheFile")) {
735
- errors.push("'cacheFile' has been removed. Please use the 'cacheLocation' option instead.");
736
- }
737
- if (unknownOptionKeys.includes("configFile")) {
738
- errors.push("'configFile' has been removed. Please use the 'overrideConfigFile' option instead.");
739
- }
740
- if (unknownOptionKeys.includes("envs")) {
741
- errors.push("'envs' has been removed.");
742
- }
743
- if (unknownOptionKeys.includes("extensions")) {
744
- errors.push("'extensions' has been removed.");
745
- }
746
- if (unknownOptionKeys.includes("resolvePluginsRelativeTo")) {
747
- errors.push("'resolvePluginsRelativeTo' has been removed.");
748
- }
749
- if (unknownOptionKeys.includes("globals")) {
750
- errors.push("'globals' has been removed. Please use the 'overrideConfig.languageOptions.globals' option instead.");
751
- }
752
- if (unknownOptionKeys.includes("ignorePath")) {
753
- errors.push("'ignorePath' has been removed.");
754
- }
755
- if (unknownOptionKeys.includes("ignorePattern")) {
756
- errors.push("'ignorePattern' has been removed. Please use the 'overrideConfig.ignorePatterns' option instead.");
757
- }
758
- if (unknownOptionKeys.includes("parser")) {
759
- errors.push("'parser' has been removed. Please use the 'overrideConfig.languageOptions.parser' option instead.");
760
- }
761
- if (unknownOptionKeys.includes("parserOptions")) {
762
- errors.push("'parserOptions' has been removed. Please use the 'overrideConfig.languageOptions.parserOptions' option instead.");
763
- }
764
- if (unknownOptionKeys.includes("rules")) {
765
- errors.push("'rules' has been removed. Please use the 'overrideConfig.rules' option instead.");
766
- }
767
- if (unknownOptionKeys.includes("rulePaths")) {
768
- errors.push("'rulePaths' has been removed. Please define your rules using plugins.");
769
- }
770
- if (unknownOptionKeys.includes("reportUnusedDisableDirectives")) {
771
- errors.push("'reportUnusedDisableDirectives' has been removed. Please use the 'overrideConfig.linterOptions.reportUnusedDisableDirectives' option instead.");
772
- }
773
- }
774
- if (typeof allowInlineConfig !== "boolean") {
775
- errors.push("'allowInlineConfig' must be a boolean.");
776
- }
777
- if (typeof baseConfig !== "object") {
778
- errors.push("'baseConfig' must be an object or null.");
779
- }
780
- if (typeof cache !== "boolean") {
781
- errors.push("'cache' must be a boolean.");
782
- }
783
- if (!isNonEmptyString(cacheLocation)) {
784
- errors.push("'cacheLocation' must be a non-empty string.");
785
- }
786
- if (
787
- cacheStrategy !== "metadata" &&
788
- cacheStrategy !== "content"
789
- ) {
790
- errors.push("'cacheStrategy' must be any of \"metadata\", \"content\".");
791
- }
792
- if (!isNonEmptyString(cwd) || !path.isAbsolute(cwd)) {
793
- errors.push("'cwd' must be an absolute path.");
794
- }
795
- if (typeof errorOnUnmatchedPattern !== "boolean") {
796
- errors.push("'errorOnUnmatchedPattern' must be a boolean.");
797
- }
798
- if (typeof fix !== "boolean" && typeof fix !== "function") {
799
- errors.push("'fix' must be a boolean or a function.");
800
- }
801
- if (fixTypes !== null && !isFixTypeArray(fixTypes)) {
802
- errors.push("'fixTypes' must be an array of any of \"directive\", \"problem\", \"suggestion\", and \"layout\".");
803
- }
804
- if (!isEmptyArrayOrArrayOfNonEmptyString(flags)) {
805
- errors.push("'flags' must be an array of non-empty strings.");
806
- }
807
- if (typeof globInputPaths !== "boolean") {
808
- errors.push("'globInputPaths' must be a boolean.");
809
- }
810
- if (typeof ignore !== "boolean") {
811
- errors.push("'ignore' must be a boolean.");
812
- }
813
- if (!isEmptyArrayOrArrayOfNonEmptyString(ignorePatterns) && ignorePatterns !== null) {
814
- errors.push("'ignorePatterns' must be an array of non-empty strings or null.");
815
- }
816
- if (typeof overrideConfig !== "object") {
817
- errors.push("'overrideConfig' must be an object or null.");
818
- }
819
- if (!isNonEmptyString(overrideConfigFile) && overrideConfigFile !== null && overrideConfigFile !== true) {
820
- errors.push("'overrideConfigFile' must be a non-empty string, null, or true.");
821
- }
822
- if (typeof passOnNoPatterns !== "boolean") {
823
- errors.push("'passOnNoPatterns' must be a boolean.");
824
- }
825
- if (typeof plugins !== "object") {
826
- errors.push("'plugins' must be an object or null.");
827
- } else if (plugins !== null && Object.keys(plugins).includes("")) {
828
- errors.push("'plugins' must not include an empty string.");
829
- }
830
- if (Array.isArray(plugins)) {
831
- errors.push("'plugins' doesn't add plugins to configuration to load. Please use the 'overrideConfig.plugins' option instead.");
832
- }
833
- if (typeof stats !== "boolean") {
834
- errors.push("'stats' must be a boolean.");
835
- }
836
- if (typeof warnIgnored !== "boolean") {
837
- errors.push("'warnIgnored' must be a boolean.");
838
- }
839
- if (typeof ruleFilter !== "function") {
840
- errors.push("'ruleFilter' must be a function.");
841
- }
842
- if (errors.length > 0) {
843
- throw new ESLintInvalidOptionsError(errors);
844
- }
845
-
846
- return {
847
- allowInlineConfig,
848
- baseConfig,
849
- cache,
850
- cacheLocation,
851
- cacheStrategy,
852
-
853
- // when overrideConfigFile is true that means don't do config file lookup
854
- configFile: overrideConfigFile === true ? false : overrideConfigFile,
855
- overrideConfig,
856
- cwd: path.normalize(cwd),
857
- errorOnUnmatchedPattern,
858
- fix,
859
- fixTypes,
860
- flags: [...flags],
861
- globInputPaths,
862
- ignore,
863
- ignorePatterns,
864
- stats,
865
- passOnNoPatterns,
866
- warnIgnored,
867
- ruleFilter
868
- };
776
+ const errors = [];
777
+ const unknownOptionKeys = Object.keys(unknownOptions);
778
+
779
+ if (unknownOptionKeys.length >= 1) {
780
+ errors.push(`Unknown options: ${unknownOptionKeys.join(", ")}`);
781
+ if (unknownOptionKeys.includes("cacheFile")) {
782
+ errors.push(
783
+ "'cacheFile' has been removed. Please use the 'cacheLocation' option instead.",
784
+ );
785
+ }
786
+ if (unknownOptionKeys.includes("configFile")) {
787
+ errors.push(
788
+ "'configFile' has been removed. Please use the 'overrideConfigFile' option instead.",
789
+ );
790
+ }
791
+ if (unknownOptionKeys.includes("envs")) {
792
+ errors.push("'envs' has been removed.");
793
+ }
794
+ if (unknownOptionKeys.includes("extensions")) {
795
+ errors.push("'extensions' has been removed.");
796
+ }
797
+ if (unknownOptionKeys.includes("resolvePluginsRelativeTo")) {
798
+ errors.push("'resolvePluginsRelativeTo' has been removed.");
799
+ }
800
+ if (unknownOptionKeys.includes("globals")) {
801
+ errors.push(
802
+ "'globals' has been removed. Please use the 'overrideConfig.languageOptions.globals' option instead.",
803
+ );
804
+ }
805
+ if (unknownOptionKeys.includes("ignorePath")) {
806
+ errors.push("'ignorePath' has been removed.");
807
+ }
808
+ if (unknownOptionKeys.includes("ignorePattern")) {
809
+ errors.push(
810
+ "'ignorePattern' has been removed. Please use the 'overrideConfig.ignorePatterns' option instead.",
811
+ );
812
+ }
813
+ if (unknownOptionKeys.includes("parser")) {
814
+ errors.push(
815
+ "'parser' has been removed. Please use the 'overrideConfig.languageOptions.parser' option instead.",
816
+ );
817
+ }
818
+ if (unknownOptionKeys.includes("parserOptions")) {
819
+ errors.push(
820
+ "'parserOptions' has been removed. Please use the 'overrideConfig.languageOptions.parserOptions' option instead.",
821
+ );
822
+ }
823
+ if (unknownOptionKeys.includes("rules")) {
824
+ errors.push(
825
+ "'rules' has been removed. Please use the 'overrideConfig.rules' option instead.",
826
+ );
827
+ }
828
+ if (unknownOptionKeys.includes("rulePaths")) {
829
+ errors.push(
830
+ "'rulePaths' has been removed. Please define your rules using plugins.",
831
+ );
832
+ }
833
+ if (unknownOptionKeys.includes("reportUnusedDisableDirectives")) {
834
+ errors.push(
835
+ "'reportUnusedDisableDirectives' has been removed. Please use the 'overrideConfig.linterOptions.reportUnusedDisableDirectives' option instead.",
836
+ );
837
+ }
838
+ }
839
+ if (typeof allowInlineConfig !== "boolean") {
840
+ errors.push("'allowInlineConfig' must be a boolean.");
841
+ }
842
+ if (typeof baseConfig !== "object") {
843
+ errors.push("'baseConfig' must be an object or null.");
844
+ }
845
+ if (typeof cache !== "boolean") {
846
+ errors.push("'cache' must be a boolean.");
847
+ }
848
+ if (!isNonEmptyString(cacheLocation)) {
849
+ errors.push("'cacheLocation' must be a non-empty string.");
850
+ }
851
+ if (cacheStrategy !== "metadata" && cacheStrategy !== "content") {
852
+ errors.push('\'cacheStrategy\' must be any of "metadata", "content".');
853
+ }
854
+ if (!isNonEmptyString(cwd) || !path.isAbsolute(cwd)) {
855
+ errors.push("'cwd' must be an absolute path.");
856
+ }
857
+ if (typeof errorOnUnmatchedPattern !== "boolean") {
858
+ errors.push("'errorOnUnmatchedPattern' must be a boolean.");
859
+ }
860
+ if (typeof fix !== "boolean" && typeof fix !== "function") {
861
+ errors.push("'fix' must be a boolean or a function.");
862
+ }
863
+ if (fixTypes !== null && !isFixTypeArray(fixTypes)) {
864
+ errors.push(
865
+ '\'fixTypes\' must be an array of any of "directive", "problem", "suggestion", and "layout".',
866
+ );
867
+ }
868
+ if (!isEmptyArrayOrArrayOfNonEmptyString(flags)) {
869
+ errors.push("'flags' must be an array of non-empty strings.");
870
+ }
871
+ if (typeof globInputPaths !== "boolean") {
872
+ errors.push("'globInputPaths' must be a boolean.");
873
+ }
874
+ if (typeof ignore !== "boolean") {
875
+ errors.push("'ignore' must be a boolean.");
876
+ }
877
+ if (
878
+ !isEmptyArrayOrArrayOfNonEmptyString(ignorePatterns) &&
879
+ ignorePatterns !== null
880
+ ) {
881
+ errors.push(
882
+ "'ignorePatterns' must be an array of non-empty strings or null.",
883
+ );
884
+ }
885
+ if (typeof overrideConfig !== "object") {
886
+ errors.push("'overrideConfig' must be an object or null.");
887
+ }
888
+ if (
889
+ !isNonEmptyString(overrideConfigFile) &&
890
+ overrideConfigFile !== null &&
891
+ overrideConfigFile !== true
892
+ ) {
893
+ errors.push(
894
+ "'overrideConfigFile' must be a non-empty string, null, or true.",
895
+ );
896
+ }
897
+ if (typeof passOnNoPatterns !== "boolean") {
898
+ errors.push("'passOnNoPatterns' must be a boolean.");
899
+ }
900
+ if (typeof plugins !== "object") {
901
+ errors.push("'plugins' must be an object or null.");
902
+ } else if (plugins !== null && Object.keys(plugins).includes("")) {
903
+ errors.push("'plugins' must not include an empty string.");
904
+ }
905
+ if (Array.isArray(plugins)) {
906
+ errors.push(
907
+ "'plugins' doesn't add plugins to configuration to load. Please use the 'overrideConfig.plugins' option instead.",
908
+ );
909
+ }
910
+ if (typeof stats !== "boolean") {
911
+ errors.push("'stats' must be a boolean.");
912
+ }
913
+ if (typeof warnIgnored !== "boolean") {
914
+ errors.push("'warnIgnored' must be a boolean.");
915
+ }
916
+ if (typeof ruleFilter !== "function") {
917
+ errors.push("'ruleFilter' must be a function.");
918
+ }
919
+ if (errors.length > 0) {
920
+ throw new ESLintInvalidOptionsError(errors);
921
+ }
922
+
923
+ return {
924
+ allowInlineConfig,
925
+ baseConfig,
926
+ cache,
927
+ cacheLocation,
928
+ cacheStrategy,
929
+
930
+ // when overrideConfigFile is true that means don't do config file lookup
931
+ configFile: overrideConfigFile === true ? false : overrideConfigFile,
932
+ overrideConfig,
933
+ cwd: path.normalize(cwd),
934
+ errorOnUnmatchedPattern,
935
+ fix,
936
+ fixTypes,
937
+ flags: [...flags],
938
+ globInputPaths,
939
+ ignore,
940
+ ignorePatterns,
941
+ stats,
942
+ passOnNoPatterns,
943
+ warnIgnored,
944
+ ruleFilter,
945
+ };
869
946
  }
870
947
 
871
-
872
948
  //-----------------------------------------------------------------------------
873
949
  // Cache-related helpers
874
950
  //-----------------------------------------------------------------------------
@@ -881,85 +957,84 @@ function processOptions({
881
957
  * if cacheFile points to a file or looks like a file then in will just use that file
882
958
  * @param {string} cacheFile The name of file to be used to store the cache
883
959
  * @param {string} cwd Current working directory
960
+ * @param {Object} options The options
961
+ * @param {string} [options.prefix] The prefix to use for the cache file
884
962
  * @returns {string} the resolved path to the cache file
885
963
  */
886
- function getCacheFile(cacheFile, cwd) {
887
-
888
- /*
889
- * make sure the path separators are normalized for the environment/os
890
- * keeping the trailing path separator if present
891
- */
892
- const normalizedCacheFile = path.normalize(cacheFile);
893
-
894
- const resolvedCacheFile = path.resolve(cwd, normalizedCacheFile);
895
- const looksLikeADirectory = normalizedCacheFile.slice(-1) === path.sep;
896
-
897
- /**
898
- * return the name for the cache file in case the provided parameter is a directory
899
- * @returns {string} the resolved path to the cacheFile
900
- */
901
- function getCacheFileForDirectory() {
902
- return path.join(resolvedCacheFile, `.cache_${hash(cwd)}`);
903
- }
904
-
905
- let fileStats;
906
-
907
- try {
908
- fileStats = fs.lstatSync(resolvedCacheFile);
909
- } catch {
910
- fileStats = null;
911
- }
912
-
913
-
914
- /*
915
- * in case the file exists we need to verify if the provided path
916
- * is a directory or a file. If it is a directory we want to create a file
917
- * inside that directory
918
- */
919
- if (fileStats) {
920
-
921
- /*
922
- * is a directory or is a file, but the original file the user provided
923
- * looks like a directory but `path.resolve` removed the `last path.sep`
924
- * so we need to still treat this like a directory
925
- */
926
- if (fileStats.isDirectory() || looksLikeADirectory) {
927
- return getCacheFileForDirectory();
928
- }
929
-
930
- // is file so just use that file
931
- return resolvedCacheFile;
932
- }
933
-
934
- /*
935
- * here we known the file or directory doesn't exist,
936
- * so we will try to infer if its a directory if it looks like a directory
937
- * for the current operating system.
938
- */
939
-
940
- // if the last character passed is a path separator we assume is a directory
941
- if (looksLikeADirectory) {
942
- return getCacheFileForDirectory();
943
- }
944
-
945
- return resolvedCacheFile;
964
+ function getCacheFile(cacheFile, cwd, { prefix = ".cache_" } = {}) {
965
+ /*
966
+ * make sure the path separators are normalized for the environment/os
967
+ * keeping the trailing path separator if present
968
+ */
969
+ const normalizedCacheFile = path.normalize(cacheFile);
970
+
971
+ const resolvedCacheFile = path.resolve(cwd, normalizedCacheFile);
972
+ const looksLikeADirectory = normalizedCacheFile.slice(-1) === path.sep;
973
+
974
+ /**
975
+ * return the name for the cache file in case the provided parameter is a directory
976
+ * @returns {string} the resolved path to the cacheFile
977
+ */
978
+ function getCacheFileForDirectory() {
979
+ return path.join(resolvedCacheFile, `${prefix}${hash(cwd)}`);
980
+ }
981
+
982
+ let fileStats;
983
+
984
+ try {
985
+ fileStats = fs.lstatSync(resolvedCacheFile);
986
+ } catch {
987
+ fileStats = null;
988
+ }
989
+
990
+ /*
991
+ * in case the file exists we need to verify if the provided path
992
+ * is a directory or a file. If it is a directory we want to create a file
993
+ * inside that directory
994
+ */
995
+ if (fileStats) {
996
+ /*
997
+ * is a directory or is a file, but the original file the user provided
998
+ * looks like a directory but `path.resolve` removed the `last path.sep`
999
+ * so we need to still treat this like a directory
1000
+ */
1001
+ if (fileStats.isDirectory() || looksLikeADirectory) {
1002
+ return getCacheFileForDirectory();
1003
+ }
1004
+
1005
+ // is file so just use that file
1006
+ return resolvedCacheFile;
1007
+ }
1008
+
1009
+ /*
1010
+ * here we known the file or directory doesn't exist,
1011
+ * so we will try to infer if its a directory if it looks like a directory
1012
+ * for the current operating system.
1013
+ */
1014
+
1015
+ // if the last character passed is a path separator we assume is a directory
1016
+ if (looksLikeADirectory) {
1017
+ return getCacheFileForDirectory();
1018
+ }
1019
+
1020
+ return resolvedCacheFile;
946
1021
  }
947
1022
 
948
-
949
1023
  //-----------------------------------------------------------------------------
950
1024
  // Exports
951
1025
  //-----------------------------------------------------------------------------
952
1026
 
953
1027
  module.exports = {
954
- findFiles,
1028
+ findFiles,
955
1029
 
956
- isNonEmptyString,
957
- isArrayOfNonEmptyString,
1030
+ isNonEmptyString,
1031
+ isArrayOfNonEmptyString,
958
1032
 
959
- createIgnoreResult,
960
- isErrorMessage,
1033
+ createIgnoreResult,
1034
+ isErrorMessage,
1035
+ calculateStatsPerFile,
961
1036
 
962
- processOptions,
1037
+ processOptions,
963
1038
 
964
- getCacheFile
1039
+ getCacheFile,
965
1040
  };