bahlint 28.58.6934
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/LICENSE +19 -0
- package/README.md +370 -0
- package/bin/eslint.js +195 -0
- package/conf/ecma-version.js +16 -0
- package/conf/globals.js +169 -0
- package/conf/replacements.json +26 -0
- package/conf/rule-type-list.json +91 -0
- package/lib/api.js +39 -0
- package/lib/cli-engine/formatters/formatters-meta.json +22 -0
- package/lib/cli-engine/formatters/gasoline.js +168 -0
- package/lib/cli-engine/formatters/html.js +359 -0
- package/lib/cli-engine/formatters/json-with-metadata.js +16 -0
- package/lib/cli-engine/formatters/json.js +13 -0
- package/lib/cli-engine/formatters/stylish.js +153 -0
- package/lib/cli-engine/hash.js +35 -0
- package/lib/cli-engine/lint-result-cache.js +220 -0
- package/lib/cli.js +607 -0
- package/lib/config/config-loader.js +683 -0
- package/lib/config/config.js +674 -0
- package/lib/config/default-config.js +78 -0
- package/lib/config/flat-config-array.js +217 -0
- package/lib/config/flat-config-schema.js +598 -0
- package/lib/config-api.js +12 -0
- package/lib/eslint/eslint-helpers.js +1462 -0
- package/lib/eslint/eslint.js +1364 -0
- package/lib/eslint/index.js +7 -0
- package/lib/eslint/worker.js +173 -0
- package/lib/languages/js/index.js +336 -0
- package/lib/languages/js/source-code/index.js +7 -0
- package/lib/languages/js/source-code/source-code.js +1178 -0
- package/lib/languages/js/source-code/token-store/backward-token-comment-cursor.js +61 -0
- package/lib/languages/js/source-code/token-store/backward-token-cursor.js +57 -0
- package/lib/languages/js/source-code/token-store/cursor.js +76 -0
- package/lib/languages/js/source-code/token-store/cursors.js +120 -0
- package/lib/languages/js/source-code/token-store/decorative-cursor.js +38 -0
- package/lib/languages/js/source-code/token-store/filter-cursor.js +42 -0
- package/lib/languages/js/source-code/token-store/forward-token-comment-cursor.js +65 -0
- package/lib/languages/js/source-code/token-store/forward-token-cursor.js +62 -0
- package/lib/languages/js/source-code/token-store/index.js +695 -0
- package/lib/languages/js/source-code/token-store/limit-cursor.js +39 -0
- package/lib/languages/js/source-code/token-store/padded-token-cursor.js +45 -0
- package/lib/languages/js/source-code/token-store/skip-cursor.js +41 -0
- package/lib/languages/js/source-code/token-store/utils.js +131 -0
- package/lib/languages/js/validate-language-options.js +196 -0
- package/lib/linter/apply-disable-directives.js +583 -0
- package/lib/linter/code-path-analysis/code-path-analyzer.js +828 -0
- package/lib/linter/code-path-analysis/code-path-segment.js +262 -0
- package/lib/linter/code-path-analysis/code-path-state.js +2370 -0
- package/lib/linter/code-path-analysis/code-path.js +332 -0
- package/lib/linter/code-path-analysis/debug-helpers.js +223 -0
- package/lib/linter/code-path-analysis/fork-context.js +374 -0
- package/lib/linter/code-path-analysis/id-generator.js +44 -0
- package/lib/linter/esquery.js +332 -0
- package/lib/linter/file-context.js +88 -0
- package/lib/linter/file-report.js +604 -0
- package/lib/linter/index.js +11 -0
- package/lib/linter/interpolate.js +50 -0
- package/lib/linter/linter.js +1614 -0
- package/lib/linter/rule-fixer.js +199 -0
- package/lib/linter/source-code-fixer.js +154 -0
- package/lib/linter/source-code-traverser.js +333 -0
- package/lib/linter/source-code-visitor.js +81 -0
- package/lib/linter/timing.js +209 -0
- package/lib/linter/vfile.js +115 -0
- package/lib/options.js +416 -0
- package/lib/rule-tester/index.js +7 -0
- package/lib/rule-tester/rule-tester.js +1817 -0
- package/lib/rules/accessor-pairs.js +420 -0
- package/lib/rules/array-bracket-newline.js +291 -0
- package/lib/rules/array-bracket-spacing.js +301 -0
- package/lib/rules/array-callback-return.js +493 -0
- package/lib/rules/array-element-newline.js +374 -0
- package/lib/rules/arrow-body-style.js +418 -0
- package/lib/rules/arrow-parens.js +237 -0
- package/lib/rules/arrow-spacing.js +188 -0
- package/lib/rules/block-scoped-var.js +137 -0
- package/lib/rules/block-spacing.js +202 -0
- package/lib/rules/brace-style.js +278 -0
- package/lib/rules/callback-return.js +216 -0
- package/lib/rules/camelcase.js +422 -0
- package/lib/rules/capitalized-comments.js +325 -0
- package/lib/rules/class-methods-use-this.js +250 -0
- package/lib/rules/comma-dangle.js +424 -0
- package/lib/rules/comma-spacing.js +205 -0
- package/lib/rules/comma-style.js +391 -0
- package/lib/rules/complexity.js +201 -0
- package/lib/rules/computed-property-spacing.js +251 -0
- package/lib/rules/consistent-return.js +221 -0
- package/lib/rules/consistent-this.js +179 -0
- package/lib/rules/constructor-super.js +453 -0
- package/lib/rules/curly.js +425 -0
- package/lib/rules/default-case-last.js +51 -0
- package/lib/rules/default-case.js +103 -0
- package/lib/rules/default-param-last.js +78 -0
- package/lib/rules/dot-location.js +138 -0
- package/lib/rules/dot-notation.js +216 -0
- package/lib/rules/eol-last.js +135 -0
- package/lib/rules/eqeqeq.js +210 -0
- package/lib/rules/for-direction.js +168 -0
- package/lib/rules/func-call-spacing.js +281 -0
- package/lib/rules/func-name-matching.js +338 -0
- package/lib/rules/func-names.js +194 -0
- package/lib/rules/func-style.js +221 -0
- package/lib/rules/function-call-argument-newline.js +166 -0
- package/lib/rules/function-paren-newline.js +368 -0
- package/lib/rules/generator-star-spacing.js +246 -0
- package/lib/rules/getter-return.js +242 -0
- package/lib/rules/global-require.js +117 -0
- package/lib/rules/grouped-accessor-pairs.js +268 -0
- package/lib/rules/guard-for-in.js +85 -0
- package/lib/rules/handle-callback-err.js +122 -0
- package/lib/rules/id-blacklist.js +241 -0
- package/lib/rules/id-denylist.js +223 -0
- package/lib/rules/id-length.js +217 -0
- package/lib/rules/id-match.js +363 -0
- package/lib/rules/implicit-arrow-linebreak.js +125 -0
- package/lib/rules/indent-legacy.js +1369 -0
- package/lib/rules/indent.js +2334 -0
- package/lib/rules/index.js +332 -0
- package/lib/rules/init-declarations.js +172 -0
- package/lib/rules/jsx-quotes.js +128 -0
- package/lib/rules/key-spacing.js +822 -0
- package/lib/rules/keyword-spacing.js +701 -0
- package/lib/rules/line-comment-position.js +157 -0
- package/lib/rules/linebreak-style.js +135 -0
- package/lib/rules/lines-around-comment.js +581 -0
- package/lib/rules/lines-around-directive.js +249 -0
- package/lib/rules/lines-between-class-members.js +358 -0
- package/lib/rules/logical-assignment-operators.js +688 -0
- package/lib/rules/max-classes-per-file.js +90 -0
- package/lib/rules/max-depth.js +159 -0
- package/lib/rules/max-len.js +497 -0
- package/lib/rules/max-lines-per-function.js +238 -0
- package/lib/rules/max-lines.js +189 -0
- package/lib/rules/max-nested-callbacks.js +115 -0
- package/lib/rules/max-params.js +148 -0
- package/lib/rules/max-statements-per-line.js +224 -0
- package/lib/rules/max-statements.js +188 -0
- package/lib/rules/multiline-comment-style.js +652 -0
- package/lib/rules/multiline-ternary.js +257 -0
- package/lib/rules/new-cap.js +277 -0
- package/lib/rules/new-parens.js +120 -0
- package/lib/rules/newline-after-var.js +307 -0
- package/lib/rules/newline-before-return.js +242 -0
- package/lib/rules/newline-per-chained-call.js +159 -0
- package/lib/rules/no-alert.js +149 -0
- package/lib/rules/no-array-constructor.js +195 -0
- package/lib/rules/no-async-promise-executor.js +45 -0
- package/lib/rules/no-await-in-loop.js +115 -0
- package/lib/rules/no-bitwise.js +145 -0
- package/lib/rules/no-buffer-constructor.js +74 -0
- package/lib/rules/no-caller.js +52 -0
- package/lib/rules/no-case-declarations.js +80 -0
- package/lib/rules/no-catch-shadow.js +96 -0
- package/lib/rules/no-class-assign.js +66 -0
- package/lib/rules/no-compare-neg-zero.js +74 -0
- package/lib/rules/no-cond-assign.js +175 -0
- package/lib/rules/no-confusing-arrow.js +127 -0
- package/lib/rules/no-console.js +221 -0
- package/lib/rules/no-const-assign.js +73 -0
- package/lib/rules/no-constant-binary-expression.js +603 -0
- package/lib/rules/no-constant-condition.js +177 -0
- package/lib/rules/no-constructor-return.js +62 -0
- package/lib/rules/no-continue.js +38 -0
- package/lib/rules/no-control-regex.js +142 -0
- package/lib/rules/no-debugger.js +41 -0
- package/lib/rules/no-delete-var.js +42 -0
- package/lib/rules/no-div-regex.js +60 -0
- package/lib/rules/no-dupe-args.js +92 -0
- package/lib/rules/no-dupe-class-members.js +117 -0
- package/lib/rules/no-dupe-else-if.js +145 -0
- package/lib/rules/no-dupe-keys.js +165 -0
- package/lib/rules/no-duplicate-case.js +78 -0
- package/lib/rules/no-duplicate-imports.js +368 -0
- package/lib/rules/no-else-return.js +450 -0
- package/lib/rules/no-empty-character-class.js +83 -0
- package/lib/rules/no-empty-function.js +236 -0
- package/lib/rules/no-empty-pattern.js +85 -0
- package/lib/rules/no-empty-static-block.js +73 -0
- package/lib/rules/no-empty.js +153 -0
- package/lib/rules/no-eq-null.js +51 -0
- package/lib/rules/no-eval.js +295 -0
- package/lib/rules/no-ex-assign.js +57 -0
- package/lib/rules/no-extend-native.js +180 -0
- package/lib/rules/no-extra-bind.js +224 -0
- package/lib/rules/no-extra-boolean-cast.js +420 -0
- package/lib/rules/no-extra-label.js +169 -0
- package/lib/rules/no-extra-parens.js +1669 -0
- package/lib/rules/no-extra-semi.js +167 -0
- package/lib/rules/no-fallthrough.js +260 -0
- package/lib/rules/no-floating-decimal.js +99 -0
- package/lib/rules/no-func-assign.js +77 -0
- package/lib/rules/no-global-assign.js +101 -0
- package/lib/rules/no-implicit-coercion.js +468 -0
- package/lib/rules/no-implicit-globals.js +187 -0
- package/lib/rules/no-implied-eval.js +170 -0
- package/lib/rules/no-import-assign.js +227 -0
- package/lib/rules/no-inline-comments.js +115 -0
- package/lib/rules/no-inner-declarations.js +147 -0
- package/lib/rules/no-invalid-regexp.js +244 -0
- package/lib/rules/no-invalid-this.js +178 -0
- package/lib/rules/no-irregular-whitespace.js +292 -0
- package/lib/rules/no-iterator.js +48 -0
- package/lib/rules/no-label-var.js +78 -0
- package/lib/rules/no-labels.js +156 -0
- package/lib/rules/no-lone-blocks.js +140 -0
- package/lib/rules/no-lonely-if.js +126 -0
- package/lib/rules/no-loop-func.js +267 -0
- package/lib/rules/no-loss-of-precision.js +249 -0
- package/lib/rules/no-magic-numbers.js +365 -0
- package/lib/rules/no-misleading-character-class.js +595 -0
- package/lib/rules/no-mixed-operators.js +253 -0
- package/lib/rules/no-mixed-requires.js +267 -0
- package/lib/rules/no-mixed-spaces-and-tabs.js +148 -0
- package/lib/rules/no-multi-assign.js +66 -0
- package/lib/rules/no-multi-spaces.js +179 -0
- package/lib/rules/no-multi-str.js +67 -0
- package/lib/rules/no-multiple-empty-lines.js +210 -0
- package/lib/rules/no-native-reassign.js +114 -0
- package/lib/rules/no-negated-condition.js +100 -0
- package/lib/rules/no-negated-in-lhs.js +59 -0
- package/lib/rules/no-nested-ternary.js +46 -0
- package/lib/rules/no-new-func.js +96 -0
- package/lib/rules/no-new-native-nonconstructor.js +70 -0
- package/lib/rules/no-new-object.js +76 -0
- package/lib/rules/no-new-require.js +67 -0
- package/lib/rules/no-new-symbol.js +74 -0
- package/lib/rules/no-new-wrappers.js +62 -0
- package/lib/rules/no-new.js +42 -0
- package/lib/rules/no-nonoctal-decimal-escape.js +176 -0
- package/lib/rules/no-obj-calls.js +99 -0
- package/lib/rules/no-object-constructor.js +124 -0
- package/lib/rules/no-octal-escape.js +53 -0
- package/lib/rules/no-octal.js +42 -0
- package/lib/rules/no-param-reassign.js +248 -0
- package/lib/rules/no-path-concat.js +79 -0
- package/lib/rules/no-plusplus.js +102 -0
- package/lib/rules/no-process-env.js +68 -0
- package/lib/rules/no-process-exit.js +67 -0
- package/lib/rules/no-promise-executor-return.js +264 -0
- package/lib/rules/no-proto.js +45 -0
- package/lib/rules/no-prototype-builtins.js +181 -0
- package/lib/rules/no-redeclare.js +173 -0
- package/lib/rules/no-regex-spaces.js +219 -0
- package/lib/rules/no-restricted-exports.js +227 -0
- package/lib/rules/no-restricted-globals.js +266 -0
- package/lib/rules/no-restricted-imports.js +892 -0
- package/lib/rules/no-restricted-modules.js +249 -0
- package/lib/rules/no-restricted-properties.js +233 -0
- package/lib/rules/no-restricted-syntax.js +74 -0
- package/lib/rules/no-return-assign.js +87 -0
- package/lib/rules/no-return-await.js +162 -0
- package/lib/rules/no-script-url.js +68 -0
- package/lib/rules/no-self-assign.js +186 -0
- package/lib/rules/no-self-compare.js +77 -0
- package/lib/rules/no-sequences.js +158 -0
- package/lib/rules/no-setter-return.js +224 -0
- package/lib/rules/no-shadow-restricted-names.js +113 -0
- package/lib/rules/no-shadow.js +624 -0
- package/lib/rules/no-spaced-func.js +105 -0
- package/lib/rules/no-sparse-arrays.js +68 -0
- package/lib/rules/no-sync.js +81 -0
- package/lib/rules/no-tabs.js +110 -0
- package/lib/rules/no-template-curly-in-string.js +45 -0
- package/lib/rules/no-ternary.js +38 -0
- package/lib/rules/no-this-before-super.js +365 -0
- package/lib/rules/no-throw-literal.js +46 -0
- package/lib/rules/no-trailing-spaces.js +227 -0
- package/lib/rules/no-unassigned-vars.js +80 -0
- package/lib/rules/no-undef-init.js +101 -0
- package/lib/rules/no-undef.js +84 -0
- package/lib/rules/no-undefined.js +85 -0
- package/lib/rules/no-underscore-dangle.js +383 -0
- package/lib/rules/no-unexpected-multiline.js +130 -0
- package/lib/rules/no-unmodified-loop-condition.js +360 -0
- package/lib/rules/no-unneeded-ternary.js +232 -0
- package/lib/rules/no-unreachable-loop.js +190 -0
- package/lib/rules/no-unreachable.js +300 -0
- package/lib/rules/no-unsafe-finally.js +119 -0
- package/lib/rules/no-unsafe-negation.js +152 -0
- package/lib/rules/no-unsafe-optional-chaining.js +221 -0
- package/lib/rules/no-unused-expressions.js +227 -0
- package/lib/rules/no-unused-labels.js +158 -0
- package/lib/rules/no-unused-private-class-members.js +219 -0
- package/lib/rules/no-unused-vars.js +1739 -0
- package/lib/rules/no-use-before-define.js +446 -0
- package/lib/rules/no-useless-assignment.js +657 -0
- package/lib/rules/no-useless-backreference.js +263 -0
- package/lib/rules/no-useless-call.js +95 -0
- package/lib/rules/no-useless-catch.js +57 -0
- package/lib/rules/no-useless-computed-key.js +204 -0
- package/lib/rules/no-useless-concat.js +121 -0
- package/lib/rules/no-useless-constructor.js +262 -0
- package/lib/rules/no-useless-escape.js +406 -0
- package/lib/rules/no-useless-rename.js +202 -0
- package/lib/rules/no-useless-return.js +401 -0
- package/lib/rules/no-var.js +367 -0
- package/lib/rules/no-void.js +69 -0
- package/lib/rules/no-warning-comments.js +209 -0
- package/lib/rules/no-whitespace-before-property.js +150 -0
- package/lib/rules/no-with.js +37 -0
- package/lib/rules/nonblock-statement-body-position.js +164 -0
- package/lib/rules/object-curly-newline.js +383 -0
- package/lib/rules/object-curly-spacing.js +369 -0
- package/lib/rules/object-property-newline.js +151 -0
- package/lib/rules/object-shorthand.js +652 -0
- package/lib/rules/one-var-declaration-per-line.js +117 -0
- package/lib/rules/one-var.js +717 -0
- package/lib/rules/operator-assignment.js +270 -0
- package/lib/rules/operator-linebreak.js +315 -0
- package/lib/rules/padded-blocks.js +366 -0
- package/lib/rules/padding-line-between-statements.js +612 -0
- package/lib/rules/prefer-arrow-callback.js +437 -0
- package/lib/rules/prefer-const.js +546 -0
- package/lib/rules/prefer-destructuring.js +332 -0
- package/lib/rules/prefer-exponentiation-operator.js +235 -0
- package/lib/rules/prefer-named-capture-group.js +197 -0
- package/lib/rules/prefer-numeric-literals.js +157 -0
- package/lib/rules/prefer-object-has-own.js +148 -0
- package/lib/rules/prefer-object-spread.js +319 -0
- package/lib/rules/prefer-promise-reject-errors.js +154 -0
- package/lib/rules/prefer-reflect.js +150 -0
- package/lib/rules/prefer-regex-literals.js +605 -0
- package/lib/rules/prefer-rest-params.js +117 -0
- package/lib/rules/prefer-spread.js +91 -0
- package/lib/rules/prefer-template.js +347 -0
- package/lib/rules/preserve-caught-error.js +535 -0
- package/lib/rules/quote-props.js +394 -0
- package/lib/rules/quotes.js +416 -0
- package/lib/rules/radix.js +193 -0
- package/lib/rules/require-atomic-updates.js +365 -0
- package/lib/rules/require-await.js +184 -0
- package/lib/rules/require-unicode-regexp.js +317 -0
- package/lib/rules/require-yield.js +86 -0
- package/lib/rules/rest-spread-spacing.js +150 -0
- package/lib/rules/semi-spacing.js +297 -0
- package/lib/rules/semi-style.js +218 -0
- package/lib/rules/semi.js +476 -0
- package/lib/rules/sort-imports.js +319 -0
- package/lib/rules/sort-keys.js +268 -0
- package/lib/rules/sort-vars.js +140 -0
- package/lib/rules/space-before-blocks.js +232 -0
- package/lib/rules/space-before-function-paren.js +202 -0
- package/lib/rules/space-in-parens.js +374 -0
- package/lib/rules/space-infix-ops.js +249 -0
- package/lib/rules/space-unary-ops.js +400 -0
- package/lib/rules/spaced-comment.js +447 -0
- package/lib/rules/strict.js +314 -0
- package/lib/rules/switch-colon-spacing.js +158 -0
- package/lib/rules/symbol-description.js +70 -0
- package/lib/rules/template-curly-spacing.js +168 -0
- package/lib/rules/template-tag-spacing.js +121 -0
- package/lib/rules/unicode-bom.js +73 -0
- package/lib/rules/use-isnan.js +268 -0
- package/lib/rules/utils/ast-utils.js +2828 -0
- package/lib/rules/utils/char-source.js +247 -0
- package/lib/rules/utils/fix-tracker.js +125 -0
- package/lib/rules/utils/keywords.js +67 -0
- package/lib/rules/utils/lazy-loading-rule-map.js +118 -0
- package/lib/rules/utils/regular-expressions.js +58 -0
- package/lib/rules/utils/unicode/index.js +16 -0
- package/lib/rules/utils/unicode/is-combining-character.js +13 -0
- package/lib/rules/utils/unicode/is-emoji-modifier.js +13 -0
- package/lib/rules/utils/unicode/is-regional-indicator-symbol.js +13 -0
- package/lib/rules/utils/unicode/is-surrogate-pair.js +14 -0
- package/lib/rules/valid-typeof.js +171 -0
- package/lib/rules/vars-on-top.js +165 -0
- package/lib/rules/wrap-iife.js +238 -0
- package/lib/rules/wrap-regex.js +91 -0
- package/lib/rules/yield-star-spacing.js +158 -0
- package/lib/rules/yoda.js +362 -0
- package/lib/services/parser-service.js +64 -0
- package/lib/services/processor-service.js +100 -0
- package/lib/services/suppressions-service.js +302 -0
- package/lib/services/warning-service.js +87 -0
- package/lib/shared/ajv.js +34 -0
- package/lib/shared/assert.js +21 -0
- package/lib/shared/ast-utils.js +30 -0
- package/lib/shared/deep-merge-arrays.js +62 -0
- package/lib/shared/directives.js +16 -0
- package/lib/shared/flags.js +89 -0
- package/lib/shared/logging.js +38 -0
- package/lib/shared/naming.js +109 -0
- package/lib/shared/option-utils.js +63 -0
- package/lib/shared/relative-module-resolver.js +28 -0
- package/lib/shared/runtime-info.js +177 -0
- package/lib/shared/serialization.js +78 -0
- package/lib/shared/severity.js +49 -0
- package/lib/shared/stats.js +30 -0
- package/lib/shared/string-utils.js +58 -0
- package/lib/shared/text-table.js +68 -0
- package/lib/shared/translate-cli-options.js +223 -0
- package/lib/shared/traverser.js +202 -0
- package/lib/types/config-api.d.ts +12 -0
- package/lib/types/index.d.ts +1482 -0
- package/lib/types/rules.d.ts +5603 -0
- package/lib/types/universal.d.ts +6 -0
- package/lib/types/use-at-your-own-risk.d.ts +34 -0
- package/lib/universal.js +10 -0
- package/lib/unsupported-api.js +26 -0
- package/messages/all-files-ignored.js +16 -0
- package/messages/all-matched-files-ignored.js +21 -0
- package/messages/config-file-missing.js +16 -0
- package/messages/config-plugin-missing.js +14 -0
- package/messages/config-serialize-function.js +30 -0
- package/messages/eslintrc-incompat.js +117 -0
- package/messages/eslintrc-plugins.js +27 -0
- package/messages/extend-config-missing.js +13 -0
- package/messages/failed-to-read-json.js +11 -0
- package/messages/file-not-found.js +10 -0
- package/messages/invalid-rule-options.js +17 -0
- package/messages/invalid-rule-severity.js +13 -0
- package/messages/no-config-found.js +15 -0
- package/messages/plugin-conflict.js +22 -0
- package/messages/plugin-invalid.js +16 -0
- package/messages/plugin-missing.js +19 -0
- package/messages/print-config-with-directory-path.js +8 -0
- package/messages/shared.js +23 -0
- package/messages/whitespace-found.js +11 -0
- package/package.json +220 -0
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A module that filters reported problems based on `eslint-disable` and `eslint-enable` comments
|
|
3
|
+
* @author Teddy Katz
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
// Typedefs
|
|
10
|
+
//------------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
/** @typedef {import("../types").Linter.LintMessage} LintMessage */
|
|
13
|
+
/** @typedef {import("@eslint/core").Language} Language */
|
|
14
|
+
/** @typedef {import("@eslint/core").Position} Position */
|
|
15
|
+
/** @typedef {import("@eslint/core").RulesConfig} RulesConfig */
|
|
16
|
+
|
|
17
|
+
//------------------------------------------------------------------------------
|
|
18
|
+
// Module Definition
|
|
19
|
+
//------------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
const escapeRegExp = require("escape-string-regexp");
|
|
22
|
+
const { Config } = require("../config/config.js");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Compares the locations of two objects in a source file
|
|
26
|
+
* @param {Position} itemA The first object
|
|
27
|
+
* @param {Position} itemB The second object
|
|
28
|
+
* @returns {number} A value less than 1 if itemA appears before itemB in the source file, greater than 1 if
|
|
29
|
+
* itemA appears after itemB in the source file, or 0 if itemA and itemB have the same location.
|
|
30
|
+
*/
|
|
31
|
+
function compareLocations(itemA, itemB) {
|
|
32
|
+
return itemA.line - itemB.line || itemA.column - itemB.column;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Groups a set of directives into sub-arrays by their parent comment.
|
|
37
|
+
* @param {Iterable<Directive>} directives Unused directives to be removed.
|
|
38
|
+
* @returns {Directive[][]} Directives grouped by their parent comment.
|
|
39
|
+
*/
|
|
40
|
+
function groupByParentDirective(directives) {
|
|
41
|
+
const groups = new Map();
|
|
42
|
+
|
|
43
|
+
for (const directive of directives) {
|
|
44
|
+
const {
|
|
45
|
+
unprocessedDirective: { parentDirective },
|
|
46
|
+
} = directive;
|
|
47
|
+
|
|
48
|
+
if (groups.has(parentDirective)) {
|
|
49
|
+
groups.get(parentDirective).push(directive);
|
|
50
|
+
} else {
|
|
51
|
+
groups.set(parentDirective, [directive]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return [...groups.values()];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Creates removal details for a set of directives within the same comment.
|
|
60
|
+
* @param {Directive[]} directives Unused directives to be removed.
|
|
61
|
+
* @param {{node: Token, value: string}} parentDirective Data about the backing directive.
|
|
62
|
+
* @param {SourceCode} sourceCode The source code object for the file being linted.
|
|
63
|
+
* @returns {{ description, fix, unprocessedDirective }[]} Details for later creation of output Problems.
|
|
64
|
+
*/
|
|
65
|
+
function createIndividualDirectivesRemoval(
|
|
66
|
+
directives,
|
|
67
|
+
parentDirective,
|
|
68
|
+
sourceCode,
|
|
69
|
+
) {
|
|
70
|
+
/*
|
|
71
|
+
* Get the list of the rules text without any surrounding whitespace. In order to preserve the original
|
|
72
|
+
* formatting, we don't want to change that whitespace.
|
|
73
|
+
*
|
|
74
|
+
* // eslint-disable-line rule-one , rule-two , rule-three -- comment
|
|
75
|
+
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
76
|
+
*/
|
|
77
|
+
const listText = parentDirective.value.trim();
|
|
78
|
+
|
|
79
|
+
// Calculate where it starts in the source code text
|
|
80
|
+
const listStart = sourceCode.text.indexOf(
|
|
81
|
+
listText,
|
|
82
|
+
sourceCode.getRange(parentDirective.node)[0],
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* We can assume that `listText` contains multiple elements.
|
|
87
|
+
* Otherwise, this function wouldn't be called - if there is
|
|
88
|
+
* only one rule in the list, then the whole comment must be removed.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
return directives.map(directive => {
|
|
92
|
+
const { ruleId } = directive;
|
|
93
|
+
|
|
94
|
+
const regex = new RegExp(
|
|
95
|
+
String.raw`(?:^|\s*,\s*)(?<quote>['"]?)${escapeRegExp(ruleId)}\k<quote>(?:\s*,\s*|$)`,
|
|
96
|
+
"u",
|
|
97
|
+
);
|
|
98
|
+
const match = regex.exec(listText);
|
|
99
|
+
const matchedText = match[0];
|
|
100
|
+
const matchStart = listStart + match.index;
|
|
101
|
+
const matchEnd = matchStart + matchedText.length;
|
|
102
|
+
|
|
103
|
+
const firstIndexOfComma = matchedText.indexOf(",");
|
|
104
|
+
const lastIndexOfComma = matchedText.lastIndexOf(",");
|
|
105
|
+
|
|
106
|
+
let removalStart, removalEnd;
|
|
107
|
+
|
|
108
|
+
if (firstIndexOfComma !== lastIndexOfComma) {
|
|
109
|
+
/*
|
|
110
|
+
* Since there are two commas, this must one of the elements in the middle of the list.
|
|
111
|
+
* Matched range starts where the previous rule name ends, and ends where the next rule name starts.
|
|
112
|
+
*
|
|
113
|
+
* // eslint-disable-line rule-one , rule-two , rule-three -- comment
|
|
114
|
+
* ^^^^^^^^^^^^^^
|
|
115
|
+
*
|
|
116
|
+
* We want to remove only the content between the two commas, and also one of the commas.
|
|
117
|
+
*
|
|
118
|
+
* // eslint-disable-line rule-one , rule-two , rule-three -- comment
|
|
119
|
+
* ^^^^^^^^^^^
|
|
120
|
+
*/
|
|
121
|
+
removalStart = matchStart + firstIndexOfComma;
|
|
122
|
+
removalEnd = matchStart + lastIndexOfComma;
|
|
123
|
+
} else {
|
|
124
|
+
/*
|
|
125
|
+
* This is either the first element or the last element.
|
|
126
|
+
*
|
|
127
|
+
* If this is the first element, matched range starts where the first rule name starts
|
|
128
|
+
* and ends where the second rule name starts. This is exactly the range we want
|
|
129
|
+
* to remove so that the second rule name will start where the first one was starting
|
|
130
|
+
* and thus preserve the original formatting.
|
|
131
|
+
*
|
|
132
|
+
* // eslint-disable-line rule-one , rule-two , rule-three -- comment
|
|
133
|
+
* ^^^^^^^^^^^
|
|
134
|
+
*
|
|
135
|
+
* Similarly, if this is the last element, we've already matched the range we want to
|
|
136
|
+
* remove. The previous rule name will end where the last one was ending, relative
|
|
137
|
+
* to the content on the right side.
|
|
138
|
+
*
|
|
139
|
+
* // eslint-disable-line rule-one , rule-two , rule-three -- comment
|
|
140
|
+
* ^^^^^^^^^^^^^
|
|
141
|
+
*/
|
|
142
|
+
removalStart = matchStart;
|
|
143
|
+
removalEnd = matchEnd;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
description: `'${ruleId}'`,
|
|
148
|
+
fix: {
|
|
149
|
+
range: [removalStart, removalEnd],
|
|
150
|
+
text: "",
|
|
151
|
+
},
|
|
152
|
+
unprocessedDirective: directive.unprocessedDirective,
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Creates a description of deleting an entire unused disable directive.
|
|
159
|
+
* @param {Directive[]} directives Unused directives to be removed.
|
|
160
|
+
* @param {Token} node The backing Comment token.
|
|
161
|
+
* @param {SourceCode} sourceCode The source code object for the file being linted.
|
|
162
|
+
* @returns {{ description, fix, unprocessedDirective }} Details for later creation of an output problem.
|
|
163
|
+
*/
|
|
164
|
+
function createDirectiveRemoval(directives, node, sourceCode) {
|
|
165
|
+
const range = sourceCode.getRange(node);
|
|
166
|
+
const ruleIds = directives
|
|
167
|
+
.filter(directive => directive.ruleId)
|
|
168
|
+
.map(directive => `'${directive.ruleId}'`);
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
description:
|
|
172
|
+
ruleIds.length <= 2
|
|
173
|
+
? ruleIds.join(" or ")
|
|
174
|
+
: `${ruleIds.slice(0, ruleIds.length - 1).join(", ")}, or ${ruleIds.at(-1)}`,
|
|
175
|
+
fix: {
|
|
176
|
+
range,
|
|
177
|
+
text: " ",
|
|
178
|
+
},
|
|
179
|
+
unprocessedDirective: directives[0].unprocessedDirective,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Parses details from directives to create output Problems.
|
|
185
|
+
* @param {Iterable<Directive>} allDirectives Unused directives to be removed.
|
|
186
|
+
* @param {SourceCode} sourceCode The source code object for the file being linted.
|
|
187
|
+
* @returns {{ description, fix, unprocessedDirective }[]} Details for later creation of output Problems.
|
|
188
|
+
*/
|
|
189
|
+
function processUnusedDirectives(allDirectives, sourceCode) {
|
|
190
|
+
const directiveGroups = groupByParentDirective(allDirectives);
|
|
191
|
+
|
|
192
|
+
return directiveGroups.flatMap(directives => {
|
|
193
|
+
const { parentDirective } = directives[0].unprocessedDirective;
|
|
194
|
+
const remainingRuleIds = new Set(parentDirective.ruleIds);
|
|
195
|
+
|
|
196
|
+
for (const directive of directives) {
|
|
197
|
+
remainingRuleIds.delete(directive.ruleId);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return remainingRuleIds.size
|
|
201
|
+
? createIndividualDirectivesRemoval(
|
|
202
|
+
directives,
|
|
203
|
+
parentDirective,
|
|
204
|
+
sourceCode,
|
|
205
|
+
)
|
|
206
|
+
: [
|
|
207
|
+
createDirectiveRemoval(
|
|
208
|
+
directives,
|
|
209
|
+
parentDirective.node,
|
|
210
|
+
sourceCode,
|
|
211
|
+
),
|
|
212
|
+
];
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Collect eslint-enable comments that are removing suppressions by eslint-disable comments.
|
|
218
|
+
* @param {Directive[]} directives The directives to check.
|
|
219
|
+
* @returns {Set<Directive>} The used eslint-enable comments
|
|
220
|
+
*/
|
|
221
|
+
function collectUsedEnableDirectives(directives) {
|
|
222
|
+
/**
|
|
223
|
+
* A Map of `eslint-enable` keyed by ruleIds that may be marked as used.
|
|
224
|
+
* If `eslint-enable` does not have a ruleId, the key will be `null`.
|
|
225
|
+
* @type {Map<string|null, Directive>}
|
|
226
|
+
*/
|
|
227
|
+
const enabledRules = new Map();
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* A Set of `eslint-enable` marked as used.
|
|
231
|
+
* It is also the return value of `collectUsedEnableDirectives` function.
|
|
232
|
+
* @type {Set<Directive>}
|
|
233
|
+
*/
|
|
234
|
+
const usedEnableDirectives = new Set();
|
|
235
|
+
|
|
236
|
+
/*
|
|
237
|
+
* Checks the directives backwards to see if the encountered `eslint-enable` is used by the previous `eslint-disable`,
|
|
238
|
+
* and if so, stores the `eslint-enable` in `usedEnableDirectives`.
|
|
239
|
+
*/
|
|
240
|
+
for (let index = directives.length - 1; index >= 0; index--) {
|
|
241
|
+
const directive = directives[index];
|
|
242
|
+
|
|
243
|
+
if (directive.type === "disable") {
|
|
244
|
+
if (enabledRules.size === 0) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (directive.ruleId === null) {
|
|
248
|
+
// If encounter `eslint-disable` without ruleId,
|
|
249
|
+
// mark all `eslint-enable` currently held in enabledRules as used.
|
|
250
|
+
// e.g.
|
|
251
|
+
// /* eslint-disable */ <- current directive
|
|
252
|
+
// /* eslint-enable rule-id1 */ <- used
|
|
253
|
+
// /* eslint-enable rule-id2 */ <- used
|
|
254
|
+
// /* eslint-enable */ <- used
|
|
255
|
+
for (const enableDirective of enabledRules.values()) {
|
|
256
|
+
usedEnableDirectives.add(enableDirective);
|
|
257
|
+
}
|
|
258
|
+
enabledRules.clear();
|
|
259
|
+
} else {
|
|
260
|
+
const enableDirective = enabledRules.get(directive.ruleId);
|
|
261
|
+
|
|
262
|
+
if (enableDirective) {
|
|
263
|
+
// If encounter `eslint-disable` with ruleId, and there is an `eslint-enable` with the same ruleId in enabledRules,
|
|
264
|
+
// mark `eslint-enable` with ruleId as used.
|
|
265
|
+
// e.g.
|
|
266
|
+
// /* eslint-disable rule-id */ <- current directive
|
|
267
|
+
// /* eslint-enable rule-id */ <- used
|
|
268
|
+
usedEnableDirectives.add(enableDirective);
|
|
269
|
+
} else {
|
|
270
|
+
const enabledDirectiveWithoutRuleId =
|
|
271
|
+
enabledRules.get(null);
|
|
272
|
+
|
|
273
|
+
if (enabledDirectiveWithoutRuleId) {
|
|
274
|
+
// If encounter `eslint-disable` with ruleId, and there is no `eslint-enable` with the same ruleId in enabledRules,
|
|
275
|
+
// mark `eslint-enable` without ruleId as used.
|
|
276
|
+
// e.g.
|
|
277
|
+
// /* eslint-disable rule-id */ <- current directive
|
|
278
|
+
// /* eslint-enable */ <- used
|
|
279
|
+
usedEnableDirectives.add(enabledDirectiveWithoutRuleId);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
} else if (directive.type === "enable") {
|
|
284
|
+
if (directive.ruleId === null) {
|
|
285
|
+
// If encounter `eslint-enable` without ruleId, the `eslint-enable` that follows it are unused.
|
|
286
|
+
// So clear enabledRules.
|
|
287
|
+
// e.g.
|
|
288
|
+
// /* eslint-enable */ <- current directive
|
|
289
|
+
// /* eslint-enable rule-id *// <- unused
|
|
290
|
+
// /* eslint-enable */ <- unused
|
|
291
|
+
enabledRules.clear();
|
|
292
|
+
enabledRules.set(null, directive);
|
|
293
|
+
} else {
|
|
294
|
+
enabledRules.set(directive.ruleId, directive);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return usedEnableDirectives;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* This is the same as the exported function, except that it
|
|
303
|
+
* doesn't handle disable-line and disable-next-line directives, and it always reports unused
|
|
304
|
+
* disable directives.
|
|
305
|
+
* @param {Object} options options for applying directives. This is the same as the options
|
|
306
|
+
* for the exported function, except that `reportUnusedDisableDirectives` is not supported
|
|
307
|
+
* (this function always reports unused disable directives).
|
|
308
|
+
* @returns {{problems: LintMessage[], unusedDirectives: LintMessage[]}} An object with a list
|
|
309
|
+
* of problems (including suppressed ones) and unused eslint-disable directives
|
|
310
|
+
*/
|
|
311
|
+
function applyDirectives(options) {
|
|
312
|
+
const problems = [];
|
|
313
|
+
const usedDisableDirectives = new Set();
|
|
314
|
+
const { sourceCode } = options;
|
|
315
|
+
|
|
316
|
+
for (const problem of options.problems) {
|
|
317
|
+
let disableDirectivesForProblem = [];
|
|
318
|
+
let nextDirectiveIndex = 0;
|
|
319
|
+
|
|
320
|
+
while (
|
|
321
|
+
nextDirectiveIndex < options.directives.length &&
|
|
322
|
+
compareLocations(options.directives[nextDirectiveIndex], problem) <=
|
|
323
|
+
0
|
|
324
|
+
) {
|
|
325
|
+
const directive = options.directives[nextDirectiveIndex++];
|
|
326
|
+
|
|
327
|
+
if (
|
|
328
|
+
directive.ruleId === null ||
|
|
329
|
+
directive.ruleId === problem.ruleId
|
|
330
|
+
) {
|
|
331
|
+
switch (directive.type) {
|
|
332
|
+
case "disable":
|
|
333
|
+
disableDirectivesForProblem.push(directive);
|
|
334
|
+
break;
|
|
335
|
+
|
|
336
|
+
case "enable":
|
|
337
|
+
disableDirectivesForProblem = [];
|
|
338
|
+
break;
|
|
339
|
+
|
|
340
|
+
// no default
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (disableDirectivesForProblem.length > 0) {
|
|
346
|
+
const suppressions = disableDirectivesForProblem.map(directive => ({
|
|
347
|
+
kind: "directive",
|
|
348
|
+
justification: directive.unprocessedDirective.justification,
|
|
349
|
+
}));
|
|
350
|
+
|
|
351
|
+
if (problem.suppressions) {
|
|
352
|
+
problem.suppressions =
|
|
353
|
+
problem.suppressions.concat(suppressions);
|
|
354
|
+
} else {
|
|
355
|
+
problem.suppressions = suppressions;
|
|
356
|
+
usedDisableDirectives.add(disableDirectivesForProblem.at(-1));
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
problems.push(problem);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const unusedDisableDirectivesToReport = options.directives.filter(
|
|
364
|
+
directive =>
|
|
365
|
+
directive.type === "disable" &&
|
|
366
|
+
!usedDisableDirectives.has(directive) &&
|
|
367
|
+
!options.rulesToIgnore.has(directive.ruleId),
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
const unusedEnableDirectivesToReport = new Set(
|
|
371
|
+
options.directives.filter(
|
|
372
|
+
directive =>
|
|
373
|
+
directive.unprocessedDirective.type === "enable" &&
|
|
374
|
+
!options.rulesToIgnore.has(directive.ruleId),
|
|
375
|
+
),
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
/*
|
|
379
|
+
* If directives has the eslint-enable directive,
|
|
380
|
+
* check whether the eslint-enable comment is used.
|
|
381
|
+
*/
|
|
382
|
+
if (unusedEnableDirectivesToReport.size > 0) {
|
|
383
|
+
for (const directive of collectUsedEnableDirectives(
|
|
384
|
+
options.directives,
|
|
385
|
+
)) {
|
|
386
|
+
unusedEnableDirectivesToReport.delete(directive);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const processed = processUnusedDirectives(
|
|
391
|
+
unusedDisableDirectivesToReport,
|
|
392
|
+
sourceCode,
|
|
393
|
+
).concat(
|
|
394
|
+
processUnusedDirectives(unusedEnableDirectivesToReport, sourceCode),
|
|
395
|
+
);
|
|
396
|
+
const columnOffset = options.language.columnStart === 1 ? 0 : 1;
|
|
397
|
+
const lineOffset = options.language.lineStart === 1 ? 0 : 1;
|
|
398
|
+
|
|
399
|
+
const unusedDirectives = processed.map(
|
|
400
|
+
({ description, fix, unprocessedDirective }) => {
|
|
401
|
+
const { parentDirective, type, line, column } =
|
|
402
|
+
unprocessedDirective;
|
|
403
|
+
|
|
404
|
+
let message;
|
|
405
|
+
|
|
406
|
+
if (type === "enable") {
|
|
407
|
+
message = description
|
|
408
|
+
? `Unused eslint-enable directive (no matching eslint-disable directives were found for ${description}).`
|
|
409
|
+
: "Unused eslint-enable directive (no matching eslint-disable directives were found).";
|
|
410
|
+
} else {
|
|
411
|
+
message = description
|
|
412
|
+
? `Unused eslint-disable directive (no problems were reported from ${description}).`
|
|
413
|
+
: "Unused eslint-disable directive (no problems were reported).";
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const loc = sourceCode.getLoc(parentDirective.node);
|
|
417
|
+
|
|
418
|
+
return {
|
|
419
|
+
ruleId: null,
|
|
420
|
+
message,
|
|
421
|
+
line:
|
|
422
|
+
type === "disable-next-line"
|
|
423
|
+
? loc.start.line + lineOffset
|
|
424
|
+
: line,
|
|
425
|
+
column:
|
|
426
|
+
type === "disable-next-line"
|
|
427
|
+
? loc.start.column + columnOffset
|
|
428
|
+
: column,
|
|
429
|
+
severity:
|
|
430
|
+
options.reportUnusedDisableDirectives === "warn" ? 1 : 2,
|
|
431
|
+
...(options.disableFixes ? {} : { fix }),
|
|
432
|
+
};
|
|
433
|
+
},
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
return { problems, unusedDirectives };
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Given a list of directive comments (i.e. metadata about eslint-disable and eslint-enable comments) and a list
|
|
441
|
+
* of reported problems, adds the suppression information to the problems.
|
|
442
|
+
* @param {Object} options Information about directives and problems
|
|
443
|
+
* @param {Language} options.language The language being linted.
|
|
444
|
+
* @param {SourceCode} options.sourceCode The source code object for the file being linted.
|
|
445
|
+
* @param {{
|
|
446
|
+
* type: ("disable"|"enable"|"disable-line"|"disable-next-line"),
|
|
447
|
+
* ruleId: (string|null),
|
|
448
|
+
* line: number,
|
|
449
|
+
* column: number,
|
|
450
|
+
* justification: string
|
|
451
|
+
* }} options.directives Directive comments found in the file, with one-based columns.
|
|
452
|
+
* Two directive comments can only have the same location if they also have the same type (e.g. a single eslint-disable
|
|
453
|
+
* comment for two different rules is represented as two directives).
|
|
454
|
+
* @param {{ruleId: (string|null), line: number, column: number}[]} options.problems
|
|
455
|
+
* A list of problems reported by rules, sorted by increasing location in the file, with one-based columns.
|
|
456
|
+
* @param {"off" | "warn" | "error"} options.reportUnusedDisableDirectives If `"warn"` or `"error"`, adds additional problems for unused directives
|
|
457
|
+
* @param {RulesConfig} options.configuredRules The rules configuration.
|
|
458
|
+
* @param {Function} options.ruleFilter A predicate function to filter which rules should be executed.
|
|
459
|
+
* @param {boolean} options.disableFixes If true, it doesn't make `fix` properties.
|
|
460
|
+
* @returns {{ruleId: (string|null), line: number, column: number, suppressions?: {kind: string, justification: string}}[]}
|
|
461
|
+
* An object with a list of reported problems, the suppressed of which contain the suppression information.
|
|
462
|
+
*/
|
|
463
|
+
module.exports = ({
|
|
464
|
+
language,
|
|
465
|
+
sourceCode,
|
|
466
|
+
directives,
|
|
467
|
+
disableFixes,
|
|
468
|
+
problems,
|
|
469
|
+
configuredRules,
|
|
470
|
+
ruleFilter,
|
|
471
|
+
reportUnusedDisableDirectives = "off",
|
|
472
|
+
}) => {
|
|
473
|
+
const blockDirectives = directives
|
|
474
|
+
.filter(
|
|
475
|
+
directive =>
|
|
476
|
+
directive.type === "disable" || directive.type === "enable",
|
|
477
|
+
)
|
|
478
|
+
.map(directive =>
|
|
479
|
+
Object.assign({}, directive, { unprocessedDirective: directive }),
|
|
480
|
+
)
|
|
481
|
+
.sort(compareLocations);
|
|
482
|
+
|
|
483
|
+
const lineDirectives = directives
|
|
484
|
+
.flatMap(directive => {
|
|
485
|
+
switch (directive.type) {
|
|
486
|
+
case "disable":
|
|
487
|
+
case "enable":
|
|
488
|
+
return [];
|
|
489
|
+
|
|
490
|
+
case "disable-line":
|
|
491
|
+
return [
|
|
492
|
+
{
|
|
493
|
+
type: "disable",
|
|
494
|
+
line: directive.line,
|
|
495
|
+
column: 1,
|
|
496
|
+
ruleId: directive.ruleId,
|
|
497
|
+
unprocessedDirective: directive,
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
type: "enable",
|
|
501
|
+
line: directive.line + 1,
|
|
502
|
+
column: 0,
|
|
503
|
+
ruleId: directive.ruleId,
|
|
504
|
+
unprocessedDirective: directive,
|
|
505
|
+
},
|
|
506
|
+
];
|
|
507
|
+
|
|
508
|
+
case "disable-next-line":
|
|
509
|
+
return [
|
|
510
|
+
{
|
|
511
|
+
type: "disable",
|
|
512
|
+
line: directive.line + 1,
|
|
513
|
+
column: 1,
|
|
514
|
+
ruleId: directive.ruleId,
|
|
515
|
+
unprocessedDirective: directive,
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
type: "enable",
|
|
519
|
+
line: directive.line + 2,
|
|
520
|
+
column: 0,
|
|
521
|
+
ruleId: directive.ruleId,
|
|
522
|
+
unprocessedDirective: directive,
|
|
523
|
+
},
|
|
524
|
+
];
|
|
525
|
+
|
|
526
|
+
default:
|
|
527
|
+
throw new TypeError(
|
|
528
|
+
`Unrecognized directive type '${directive.type}'`,
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
})
|
|
532
|
+
.sort(compareLocations);
|
|
533
|
+
|
|
534
|
+
// This determines a list of rules that are not being run by the given ruleFilter, if present.
|
|
535
|
+
const rulesToIgnore =
|
|
536
|
+
configuredRules && ruleFilter
|
|
537
|
+
? new Set(
|
|
538
|
+
Object.keys(configuredRules).filter(ruleId => {
|
|
539
|
+
const severity = Config.getRuleNumericSeverity(
|
|
540
|
+
configuredRules[ruleId],
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
// Ignore for disabled rules.
|
|
544
|
+
if (severity === 0) {
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
return !ruleFilter({ severity, ruleId });
|
|
549
|
+
}),
|
|
550
|
+
)
|
|
551
|
+
: new Set();
|
|
552
|
+
|
|
553
|
+
// If no ruleId is supplied that means this directive is applied to all rules, so we can't determine if it's unused if any rules are filtered out.
|
|
554
|
+
if (rulesToIgnore.size > 0) {
|
|
555
|
+
rulesToIgnore.add(null);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
const blockDirectivesResult = applyDirectives({
|
|
559
|
+
language,
|
|
560
|
+
sourceCode,
|
|
561
|
+
problems,
|
|
562
|
+
directives: blockDirectives,
|
|
563
|
+
disableFixes,
|
|
564
|
+
reportUnusedDisableDirectives,
|
|
565
|
+
rulesToIgnore,
|
|
566
|
+
});
|
|
567
|
+
const lineDirectivesResult = applyDirectives({
|
|
568
|
+
language,
|
|
569
|
+
sourceCode,
|
|
570
|
+
problems: blockDirectivesResult.problems,
|
|
571
|
+
directives: lineDirectives,
|
|
572
|
+
disableFixes,
|
|
573
|
+
reportUnusedDisableDirectives,
|
|
574
|
+
rulesToIgnore,
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
return reportUnusedDisableDirectives !== "off"
|
|
578
|
+
? lineDirectivesResult.problems
|
|
579
|
+
.concat(blockDirectivesResult.unusedDirectives)
|
|
580
|
+
.concat(lineDirectivesResult.unusedDirectives)
|
|
581
|
+
.sort(compareLocations)
|
|
582
|
+
: lineDirectivesResult.problems;
|
|
583
|
+
};
|