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,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Rule to control usage of strict mode directives.
|
|
3
|
+
* @author Brandon Mills
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
// Requirements
|
|
10
|
+
//------------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
|
13
|
+
|
|
14
|
+
//------------------------------------------------------------------------------
|
|
15
|
+
// Helpers
|
|
16
|
+
//------------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gets all of the Use Strict Directives in the Directive Prologue of a group of
|
|
20
|
+
* statements.
|
|
21
|
+
* @param {ASTNode[]} statements Statements in the program or function body.
|
|
22
|
+
* @returns {ASTNode[]} All of the Use Strict Directives.
|
|
23
|
+
*/
|
|
24
|
+
function getUseStrictDirectives(statements) {
|
|
25
|
+
const directives = [];
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < statements.length; i++) {
|
|
28
|
+
const statement = statements[i];
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
statement.type === "ExpressionStatement" &&
|
|
32
|
+
statement.expression.type === "Literal" &&
|
|
33
|
+
statement.expression.value === "use strict"
|
|
34
|
+
) {
|
|
35
|
+
directives[i] = statement;
|
|
36
|
+
} else {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return directives;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Checks whether a given parameter is a simple parameter.
|
|
46
|
+
* @param {ASTNode} node A pattern node to check.
|
|
47
|
+
* @returns {boolean} `true` if the node is an Identifier node.
|
|
48
|
+
*/
|
|
49
|
+
function isSimpleParameter(node) {
|
|
50
|
+
return node.type === "Identifier";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Checks whether a given parameter list is a simple parameter list.
|
|
55
|
+
* @param {ASTNode[]} params A parameter list to check.
|
|
56
|
+
* @returns {boolean} `true` if the every parameter is an Identifier node.
|
|
57
|
+
*/
|
|
58
|
+
function isSimpleParameterList(params) {
|
|
59
|
+
return params.every(isSimpleParameter);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//------------------------------------------------------------------------------
|
|
63
|
+
// Rule Definition
|
|
64
|
+
//------------------------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
67
|
+
module.exports = {
|
|
68
|
+
meta: {
|
|
69
|
+
type: "suggestion",
|
|
70
|
+
|
|
71
|
+
defaultOptions: ["safe"],
|
|
72
|
+
|
|
73
|
+
docs: {
|
|
74
|
+
description: "Require or disallow strict mode directives",
|
|
75
|
+
recommended: false,
|
|
76
|
+
url: "https://eslint.org/docs/latest/rules/strict",
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
schema: [
|
|
80
|
+
{
|
|
81
|
+
enum: ["never", "global", "function", "safe"],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
|
|
85
|
+
fixable: "code",
|
|
86
|
+
messages: {
|
|
87
|
+
function: "Use the function form of 'use strict'.",
|
|
88
|
+
global: "Use the global form of 'use strict'.",
|
|
89
|
+
multiple: "Multiple 'use strict' directives.",
|
|
90
|
+
never: "Strict mode is not permitted.",
|
|
91
|
+
unnecessary: "Unnecessary 'use strict' directive.",
|
|
92
|
+
module: "'use strict' is unnecessary inside of modules.",
|
|
93
|
+
implied:
|
|
94
|
+
"'use strict' is unnecessary when implied strict mode is enabled.",
|
|
95
|
+
unnecessaryInClasses:
|
|
96
|
+
"'use strict' is unnecessary inside of classes.",
|
|
97
|
+
nonSimpleParameterList:
|
|
98
|
+
"'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016.",
|
|
99
|
+
wrap: "Wrap {{name}} in a function with 'use strict' directive.",
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
create(context) {
|
|
104
|
+
const ecmaFeatures =
|
|
105
|
+
context.languageOptions.parserOptions.ecmaFeatures || {},
|
|
106
|
+
scopes = [],
|
|
107
|
+
classScopes = [];
|
|
108
|
+
let [mode] = context.options;
|
|
109
|
+
|
|
110
|
+
if (ecmaFeatures.impliedStrict) {
|
|
111
|
+
mode = "implied";
|
|
112
|
+
} else if (mode === "safe") {
|
|
113
|
+
mode =
|
|
114
|
+
ecmaFeatures.globalReturn ||
|
|
115
|
+
context.languageOptions.sourceType === "commonjs"
|
|
116
|
+
? "global"
|
|
117
|
+
: "function";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Determines whether a reported error should be fixed, depending on the error type.
|
|
122
|
+
* @param {string} errorType The type of error
|
|
123
|
+
* @returns {boolean} `true` if the reported error should be fixed
|
|
124
|
+
*/
|
|
125
|
+
function shouldFix(errorType) {
|
|
126
|
+
return (
|
|
127
|
+
errorType === "multiple" ||
|
|
128
|
+
errorType === "unnecessary" ||
|
|
129
|
+
errorType === "module" ||
|
|
130
|
+
errorType === "implied" ||
|
|
131
|
+
errorType === "unnecessaryInClasses"
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Gets a fixer function to remove a given 'use strict' directive.
|
|
137
|
+
* @param {ASTNode} node The directive that should be removed
|
|
138
|
+
* @returns {Function} A fixer function
|
|
139
|
+
*/
|
|
140
|
+
function getFixFunction(node) {
|
|
141
|
+
return fixer => fixer.remove(node);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Report a slice of an array of nodes with a given message.
|
|
146
|
+
* @param {ASTNode[]} nodes Nodes.
|
|
147
|
+
* @param {string} start Index to start from.
|
|
148
|
+
* @param {string} end Index to end before.
|
|
149
|
+
* @param {string} messageId Message to display.
|
|
150
|
+
* @param {boolean} fix `true` if the directive should be fixed (i.e. removed)
|
|
151
|
+
* @returns {void}
|
|
152
|
+
*/
|
|
153
|
+
function reportSlice(nodes, start, end, messageId, fix) {
|
|
154
|
+
nodes.slice(start, end).forEach(node => {
|
|
155
|
+
context.report({
|
|
156
|
+
node,
|
|
157
|
+
messageId,
|
|
158
|
+
fix: fix ? getFixFunction(node) : null,
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Report all nodes in an array with a given message.
|
|
165
|
+
* @param {ASTNode[]} nodes Nodes.
|
|
166
|
+
* @param {string} messageId Message id to display.
|
|
167
|
+
* @param {boolean} fix `true` if the directive should be fixed (i.e. removed)
|
|
168
|
+
* @returns {void}
|
|
169
|
+
*/
|
|
170
|
+
function reportAll(nodes, messageId, fix) {
|
|
171
|
+
reportSlice(nodes, 0, nodes.length, messageId, fix);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Report all nodes in an array, except the first, with a given message.
|
|
176
|
+
* @param {ASTNode[]} nodes Nodes.
|
|
177
|
+
* @param {string} messageId Message id to display.
|
|
178
|
+
* @param {boolean} fix `true` if the directive should be fixed (i.e. removed)
|
|
179
|
+
* @returns {void}
|
|
180
|
+
*/
|
|
181
|
+
function reportAllExceptFirst(nodes, messageId, fix) {
|
|
182
|
+
reportSlice(nodes, 1, nodes.length, messageId, fix);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Entering a function in 'function' mode pushes a new nested scope onto the
|
|
187
|
+
* stack. The new scope is true if the nested function is strict mode code.
|
|
188
|
+
* @param {ASTNode} node The function declaration or expression.
|
|
189
|
+
* @param {ASTNode[]} useStrictDirectives The Use Strict Directives of the node.
|
|
190
|
+
* @returns {void}
|
|
191
|
+
*/
|
|
192
|
+
function enterFunctionInFunctionMode(node, useStrictDirectives) {
|
|
193
|
+
const isInClass = classScopes.length > 0,
|
|
194
|
+
isParentGlobal =
|
|
195
|
+
scopes.length === 0 && classScopes.length === 0,
|
|
196
|
+
isParentStrict = scopes.length > 0 && scopes.at(-1),
|
|
197
|
+
isStrict = useStrictDirectives.length > 0;
|
|
198
|
+
|
|
199
|
+
if (isStrict) {
|
|
200
|
+
if (!isSimpleParameterList(node.params)) {
|
|
201
|
+
context.report({
|
|
202
|
+
node: useStrictDirectives[0],
|
|
203
|
+
messageId: "nonSimpleParameterList",
|
|
204
|
+
});
|
|
205
|
+
} else if (isParentStrict) {
|
|
206
|
+
context.report({
|
|
207
|
+
node: useStrictDirectives[0],
|
|
208
|
+
messageId: "unnecessary",
|
|
209
|
+
fix: getFixFunction(useStrictDirectives[0]),
|
|
210
|
+
});
|
|
211
|
+
} else if (isInClass) {
|
|
212
|
+
context.report({
|
|
213
|
+
node: useStrictDirectives[0],
|
|
214
|
+
messageId: "unnecessaryInClasses",
|
|
215
|
+
fix: getFixFunction(useStrictDirectives[0]),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
reportAllExceptFirst(useStrictDirectives, "multiple", true);
|
|
220
|
+
} else if (isParentGlobal) {
|
|
221
|
+
if (isSimpleParameterList(node.params)) {
|
|
222
|
+
context.report({ node, messageId: "function" });
|
|
223
|
+
} else {
|
|
224
|
+
context.report({
|
|
225
|
+
node,
|
|
226
|
+
messageId: "wrap",
|
|
227
|
+
data: { name: astUtils.getFunctionNameWithKind(node) },
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
scopes.push(isParentStrict || isStrict);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Exiting a function in 'function' mode pops its scope off the stack.
|
|
237
|
+
* @returns {void}
|
|
238
|
+
*/
|
|
239
|
+
function exitFunctionInFunctionMode() {
|
|
240
|
+
scopes.pop();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Enter a function and either:
|
|
245
|
+
* - Push a new nested scope onto the stack (in 'function' mode).
|
|
246
|
+
* - Report all the Use Strict Directives (in the other modes).
|
|
247
|
+
* @param {ASTNode} node The function declaration or expression.
|
|
248
|
+
* @returns {void}
|
|
249
|
+
*/
|
|
250
|
+
function enterFunction(node) {
|
|
251
|
+
const isBlock = node.body.type === "BlockStatement",
|
|
252
|
+
useStrictDirectives = isBlock
|
|
253
|
+
? getUseStrictDirectives(node.body.body)
|
|
254
|
+
: [];
|
|
255
|
+
|
|
256
|
+
if (mode === "function") {
|
|
257
|
+
enterFunctionInFunctionMode(node, useStrictDirectives);
|
|
258
|
+
} else if (useStrictDirectives.length > 0) {
|
|
259
|
+
if (isSimpleParameterList(node.params)) {
|
|
260
|
+
reportAll(useStrictDirectives, mode, shouldFix(mode));
|
|
261
|
+
} else {
|
|
262
|
+
context.report({
|
|
263
|
+
node: useStrictDirectives[0],
|
|
264
|
+
messageId: "nonSimpleParameterList",
|
|
265
|
+
});
|
|
266
|
+
reportAllExceptFirst(useStrictDirectives, "multiple", true);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const rule = {
|
|
272
|
+
Program(node) {
|
|
273
|
+
const useStrictDirectives = getUseStrictDirectives(node.body);
|
|
274
|
+
|
|
275
|
+
if (node.sourceType === "module") {
|
|
276
|
+
mode = "module";
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (mode === "global") {
|
|
280
|
+
if (
|
|
281
|
+
node.body.length > 0 &&
|
|
282
|
+
useStrictDirectives.length === 0
|
|
283
|
+
) {
|
|
284
|
+
context.report({ node, messageId: "global" });
|
|
285
|
+
}
|
|
286
|
+
reportAllExceptFirst(useStrictDirectives, "multiple", true);
|
|
287
|
+
} else {
|
|
288
|
+
reportAll(useStrictDirectives, mode, shouldFix(mode));
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
FunctionDeclaration: enterFunction,
|
|
292
|
+
FunctionExpression: enterFunction,
|
|
293
|
+
ArrowFunctionExpression: enterFunction,
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
if (mode === "function") {
|
|
297
|
+
Object.assign(rule, {
|
|
298
|
+
// Inside of class bodies are always strict mode.
|
|
299
|
+
ClassBody() {
|
|
300
|
+
classScopes.push(true);
|
|
301
|
+
},
|
|
302
|
+
"ClassBody:exit"() {
|
|
303
|
+
classScopes.pop();
|
|
304
|
+
},
|
|
305
|
+
|
|
306
|
+
"FunctionDeclaration:exit": exitFunctionInFunctionMode,
|
|
307
|
+
"FunctionExpression:exit": exitFunctionInFunctionMode,
|
|
308
|
+
"ArrowFunctionExpression:exit": exitFunctionInFunctionMode,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return rule;
|
|
313
|
+
},
|
|
314
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Rule to enforce spacing around colons of switch statements.
|
|
3
|
+
* @author Toru Nagashima
|
|
4
|
+
* @deprecated in ESLint v8.53.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
// Requirements
|
|
11
|
+
//------------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
const astUtils = require("./utils/ast-utils");
|
|
14
|
+
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
// Rule Definition
|
|
17
|
+
//------------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
20
|
+
module.exports = {
|
|
21
|
+
meta: {
|
|
22
|
+
deprecated: {
|
|
23
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
24
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
25
|
+
deprecatedSince: "8.53.0",
|
|
26
|
+
availableUntil: "11.0.0",
|
|
27
|
+
replacedBy: [
|
|
28
|
+
{
|
|
29
|
+
message:
|
|
30
|
+
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
31
|
+
url: "https://eslint.style/guide/migration",
|
|
32
|
+
plugin: {
|
|
33
|
+
name: "@stylistic/eslint-plugin",
|
|
34
|
+
url: "https://eslint.style",
|
|
35
|
+
},
|
|
36
|
+
rule: {
|
|
37
|
+
name: "switch-colon-spacing",
|
|
38
|
+
url: "https://eslint.style/rules/switch-colon-spacing",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
type: "layout",
|
|
44
|
+
|
|
45
|
+
docs: {
|
|
46
|
+
description: "Enforce spacing around colons of switch statements",
|
|
47
|
+
recommended: false,
|
|
48
|
+
url: "https://eslint.org/docs/latest/rules/switch-colon-spacing",
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
schema: [
|
|
52
|
+
{
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: {
|
|
55
|
+
before: { type: "boolean", default: false },
|
|
56
|
+
after: { type: "boolean", default: true },
|
|
57
|
+
},
|
|
58
|
+
additionalProperties: false,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
fixable: "whitespace",
|
|
62
|
+
messages: {
|
|
63
|
+
expectedBefore: "Expected space(s) before this colon.",
|
|
64
|
+
expectedAfter: "Expected space(s) after this colon.",
|
|
65
|
+
unexpectedBefore: "Unexpected space(s) before this colon.",
|
|
66
|
+
unexpectedAfter: "Unexpected space(s) after this colon.",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
create(context) {
|
|
71
|
+
const sourceCode = context.sourceCode;
|
|
72
|
+
const options = context.options[0] || {};
|
|
73
|
+
const beforeSpacing = options.before === true; // false by default
|
|
74
|
+
const afterSpacing = options.after !== false; // true by default
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Check whether the spacing between the given 2 tokens is valid or not.
|
|
78
|
+
* @param {Token} left The left token to check.
|
|
79
|
+
* @param {Token} right The right token to check.
|
|
80
|
+
* @param {boolean} expected The expected spacing to check. `true` if there should be a space.
|
|
81
|
+
* @returns {boolean} `true` if the spacing between the tokens is valid.
|
|
82
|
+
*/
|
|
83
|
+
function isValidSpacing(left, right, expected) {
|
|
84
|
+
return (
|
|
85
|
+
astUtils.isClosingBraceToken(right) ||
|
|
86
|
+
!astUtils.isTokenOnSameLine(left, right) ||
|
|
87
|
+
sourceCode.isSpaceBetween(left, right) === expected
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Check whether comments exist between the given 2 tokens.
|
|
93
|
+
* @param {Token} left The left token to check.
|
|
94
|
+
* @param {Token} right The right token to check.
|
|
95
|
+
* @returns {boolean} `true` if comments exist between the given 2 tokens.
|
|
96
|
+
*/
|
|
97
|
+
function commentsExistBetween(left, right) {
|
|
98
|
+
return (
|
|
99
|
+
sourceCode.getFirstTokenBetween(left, right, {
|
|
100
|
+
includeComments: true,
|
|
101
|
+
filter: astUtils.isCommentToken,
|
|
102
|
+
}) !== null
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Fix the spacing between the given 2 tokens.
|
|
108
|
+
* @param {RuleFixer} fixer The fixer to fix.
|
|
109
|
+
* @param {Token} left The left token of fix range.
|
|
110
|
+
* @param {Token} right The right token of fix range.
|
|
111
|
+
* @param {boolean} spacing The spacing style. `true` if there should be a space.
|
|
112
|
+
* @returns {Fix|null} The fix object.
|
|
113
|
+
*/
|
|
114
|
+
function fix(fixer, left, right, spacing) {
|
|
115
|
+
if (commentsExistBetween(left, right)) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (spacing) {
|
|
119
|
+
return fixer.insertTextAfter(left, " ");
|
|
120
|
+
}
|
|
121
|
+
return fixer.removeRange([left.range[1], right.range[0]]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
SwitchCase(node) {
|
|
126
|
+
const colonToken = astUtils.getSwitchCaseColonToken(
|
|
127
|
+
node,
|
|
128
|
+
sourceCode,
|
|
129
|
+
);
|
|
130
|
+
const beforeToken = sourceCode.getTokenBefore(colonToken);
|
|
131
|
+
const afterToken = sourceCode.getTokenAfter(colonToken);
|
|
132
|
+
|
|
133
|
+
if (!isValidSpacing(beforeToken, colonToken, beforeSpacing)) {
|
|
134
|
+
context.report({
|
|
135
|
+
node,
|
|
136
|
+
loc: colonToken.loc,
|
|
137
|
+
messageId: beforeSpacing
|
|
138
|
+
? "expectedBefore"
|
|
139
|
+
: "unexpectedBefore",
|
|
140
|
+
fix: fixer =>
|
|
141
|
+
fix(fixer, beforeToken, colonToken, beforeSpacing),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (!isValidSpacing(colonToken, afterToken, afterSpacing)) {
|
|
145
|
+
context.report({
|
|
146
|
+
node,
|
|
147
|
+
loc: colonToken.loc,
|
|
148
|
+
messageId: afterSpacing
|
|
149
|
+
? "expectedAfter"
|
|
150
|
+
: "unexpectedAfter",
|
|
151
|
+
fix: fixer =>
|
|
152
|
+
fix(fixer, colonToken, afterToken, afterSpacing),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Rule to enforce description with the `Symbol` object
|
|
3
|
+
* @author Jarek Rencz
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
// Requirements
|
|
10
|
+
//------------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
|
13
|
+
|
|
14
|
+
//------------------------------------------------------------------------------
|
|
15
|
+
// Rule Definition
|
|
16
|
+
//------------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
19
|
+
module.exports = {
|
|
20
|
+
meta: {
|
|
21
|
+
type: "suggestion",
|
|
22
|
+
|
|
23
|
+
docs: {
|
|
24
|
+
description: "Require symbol descriptions",
|
|
25
|
+
recommended: false,
|
|
26
|
+
url: "https://eslint.org/docs/latest/rules/symbol-description",
|
|
27
|
+
},
|
|
28
|
+
fixable: null,
|
|
29
|
+
schema: [],
|
|
30
|
+
messages: {
|
|
31
|
+
expected: "Expected Symbol to have a description.",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
create(context) {
|
|
36
|
+
const sourceCode = context.sourceCode;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Reports if node does not conform the rule in case rule is set to
|
|
40
|
+
* report missing description
|
|
41
|
+
* @param {ASTNode} node A CallExpression node to check.
|
|
42
|
+
* @returns {void}
|
|
43
|
+
*/
|
|
44
|
+
function checkArgument(node) {
|
|
45
|
+
if (node.arguments.length === 0) {
|
|
46
|
+
context.report({
|
|
47
|
+
node,
|
|
48
|
+
messageId: "expected",
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
"Program:exit"(node) {
|
|
55
|
+
const scope = sourceCode.getScope(node);
|
|
56
|
+
const variable = astUtils.getVariableByName(scope, "Symbol");
|
|
57
|
+
|
|
58
|
+
if (variable && variable.defs.length === 0) {
|
|
59
|
+
variable.references.forEach(reference => {
|
|
60
|
+
const idNode = reference.identifier;
|
|
61
|
+
|
|
62
|
+
if (astUtils.isCallee(idNode)) {
|
|
63
|
+
checkArgument(idNode.parent);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Rule to enforce spacing around embedded expressions of template strings
|
|
3
|
+
* @author Toru Nagashima
|
|
4
|
+
* @deprecated in ESLint v8.53.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
// Requirements
|
|
11
|
+
//------------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
const astUtils = require("./utils/ast-utils");
|
|
14
|
+
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
// Rule Definition
|
|
17
|
+
//------------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
/** @type {import('../types').Rule.RuleModule} */
|
|
20
|
+
module.exports = {
|
|
21
|
+
meta: {
|
|
22
|
+
deprecated: {
|
|
23
|
+
message: "Formatting rules are being moved out of ESLint core.",
|
|
24
|
+
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
25
|
+
deprecatedSince: "8.53.0",
|
|
26
|
+
availableUntil: "11.0.0",
|
|
27
|
+
replacedBy: [
|
|
28
|
+
{
|
|
29
|
+
message:
|
|
30
|
+
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
31
|
+
url: "https://eslint.style/guide/migration",
|
|
32
|
+
plugin: {
|
|
33
|
+
name: "@stylistic/eslint-plugin",
|
|
34
|
+
url: "https://eslint.style",
|
|
35
|
+
},
|
|
36
|
+
rule: {
|
|
37
|
+
name: "template-curly-spacing",
|
|
38
|
+
url: "https://eslint.style/rules/template-curly-spacing",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
type: "layout",
|
|
44
|
+
|
|
45
|
+
docs: {
|
|
46
|
+
description:
|
|
47
|
+
"Require or disallow spacing around embedded expressions of template strings",
|
|
48
|
+
recommended: false,
|
|
49
|
+
url: "https://eslint.org/docs/latest/rules/template-curly-spacing",
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
fixable: "whitespace",
|
|
53
|
+
|
|
54
|
+
schema: [{ enum: ["always", "never"] }],
|
|
55
|
+
messages: {
|
|
56
|
+
expectedBefore: "Expected space(s) before '}'.",
|
|
57
|
+
expectedAfter: "Expected space(s) after '${'.",
|
|
58
|
+
unexpectedBefore: "Unexpected space(s) before '}'.",
|
|
59
|
+
unexpectedAfter: "Unexpected space(s) after '${'.",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
create(context) {
|
|
64
|
+
const sourceCode = context.sourceCode;
|
|
65
|
+
const always = context.options[0] === "always";
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Checks spacing before `}` of a given token.
|
|
69
|
+
* @param {Token} token A token to check. This is a Template token.
|
|
70
|
+
* @returns {void}
|
|
71
|
+
*/
|
|
72
|
+
function checkSpacingBefore(token) {
|
|
73
|
+
if (!token.value.startsWith("}")) {
|
|
74
|
+
return; // starts with a backtick, this is the first template element in the template literal
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const prevToken = sourceCode.getTokenBefore(token, {
|
|
78
|
+
includeComments: true,
|
|
79
|
+
}),
|
|
80
|
+
hasSpace = sourceCode.isSpaceBetween(prevToken, token);
|
|
81
|
+
|
|
82
|
+
if (!astUtils.isTokenOnSameLine(prevToken, token)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (always && !hasSpace) {
|
|
87
|
+
context.report({
|
|
88
|
+
loc: {
|
|
89
|
+
start: token.loc.start,
|
|
90
|
+
end: {
|
|
91
|
+
line: token.loc.start.line,
|
|
92
|
+
column: token.loc.start.column + 1,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
messageId: "expectedBefore",
|
|
96
|
+
fix: fixer => fixer.insertTextBefore(token, " "),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!always && hasSpace) {
|
|
101
|
+
context.report({
|
|
102
|
+
loc: {
|
|
103
|
+
start: prevToken.loc.end,
|
|
104
|
+
end: token.loc.start,
|
|
105
|
+
},
|
|
106
|
+
messageId: "unexpectedBefore",
|
|
107
|
+
fix: fixer =>
|
|
108
|
+
fixer.removeRange([prevToken.range[1], token.range[0]]),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Checks spacing after `${` of a given token.
|
|
115
|
+
* @param {Token} token A token to check. This is a Template token.
|
|
116
|
+
* @returns {void}
|
|
117
|
+
*/
|
|
118
|
+
function checkSpacingAfter(token) {
|
|
119
|
+
if (!token.value.endsWith("${")) {
|
|
120
|
+
return; // ends with a backtick, this is the last template element in the template literal
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const nextToken = sourceCode.getTokenAfter(token, {
|
|
124
|
+
includeComments: true,
|
|
125
|
+
}),
|
|
126
|
+
hasSpace = sourceCode.isSpaceBetween(token, nextToken);
|
|
127
|
+
|
|
128
|
+
if (!astUtils.isTokenOnSameLine(token, nextToken)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (always && !hasSpace) {
|
|
133
|
+
context.report({
|
|
134
|
+
loc: {
|
|
135
|
+
start: {
|
|
136
|
+
line: token.loc.end.line,
|
|
137
|
+
column: token.loc.end.column - 2,
|
|
138
|
+
},
|
|
139
|
+
end: token.loc.end,
|
|
140
|
+
},
|
|
141
|
+
messageId: "expectedAfter",
|
|
142
|
+
fix: fixer => fixer.insertTextAfter(token, " "),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!always && hasSpace) {
|
|
147
|
+
context.report({
|
|
148
|
+
loc: {
|
|
149
|
+
start: token.loc.end,
|
|
150
|
+
end: nextToken.loc.start,
|
|
151
|
+
},
|
|
152
|
+
messageId: "unexpectedAfter",
|
|
153
|
+
fix: fixer =>
|
|
154
|
+
fixer.removeRange([token.range[1], nextToken.range[0]]),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
TemplateElement(node) {
|
|
161
|
+
const token = sourceCode.getFirstToken(node);
|
|
162
|
+
|
|
163
|
+
checkSpacingBefore(token);
|
|
164
|
+
checkSpacingAfter(token);
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
};
|