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.
- package/README.md +48 -46
- package/bin/eslint.js +92 -90
- package/conf/default-cli-options.js +22 -22
- package/conf/ecma-version.js +1 -1
- package/conf/globals.js +97 -98
- package/conf/replacements.json +24 -20
- package/conf/rule-type-list.json +88 -92
- package/lib/api.js +12 -12
- package/lib/cli-engine/cli-engine.js +830 -810
- package/lib/cli-engine/file-enumerator.js +381 -387
- package/lib/cli-engine/formatters/formatters-meta.json +16 -16
- package/lib/cli-engine/formatters/html.js +107 -99
- package/lib/cli-engine/formatters/json-with-metadata.js +5 -5
- package/lib/cli-engine/formatters/json.js +2 -2
- package/lib/cli-engine/formatters/stylish.js +96 -75
- package/lib/cli-engine/hash.js +1 -1
- package/lib/cli-engine/index.js +1 -1
- package/lib/cli-engine/lint-result-cache.js +144 -145
- package/lib/cli-engine/load-rules.js +16 -16
- package/lib/cli.js +638 -457
- package/lib/config/config-loader.js +726 -622
- package/lib/config/config.js +247 -221
- package/lib/config/default-config.js +54 -45
- package/lib/config/flat-config-array.js +167 -172
- package/lib/config/flat-config-helpers.js +72 -72
- package/lib/config/flat-config-schema.js +375 -368
- package/lib/config/rule-validator.js +139 -144
- package/lib/config-api.js +2 -2
- package/lib/eslint/eslint-helpers.js +756 -681
- package/lib/eslint/eslint.js +934 -912
- package/lib/eslint/index.js +2 -2
- package/lib/eslint/legacy-eslint.js +577 -533
- package/lib/languages/js/index.js +263 -264
- package/lib/languages/js/source-code/index.js +1 -1
- package/lib/languages/js/source-code/source-code.js +1128 -1057
- package/lib/languages/js/source-code/token-store/backward-token-comment-cursor.js +39 -35
- package/lib/languages/js/source-code/token-store/backward-token-cursor.js +35 -36
- package/lib/languages/js/source-code/token-store/cursor.js +36 -36
- package/lib/languages/js/source-code/token-store/cursors.js +80 -52
- package/lib/languages/js/source-code/token-store/decorative-cursor.js +17 -18
- package/lib/languages/js/source-code/token-store/filter-cursor.js +19 -20
- package/lib/languages/js/source-code/token-store/forward-token-comment-cursor.js +40 -32
- package/lib/languages/js/source-code/token-store/forward-token-cursor.js +40 -41
- package/lib/languages/js/source-code/token-store/index.js +592 -498
- package/lib/languages/js/source-code/token-store/limit-cursor.js +17 -18
- package/lib/languages/js/source-code/token-store/padded-token-cursor.js +23 -16
- package/lib/languages/js/source-code/token-store/skip-cursor.js +19 -20
- package/lib/languages/js/source-code/token-store/utils.js +63 -60
- package/lib/languages/js/validate-language-options.js +104 -89
- package/lib/linter/apply-disable-directives.js +467 -383
- package/lib/linter/code-path-analysis/code-path-analyzer.js +650 -672
- package/lib/linter/code-path-analysis/code-path-segment.js +215 -216
- package/lib/linter/code-path-analysis/code-path-state.js +2118 -2096
- package/lib/linter/code-path-analysis/code-path.js +307 -319
- package/lib/linter/code-path-analysis/debug-helpers.js +183 -163
- package/lib/linter/code-path-analysis/fork-context.js +296 -271
- package/lib/linter/code-path-analysis/id-generator.js +22 -23
- package/lib/linter/file-context.js +119 -120
- package/lib/linter/index.js +3 -3
- package/lib/linter/interpolate.js +16 -16
- package/lib/linter/linter.js +2403 -2045
- package/lib/linter/node-event-generator.js +284 -225
- package/lib/linter/report-translator.js +256 -219
- package/lib/linter/rule-fixer.js +122 -124
- package/lib/linter/rules.js +36 -36
- package/lib/linter/safe-emitter.js +18 -18
- package/lib/linter/source-code-fixer.js +94 -92
- package/lib/linter/timing.js +104 -101
- package/lib/linter/vfile.js +70 -73
- package/lib/options.js +404 -361
- package/lib/rule-tester/index.js +1 -1
- package/lib/rule-tester/rule-tester.js +1308 -1046
- package/lib/rules/accessor-pairs.js +298 -263
- package/lib/rules/array-bracket-newline.js +250 -238
- package/lib/rules/array-bracket-spacing.js +263 -224
- package/lib/rules/array-callback-return.js +402 -356
- package/lib/rules/array-element-newline.js +358 -313
- package/lib/rules/arrow-body-style.js +400 -281
- package/lib/rules/arrow-parens.js +206 -173
- package/lib/rules/arrow-spacing.js +169 -163
- package/lib/rules/block-scoped-var.js +125 -123
- package/lib/rules/block-spacing.js +186 -176
- package/lib/rules/brace-style.js +262 -199
- package/lib/rules/callback-return.js +203 -190
- package/lib/rules/camelcase.js +403 -392
- package/lib/rules/capitalized-comments.js +253 -232
- package/lib/rules/class-methods-use-this.js +224 -172
- package/lib/rules/comma-dangle.js +379 -346
- package/lib/rules/comma-spacing.js +193 -195
- package/lib/rules/comma-style.js +375 -316
- package/lib/rules/complexity.js +173 -169
- package/lib/rules/computed-property-spacing.js +236 -211
- package/lib/rules/consistent-return.js +181 -170
- package/lib/rules/consistent-this.js +167 -147
- package/lib/rules/constructor-super.js +412 -404
- package/lib/rules/curly.js +407 -332
- package/lib/rules/default-case-last.js +38 -31
- package/lib/rules/default-case.js +89 -85
- package/lib/rules/default-param-last.js +69 -54
- package/lib/rules/dot-location.js +122 -110
- package/lib/rules/dot-notation.js +192 -156
- package/lib/rules/eol-last.js +122 -120
- package/lib/rules/eqeqeq.js +168 -155
- package/lib/rules/for-direction.js +146 -121
- package/lib/rules/func-call-spacing.js +261 -231
- package/lib/rules/func-name-matching.js +293 -209
- package/lib/rules/func-names.js +165 -164
- package/lib/rules/func-style.js +159 -127
- package/lib/rules/function-call-argument-newline.js +152 -129
- package/lib/rules/function-paren-newline.js +349 -291
- package/lib/rules/generator-star-spacing.js +229 -210
- package/lib/rules/getter-return.js +208 -172
- package/lib/rules/global-require.js +85 -74
- package/lib/rules/grouped-accessor-pairs.js +170 -150
- package/lib/rules/guard-for-in.js +72 -63
- package/lib/rules/handle-callback-err.js +108 -103
- package/lib/rules/id-blacklist.js +182 -199
- package/lib/rules/id-denylist.js +168 -187
- package/lib/rules/id-length.js +197 -171
- package/lib/rules/id-match.js +344 -289
- package/lib/rules/implicit-arrow-linebreak.js +102 -79
- package/lib/rules/indent-legacy.js +1344 -1118
- package/lib/rules/indent.js +2272 -1759
- package/lib/rules/index.js +317 -292
- package/lib/rules/init-declarations.js +137 -107
- package/lib/rules/jsx-quotes.js +94 -82
- package/lib/rules/key-spacing.js +750 -633
- package/lib/rules/keyword-spacing.js +648 -605
- package/lib/rules/line-comment-position.js +142 -128
- package/lib/rules/linebreak-style.js +107 -106
- package/lib/rules/lines-around-comment.js +540 -448
- package/lib/rules/lines-around-directive.js +233 -203
- package/lib/rules/lines-between-class-members.js +305 -234
- package/lib/rules/logical-assignment-operators.js +582 -399
- package/lib/rules/max-classes-per-file.js +69 -68
- package/lib/rules/max-depth.js +146 -143
- package/lib/rules/max-len.js +473 -434
- package/lib/rules/max-lines-per-function.js +201 -176
- package/lib/rules/max-lines.js +158 -162
- package/lib/rules/max-nested-callbacks.js +102 -104
- package/lib/rules/max-params.js +78 -76
- package/lib/rules/max-statements-per-line.js +205 -198
- package/lib/rules/max-statements.js +168 -164
- package/lib/rules/multiline-comment-style.js +637 -479
- package/lib/rules/multiline-ternary.js +241 -176
- package/lib/rules/new-cap.js +233 -213
- package/lib/rules/new-parens.js +88 -79
- package/lib/rules/newline-after-var.js +287 -250
- package/lib/rules/newline-before-return.js +229 -222
- package/lib/rules/newline-per-chained-call.js +142 -127
- package/lib/rules/no-alert.js +90 -79
- package/lib/rules/no-array-constructor.js +125 -113
- package/lib/rules/no-async-promise-executor.js +30 -24
- package/lib/rules/no-await-in-loop.js +69 -71
- package/lib/rules/no-bitwise.js +124 -100
- package/lib/rules/no-buffer-constructor.js +55 -47
- package/lib/rules/no-caller.js +39 -33
- package/lib/rules/no-case-declarations.js +61 -57
- package/lib/rules/no-catch-shadow.js +76 -73
- package/lib/rules/no-class-assign.js +51 -48
- package/lib/rules/no-compare-neg-zero.js +62 -48
- package/lib/rules/no-cond-assign.js +148 -132
- package/lib/rules/no-confusing-arrow.js +98 -81
- package/lib/rules/no-console.js +202 -199
- package/lib/rules/no-const-assign.js +47 -41
- package/lib/rules/no-constant-binary-expression.js +500 -405
- package/lib/rules/no-constant-condition.js +158 -143
- package/lib/rules/no-constructor-return.js +49 -49
- package/lib/rules/no-continue.js +25 -27
- package/lib/rules/no-control-regex.js +125 -121
- package/lib/rules/no-debugger.js +28 -30
- package/lib/rules/no-delete-var.js +29 -29
- package/lib/rules/no-div-regex.js +47 -41
- package/lib/rules/no-dupe-args.js +68 -69
- package/lib/rules/no-dupe-class-members.js +102 -89
- package/lib/rules/no-dupe-else-if.js +100 -77
- package/lib/rules/no-dupe-keys.js +133 -110
- package/lib/rules/no-duplicate-case.js +50 -43
- package/lib/rules/no-duplicate-imports.js +179 -176
- package/lib/rules/no-else-return.js +430 -385
- package/lib/rules/no-empty-character-class.js +57 -50
- package/lib/rules/no-empty-function.js +127 -128
- package/lib/rules/no-empty-pattern.js +63 -58
- package/lib/rules/no-empty-static-block.js +37 -35
- package/lib/rules/no-empty.js +98 -86
- package/lib/rules/no-eq-null.js +37 -32
- package/lib/rules/no-eval.js +256 -250
- package/lib/rules/no-ex-assign.js +42 -39
- package/lib/rules/no-extend-native.js +161 -159
- package/lib/rules/no-extra-bind.js +201 -190
- package/lib/rules/no-extra-boolean-cast.js +398 -348
- package/lib/rules/no-extra-label.js +150 -131
- package/lib/rules/no-extra-parens.js +1654 -1325
- package/lib/rules/no-extra-semi.js +146 -144
- package/lib/rules/no-fallthrough.js +199 -157
- package/lib/rules/no-floating-decimal.js +74 -66
- package/lib/rules/no-func-assign.js +54 -55
- package/lib/rules/no-global-assign.js +78 -73
- package/lib/rules/no-implicit-coercion.js +349 -293
- package/lib/rules/no-implicit-globals.js +158 -135
- package/lib/rules/no-implied-eval.js +140 -112
- package/lib/rules/no-import-assign.js +145 -159
- package/lib/rules/no-inline-comments.js +101 -95
- package/lib/rules/no-inner-declarations.js +115 -101
- package/lib/rules/no-invalid-regexp.js +222 -190
- package/lib/rules/no-invalid-this.js +123 -117
- package/lib/rules/no-irregular-whitespace.js +266 -252
- package/lib/rules/no-iterator.js +29 -33
- package/lib/rules/no-label-var.js +59 -62
- package/lib/rules/no-labels.js +138 -133
- package/lib/rules/no-lone-blocks.js +127 -123
- package/lib/rules/no-lonely-if.js +108 -77
- package/lib/rules/no-loop-func.js +238 -213
- package/lib/rules/no-loss-of-precision.js +218 -201
- package/lib/rules/no-magic-numbers.js +246 -218
- package/lib/rules/no-misleading-character-class.js +499 -446
- package/lib/rules/no-mixed-operators.js +188 -182
- package/lib/rules/no-mixed-requires.js +253 -240
- package/lib/rules/no-mixed-spaces-and-tabs.js +134 -121
- package/lib/rules/no-multi-assign.js +46 -44
- package/lib/rules/no-multi-spaces.js +163 -143
- package/lib/rules/no-multi-str.js +42 -41
- package/lib/rules/no-multiple-empty-lines.js +196 -158
- package/lib/rules/no-native-reassign.js +90 -85
- package/lib/rules/no-negated-condition.js +79 -75
- package/lib/rules/no-negated-in-lhs.js +45 -43
- package/lib/rules/no-nested-ternary.js +33 -32
- package/lib/rules/no-new-func.js +71 -62
- package/lib/rules/no-new-native-nonconstructor.js +43 -39
- package/lib/rules/no-new-object.js +48 -48
- package/lib/rules/no-new-require.js +48 -47
- package/lib/rules/no-new-symbol.js +52 -50
- package/lib/rules/no-new-wrappers.js +43 -41
- package/lib/rules/no-new.js +28 -29
- package/lib/rules/no-nonoctal-decimal-escape.js +141 -121
- package/lib/rules/no-obj-calls.js +66 -53
- package/lib/rules/no-object-constructor.js +104 -97
- package/lib/rules/no-octal-escape.js +40 -43
- package/lib/rules/no-octal.js +32 -32
- package/lib/rules/no-param-reassign.js +235 -217
- package/lib/rules/no-path-concat.js +66 -67
- package/lib/rules/no-plusplus.js +60 -61
- package/lib/rules/no-process-env.js +49 -48
- package/lib/rules/no-process-exit.js +54 -50
- package/lib/rules/no-promise-executor-return.js +214 -182
- package/lib/rules/no-proto.js +26 -29
- package/lib/rules/no-prototype-builtins.js +146 -124
- package/lib/rules/no-redeclare.js +154 -152
- package/lib/rules/no-regex-spaces.js +183 -161
- package/lib/rules/no-restricted-exports.js +208 -185
- package/lib/rules/no-restricted-globals.js +111 -112
- package/lib/rules/no-restricted-imports.js +657 -537
- package/lib/rules/no-restricted-modules.js +222 -202
- package/lib/rules/no-restricted-properties.js +181 -153
- package/lib/rules/no-restricted-syntax.js +56 -52
- package/lib/rules/no-return-assign.js +55 -50
- package/lib/rules/no-return-await.js +148 -124
- package/lib/rules/no-script-url.js +52 -45
- package/lib/rules/no-self-assign.js +148 -146
- package/lib/rules/no-self-compare.js +63 -46
- package/lib/rules/no-sequences.js +135 -116
- package/lib/rules/no-setter-return.js +185 -152
- package/lib/rules/no-shadow-restricted-names.js +61 -46
- package/lib/rules/no-shadow.js +342 -316
- package/lib/rules/no-spaced-func.js +82 -77
- package/lib/rules/no-sparse-arrays.js +54 -59
- package/lib/rules/no-sync.js +61 -60
- package/lib/rules/no-tabs.js +83 -72
- package/lib/rules/no-template-curly-in-string.js +33 -32
- package/lib/rules/no-ternary.js +25 -29
- package/lib/rules/no-this-before-super.js +321 -319
- package/lib/rules/no-throw-literal.js +31 -36
- package/lib/rules/no-trailing-spaces.js +199 -191
- package/lib/rules/no-undef-init.js +76 -61
- package/lib/rules/no-undef.js +51 -48
- package/lib/rules/no-undefined.js +73 -75
- package/lib/rules/no-underscore-dangle.js +370 -327
- package/lib/rules/no-unexpected-multiline.js +112 -102
- package/lib/rules/no-unmodified-loop-condition.js +254 -254
- package/lib/rules/no-unneeded-ternary.js +212 -147
- package/lib/rules/no-unreachable-loop.js +145 -142
- package/lib/rules/no-unreachable.js +255 -248
- package/lib/rules/no-unsafe-finally.js +93 -85
- package/lib/rules/no-unsafe-negation.js +105 -83
- package/lib/rules/no-unsafe-optional-chaining.js +192 -178
- package/lib/rules/no-unused-expressions.js +178 -162
- package/lib/rules/no-unused-labels.js +139 -124
- package/lib/rules/no-unused-private-class-members.js +206 -182
- package/lib/rules/no-unused-vars.js +1669 -1449
- package/lib/rules/no-use-before-define.js +229 -231
- package/lib/rules/no-useless-assignment.js +590 -511
- package/lib/rules/no-useless-backreference.js +212 -193
- package/lib/rules/no-useless-call.js +58 -53
- package/lib/rules/no-useless-catch.js +40 -40
- package/lib/rules/no-useless-computed-key.js +144 -115
- package/lib/rules/no-useless-concat.js +65 -60
- package/lib/rules/no-useless-constructor.js +158 -111
- package/lib/rules/no-useless-escape.js +342 -291
- package/lib/rules/no-useless-rename.js +183 -156
- package/lib/rules/no-useless-return.js +344 -312
- package/lib/rules/no-var.js +233 -212
- package/lib/rules/no-void.js +50 -48
- package/lib/rules/no-warning-comments.js +191 -186
- package/lib/rules/no-whitespace-before-property.js +131 -115
- package/lib/rules/no-with.js +24 -26
- package/lib/rules/nonblock-statement-body-position.js +149 -130
- package/lib/rules/object-curly-newline.js +306 -265
- package/lib/rules/object-curly-spacing.js +360 -314
- package/lib/rules/object-property-newline.js +137 -106
- package/lib/rules/object-shorthand.js +607 -502
- package/lib/rules/one-var-declaration-per-line.js +104 -100
- package/lib/rules/one-var.js +653 -537
- package/lib/rules/operator-assignment.js +219 -161
- package/lib/rules/operator-linebreak.js +295 -251
- package/lib/rules/padded-blocks.js +346 -308
- package/lib/rules/padding-line-between-statements.js +443 -439
- package/lib/rules/prefer-arrow-callback.js +362 -313
- package/lib/rules/prefer-const.js +418 -377
- package/lib/rules/prefer-destructuring.js +301 -279
- package/lib/rules/prefer-exponentiation-operator.js +176 -133
- package/lib/rules/prefer-named-capture-group.js +153 -140
- package/lib/rules/prefer-numeric-literals.js +121 -113
- package/lib/rules/prefer-object-has-own.js +116 -82
- package/lib/rules/prefer-object-spread.js +213 -193
- package/lib/rules/prefer-promise-reject-errors.js +140 -122
- package/lib/rules/prefer-reflect.js +127 -107
- package/lib/rules/prefer-regex-literals.js +578 -466
- package/lib/rules/prefer-rest-params.js +79 -80
- package/lib/rules/prefer-spread.js +47 -44
- package/lib/rules/prefer-template.js +266 -195
- package/lib/rules/quote-props.js +373 -307
- package/lib/rules/quotes.js +374 -326
- package/lib/rules/radix.js +152 -136
- package/lib/rules/require-atomic-updates.js +316 -285
- package/lib/rules/require-await.js +144 -116
- package/lib/rules/require-unicode-regexp.js +282 -177
- package/lib/rules/require-yield.js +53 -54
- package/lib/rules/rest-spread-spacing.js +128 -116
- package/lib/rules/semi-spacing.js +281 -250
- package/lib/rules/semi-style.js +176 -134
- package/lib/rules/semi.js +456 -436
- package/lib/rules/sort-imports.js +306 -233
- package/lib/rules/sort-keys.js +219 -188
- package/lib/rules/sort-vars.js +127 -93
- package/lib/rules/space-before-blocks.js +199 -189
- package/lib/rules/space-before-function-paren.js +186 -166
- package/lib/rules/space-in-parens.js +359 -288
- package/lib/rules/space-infix-ops.js +237 -201
- package/lib/rules/space-unary-ops.js +356 -298
- package/lib/rules/spaced-comment.js +363 -319
- package/lib/rules/strict.js +265 -230
- package/lib/rules/switch-colon-spacing.js +130 -122
- package/lib/rules/symbol-description.js +45 -48
- package/lib/rules/template-curly-spacing.js +148 -142
- package/lib/rules/template-tag-spacing.js +98 -88
- package/lib/rules/unicode-bom.js +54 -56
- package/lib/rules/use-isnan.js +237 -206
- package/lib/rules/utils/ast-utils.js +2039 -1860
- package/lib/rules/utils/char-source.js +162 -155
- package/lib/rules/utils/fix-tracker.js +83 -80
- package/lib/rules/utils/keywords.js +59 -59
- package/lib/rules/utils/lazy-loading-rule-map.js +79 -76
- package/lib/rules/utils/regular-expressions.js +32 -24
- package/lib/rules/utils/unicode/index.js +4 -4
- package/lib/rules/utils/unicode/is-combining-character.js +1 -1
- package/lib/rules/utils/unicode/is-emoji-modifier.js +1 -1
- package/lib/rules/utils/unicode/is-regional-indicator-symbol.js +1 -1
- package/lib/rules/utils/unicode/is-surrogate-pair.js +1 -1
- package/lib/rules/valid-typeof.js +153 -111
- package/lib/rules/vars-on-top.js +152 -145
- package/lib/rules/wrap-iife.js +204 -191
- package/lib/rules/wrap-regex.js +70 -58
- package/lib/rules/yield-star-spacing.js +145 -134
- package/lib/rules/yoda.js +283 -272
- package/lib/services/parser-service.js +35 -35
- package/lib/services/processor-service.js +66 -73
- package/lib/services/suppressions-service.js +289 -0
- package/lib/shared/ajv.js +14 -14
- package/lib/shared/assert.js +3 -4
- package/lib/shared/ast-utils.js +7 -6
- package/lib/shared/deep-merge-arrays.js +24 -22
- package/lib/shared/directives.js +3 -2
- package/lib/shared/flags.js +50 -17
- package/lib/shared/logging.js +24 -25
- package/lib/shared/option-utils.js +43 -36
- package/lib/shared/runtime-info.js +136 -127
- package/lib/shared/serialization.js +27 -27
- package/lib/shared/severity.js +22 -22
- package/lib/shared/stats.js +5 -5
- package/lib/shared/string-utils.js +16 -16
- package/lib/shared/text-table.js +28 -27
- package/lib/shared/traverser.js +153 -146
- package/lib/shared/types.js +4 -27
- package/lib/types/index.d.ts +2010 -1559
- package/lib/types/rules.d.ts +5253 -5140
- package/lib/types/use-at-your-own-risk.d.ts +32 -30
- package/lib/unsupported-api.js +5 -5
- package/messages/all-files-ignored.js +3 -3
- package/messages/all-matched-files-ignored.js +3 -3
- package/messages/config-file-missing.js +2 -2
- package/messages/config-plugin-missing.js +3 -3
- package/messages/config-serialize-function.js +9 -7
- package/messages/eslintrc-incompat.js +13 -15
- package/messages/eslintrc-plugins.js +3 -4
- package/messages/extend-config-missing.js +3 -3
- package/messages/failed-to-read-json.js +3 -3
- package/messages/file-not-found.js +3 -3
- package/messages/invalid-rule-options.js +2 -2
- package/messages/invalid-rule-severity.js +2 -2
- package/messages/no-config-found.js +3 -3
- package/messages/plugin-conflict.js +8 -8
- package/messages/plugin-invalid.js +3 -3
- package/messages/plugin-missing.js +3 -3
- package/messages/print-config-with-directory-path.js +2 -2
- package/messages/shared.js +6 -1
- package/messages/whitespace-found.js +3 -3
- 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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
225
|
+
basePath,
|
226
|
+
patterns,
|
227
|
+
rawPatterns,
|
228
|
+
configLoader,
|
229
|
+
errorOnUnmatchedPattern,
|
222
230
|
}) {
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
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 {
|
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
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
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
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
basePath,
|
372
|
-
pattern
|
373
|
-
});
|
375
|
+
const patternHasMatch = await globMatch({
|
376
|
+
basePath,
|
377
|
+
pattern,
|
378
|
+
});
|
374
379
|
|
375
|
-
|
376
|
-
|
377
|
-
|
380
|
+
if (patternHasMatch) {
|
381
|
+
throw new AllFilesIgnoredError(rawPattern);
|
382
|
+
}
|
378
383
|
|
379
|
-
|
380
|
-
|
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({
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
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
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
482
|
+
patterns,
|
483
|
+
globInputPaths,
|
484
|
+
cwd,
|
485
|
+
configLoader,
|
486
|
+
errorOnUnmatchedPattern,
|
480
487
|
}) {
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
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
|
-
|
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
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
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
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
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
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
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
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
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
|
-
|
1028
|
+
findFiles,
|
955
1029
|
|
956
|
-
|
957
|
-
|
1030
|
+
isNonEmptyString,
|
1031
|
+
isArrayOfNonEmptyString,
|
958
1032
|
|
959
|
-
|
960
|
-
|
1033
|
+
createIgnoreResult,
|
1034
|
+
isErrorMessage,
|
1035
|
+
calculateStatsPerFile,
|
961
1036
|
|
962
|
-
|
1037
|
+
processOptions,
|
963
1038
|
|
964
|
-
|
1039
|
+
getCacheFile,
|
965
1040
|
};
|