@alexlit/lint-kit 174.0.0 → 176.0.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/package.json +1 -1
- package/packages/config-eslint/node_modules/@eslint/core/LICENSE +201 -0
- package/packages/config-eslint/node_modules/@eslint/core/README.md +29 -0
- package/packages/config-eslint/node_modules/@eslint/core/dist/cjs/types.d.cts +1179 -0
- package/packages/config-eslint/node_modules/@eslint/core/dist/esm/types.d.ts +1179 -0
- package/packages/config-eslint/node_modules/@eslint/core/package.json +49 -0
- package/packages/config-eslint/node_modules/@eslint/plugin-kit/LICENSE +201 -0
- package/packages/config-eslint/node_modules/@eslint/plugin-kit/README.md +273 -0
- package/packages/config-eslint/node_modules/@eslint/plugin-kit/dist/cjs/index.cjs +884 -0
- package/packages/config-eslint/node_modules/@eslint/plugin-kit/dist/cjs/index.d.cts +328 -0
- package/packages/config-eslint/node_modules/@eslint/plugin-kit/dist/cjs/types.cts +7 -0
- package/packages/config-eslint/node_modules/@eslint/plugin-kit/dist/esm/index.d.ts +328 -0
- package/packages/config-eslint/node_modules/@eslint/plugin-kit/dist/esm/index.js +879 -0
- package/packages/config-eslint/node_modules/@eslint/plugin-kit/dist/esm/types.d.ts +6 -0
- package/packages/config-eslint/node_modules/@eslint/plugin-kit/dist/esm/types.ts +7 -0
- package/packages/config-eslint/node_modules/@eslint/plugin-kit/package.json +61 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/configs/flat-config-base.js +9 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/index.d.ts +17 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/index.js +91 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/license +9 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/node_modules/globals/globals.json +3345 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/node_modules/globals/index.d.ts +3452 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/node_modules/globals/index.js +2 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/node_modules/globals/license +9 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/node_modules/globals/package.json +117 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/node_modules/globals/readme.md +42 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/package.json +128 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/readme.md +261 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/call-or-new-expression.js +120 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/function-types.js +7 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/index.js +30 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-arrow-function-body.js +3 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-directive.js +4 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-empty-array-expression.js +5 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-empty-node.js +17 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-expression-statement.js +7 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-function.js +5 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-member-expression.js +98 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-method-call.js +62 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-negative-one.js +8 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-reference-identifier.js +159 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-static-require.js +10 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-tagged-template-literal.js +24 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/is-undefined.js +3 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/ast/literal.js +24 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/better-regex.js +146 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/catch-error-name.js +138 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/consistent-assert.js +98 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/consistent-date-clone.js +54 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/consistent-destructuring.js +168 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/consistent-empty-array-spread.js +127 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/consistent-existence-index-check.js +137 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/consistent-function-scoping.js +265 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/custom-error-definition.js +218 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/empty-brace-spaces.js +62 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/error-message.js +98 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/escape-case.js +86 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/expiring-todo-comments.js +584 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/explicit-length-check.js +236 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/filename-case.js +276 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/add-parenthesizes-to-return-or-throw-expression.js +29 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/append-argument.js +30 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/extend-fix-range.js +11 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/fix-space-around-keywords.js +43 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/index.js +23 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/remove-argument.js +40 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/remove-expression-statement.js +34 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/remove-method-call.js +28 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/remove-object-property.js +21 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/remove-parentheses.js +19 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/remove-spaces-after.js +22 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/remove-specifier.js +59 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/rename-variable.js +8 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/replace-argument.js +17 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/replace-member-expression-property.js +25 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/replace-node-or-token-and-spaces-before.js +31 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/replace-reference-identifier.js +32 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/replace-string-raw.js +12 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/replace-template-element.js +10 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/switch-call-expression-to-new-expression.js +29 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/fix/switch-new-expression-to-call-expression.js +42 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/import-style.js +375 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/index.js +143 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/new-for-builtins.js +112 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-abusive-eslint-disable.js +63 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-accessor-recursion.js +160 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-anonymous-default-export.js +210 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-array-callback-reference.js +285 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-array-for-each.js +496 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-array-method-this-argument.js +223 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-array-reduce.js +128 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-array-reverse.js +6 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-array-sort.js +6 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-await-expression-member.js +85 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-await-in-promise-methods.js +69 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-console-spaces.js +89 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-document-cookie.js +27 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-empty-file.js +58 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-for-loop.js +419 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-hex-escape.js +54 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-immediate-mutation.js +778 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-instanceof-builtins.js +216 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-invalid-fetch-options.js +112 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-invalid-remove-event-listener.js +61 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-keyword-prefix.js +202 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-lonely-if.js +155 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-magic-array-flat-depth.js +55 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-named-default.js +101 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-negated-condition.js +145 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-negation-in-equality-check.js +99 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-nested-ternary.js +60 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-new-array.js +106 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-new-buffer.js +100 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-null.js +153 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-object-as-default-parameter.js +52 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-process-exit.js +106 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-single-promise-in-promise-methods.js +179 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-static-only-class.js +226 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-thenable.js +194 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-this-assignment.js +40 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-typeof-undefined.js +146 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-unnecessary-array-flat-depth.js +49 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-unnecessary-array-splice-count.js +23 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-unnecessary-await.js +110 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-unnecessary-polyfills.js +174 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-unnecessary-slice-end.js +22 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-unreadable-array-destructuring.js +85 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-unreadable-iife.js +43 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-unused-properties.js +240 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-useless-collection-argument.js +101 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-useless-error-capture-stack-trace.js +146 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-useless-fallback-in-spread.js +66 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-useless-length-check.js +150 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-useless-promise-resolve-reject.js +210 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-useless-spread.js +389 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-useless-switch-case.js +59 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-useless-undefined.js +275 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/no-zero-fractions.js +81 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/number-literal-case.js +82 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/numeric-separators-style.js +189 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-add-event-listener.js +191 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-array-find.js +458 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-array-flat-map.js +86 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-array-flat.js +279 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-array-index-of.js +34 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-array-some.js +219 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-at.js +380 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-bigint-literals.js +129 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-blob-reading-methods.js +47 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-class-fields.js +158 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-classlist-toggle.js +255 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-code-point.js +56 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-date-now.js +133 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-default-parameters.js +218 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-dom-node-append.js +50 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-dom-node-dataset.js +135 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-dom-node-remove.js +124 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-dom-node-text-content.js +77 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-event-target.js +119 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-export-from.js +367 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-global-this.js +222 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-import-meta-properties.js +320 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-includes.js +111 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-json-parse-buffer.js +161 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-keyboard-event-key.js +188 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-logical-operator-over-ternary.js +162 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-math-min-max.js +205 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-math-trunc.js +111 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-modern-dom-apis.js +145 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-modern-math-apis.js +210 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-module.js +377 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-native-coercion-functions.js +187 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-negative-index.js +211 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-node-protocol.js +86 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-number-properties.js +142 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-object-from-entries.js +256 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-optional-catch-binding.js +77 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-prototype-methods.js +162 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-query-selector.js +170 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-reflect-apply.js +99 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-regexp-test.js +155 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-response-static-json.js +85 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-set-has.js +181 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-set-size.js +106 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-single-call.js +188 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-spread.js +521 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-string-raw.js +149 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-string-replace-all.js +180 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-string-slice.js +180 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-string-starts-ends-with.js +201 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-string-trim-start-end.js +46 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-structured-clone.js +149 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-switch.js +357 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-ternary.js +288 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-top-level-await.js +154 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-type-error.js +169 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prevent-abbreviations.js +655 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/relative-url-style.js +171 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/require-array-join-separator.js +65 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/require-module-attributes.js +120 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/require-module-specifiers.js +158 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/require-number-to-fixed-digits-argument.js +55 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/require-post-message-target-origin.js +74 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/get-documentation-url.js +9 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/index.js +9 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/to-eslint-create.js +51 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/to-eslint-listener.js +40 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/to-eslint-problem.js +38 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/to-eslint-rule-fixer.js +49 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/to-eslint-rule.js +38 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/to-eslint-rules.js +13 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/unicorn-context.js +36 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/unicorn-listeners.js +65 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/rule/utilities.js +27 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/shared/abbreviations.js +270 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/shared/builtin-errors.js +14 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/shared/dom-events.js +275 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/shared/event-keys.js +54 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/shared/negative-index.js +52 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/shared/no-array-mutate-rule.js +139 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/shared/no-unnecessary-length-or-infinity-rule.js +80 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/shared/package-json.js +42 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/shared/simple-array-search-rule.js +126 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/shared/typed-array.js +17 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/string-content.js +192 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/switch-case-braces.js +114 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/template-indent.js +219 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/text-encoding-identifier-case.js +130 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/throw-new-error.js +60 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/array-or-object-prototype-property.js +57 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/assert-token.js +29 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/boolean.js +88 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/builtins.js +30 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/cartesian-product-samples.js +22 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/create-deprecated-rules.js +29 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/escape-string.js +24 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/escape-template-element-raw.js +6 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-ancestor.js +15 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-available-variable-name.js +147 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-builtin-rule.js +5 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-call-expression-arguments-text.js +36 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-call-or-new-expression-tokens.js +67 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-class-head-location.js +22 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-documentation-url.js +9 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-indent-string.js +18 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-references.js +5 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-scopes.js +12 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-sibling-node.js +38 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-switch-case-head-location.js +22 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-token-store.js +24 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/get-variable-identifiers.js +7 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/global-reference-tracker.js +68 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/has-optional-chain-element.js +17 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/has-same-range.js +7 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/index.js +59 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-function-self-used-inside.js +39 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-left-hand-side.js +20 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-logical-expression.js +14 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-method-named.js +7 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-new-expression-with-parentheses.js +28 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-node-matches.js +58 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-node-value-not-dom-node.js +20 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-node-value-not-function.js +40 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-number.js +224 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-object-method.js +10 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-on-same-line.js +7 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-same-identifier.js +5 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-same-reference.js +170 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-shorthand-export-local.js +8 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-shorthand-import-local.js +8 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-shorthand-property-assignment-pattern-left.js +8 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-shorthand-property-value.js +6 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-unresolved-variable.js +14 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/is-value-not-usable.js +5 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/needs-semicolon.js +118 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/numeric.js +49 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/parentheses.js +71 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/resolve-variable-name.js +18 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/rule.js +27 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/should-add-parentheses-to-await-expression-argument.js +17 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/should-add-parentheses-to-call-expression-callee.js +18 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/should-add-parentheses-to-conditional-expression-child.js +13 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/should-add-parentheses-to-expression-statement-expression.js +22 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/should-add-parentheses-to-logical-expression-child.js +43 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/should-add-parentheses-to-member-expression-object.js +47 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/should-add-parentheses-to-new-expression-callee.js +28 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/should-add-parentheses-to-unary-expression.js +24 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/singular.js +16 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/string-cases.js +2 -0
- package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/utils/to-location.js +25 -0
- package/packages/config-eslint/package.json +3 -3
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import {getStaticValue, isCommaToken, hasSideEffect} from '@eslint-community/eslint-utils';
|
|
2
|
+
import {
|
|
3
|
+
getParenthesizedRange,
|
|
4
|
+
getParenthesizedText,
|
|
5
|
+
needsSemicolon,
|
|
6
|
+
isNodeMatches,
|
|
7
|
+
isMethodNamed,
|
|
8
|
+
hasOptionalChainElement,
|
|
9
|
+
} from './utils/index.js';
|
|
10
|
+
import {removeMethodCall} from './fix/index.js';
|
|
11
|
+
import {isLiteral, isMethodCall} from './ast/index.js';
|
|
12
|
+
|
|
13
|
+
const ERROR_ARRAY_FROM = 'array-from';
|
|
14
|
+
const ERROR_ARRAY_CONCAT = 'array-concat';
|
|
15
|
+
const ERROR_ARRAY_SLICE = 'array-slice';
|
|
16
|
+
const ERROR_ARRAY_TO_SPLICED = 'array-to-spliced';
|
|
17
|
+
const ERROR_STRING_SPLIT = 'string-split';
|
|
18
|
+
const SUGGESTION_CONCAT_ARGUMENT_IS_SPREADABLE = 'argument-is-spreadable';
|
|
19
|
+
const SUGGESTION_CONCAT_ARGUMENT_IS_NOT_SPREADABLE = 'argument-is-not-spreadable';
|
|
20
|
+
const SUGGESTION_CONCAT_TEST_ARGUMENT = 'test-argument';
|
|
21
|
+
const SUGGESTION_CONCAT_SPREAD_ALL_ARGUMENTS = 'spread-all-arguments';
|
|
22
|
+
const SUGGESTION_USE_SPREAD = 'use-spread';
|
|
23
|
+
const messages = {
|
|
24
|
+
[ERROR_ARRAY_FROM]: 'Prefer the spread operator over `Array.from(…)`.',
|
|
25
|
+
[ERROR_ARRAY_CONCAT]: 'Prefer the spread operator over `Array#concat(…)`.',
|
|
26
|
+
[ERROR_ARRAY_SLICE]: 'Prefer the spread operator over `Array#slice()`.',
|
|
27
|
+
[ERROR_ARRAY_TO_SPLICED]: 'Prefer the spread operator over `Array#toSpliced()`.',
|
|
28
|
+
[ERROR_STRING_SPLIT]: 'Prefer the spread operator over `String#split(\'\')`.',
|
|
29
|
+
[SUGGESTION_CONCAT_ARGUMENT_IS_SPREADABLE]: 'First argument is an `array`.',
|
|
30
|
+
[SUGGESTION_CONCAT_ARGUMENT_IS_NOT_SPREADABLE]: 'First argument is not an `array`.',
|
|
31
|
+
[SUGGESTION_CONCAT_TEST_ARGUMENT]: 'Test first argument with `Array.isArray(…)`.',
|
|
32
|
+
[SUGGESTION_CONCAT_SPREAD_ALL_ARGUMENTS]: 'Spread all unknown arguments`.',
|
|
33
|
+
[SUGGESTION_USE_SPREAD]: 'Use `...` operator.',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const ignoredSliceCallee = [
|
|
37
|
+
'arrayBuffer',
|
|
38
|
+
'blob',
|
|
39
|
+
'buffer',
|
|
40
|
+
'file',
|
|
41
|
+
'this',
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const isArrayLiteral = node => node.type === 'ArrayExpression';
|
|
45
|
+
const isArrayLiteralHasTrailingComma = (node, sourceCode) => {
|
|
46
|
+
if (node.elements.length === 0) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return isCommaToken(sourceCode.getLastToken(node, 1));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function fixConcat(node, context, fixableArguments) {
|
|
54
|
+
const {sourceCode} = context;
|
|
55
|
+
const array = node.callee.object;
|
|
56
|
+
const concatCallArguments = node.arguments;
|
|
57
|
+
const arrayParenthesizedRange = getParenthesizedRange(array, context);
|
|
58
|
+
const arrayIsArrayLiteral = isArrayLiteral(array);
|
|
59
|
+
const arrayHasTrailingComma = arrayIsArrayLiteral && isArrayLiteralHasTrailingComma(array, sourceCode);
|
|
60
|
+
|
|
61
|
+
const getArrayLiteralElementsText = (node, keepTrailingComma) => {
|
|
62
|
+
if (
|
|
63
|
+
!keepTrailingComma
|
|
64
|
+
&& isArrayLiteralHasTrailingComma(node, sourceCode)
|
|
65
|
+
) {
|
|
66
|
+
const start = sourceCode.getRange(node)[0] + 1;
|
|
67
|
+
const [end] = sourceCode.getRange(sourceCode.getLastToken(node, 1));
|
|
68
|
+
return sourceCode.text.slice(start, end);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return sourceCode.getText(node, -1, -1);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const getFixedText = () => {
|
|
75
|
+
const nonEmptyArguments = fixableArguments
|
|
76
|
+
.filter(({node, isArrayLiteral}) => (!isArrayLiteral || node.elements.length > 0));
|
|
77
|
+
const lastArgument = nonEmptyArguments.at(-1);
|
|
78
|
+
|
|
79
|
+
let text = nonEmptyArguments
|
|
80
|
+
.map(({node, isArrayLiteral, isSpreadable, testArgument}) => {
|
|
81
|
+
if (isArrayLiteral) {
|
|
82
|
+
return getArrayLiteralElementsText(node, node === lastArgument.node);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let text = getParenthesizedText(node, context);
|
|
86
|
+
|
|
87
|
+
if (testArgument) {
|
|
88
|
+
return `...(Array.isArray(${text}) ? ${text} : [${text}])`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (isSpreadable) {
|
|
92
|
+
text = `...${text}`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return text || ' ';
|
|
96
|
+
})
|
|
97
|
+
.join(', ');
|
|
98
|
+
|
|
99
|
+
if (!text) {
|
|
100
|
+
return '';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (arrayIsArrayLiteral) {
|
|
104
|
+
if (array.elements.length > 0) {
|
|
105
|
+
text = ` ${text}`;
|
|
106
|
+
|
|
107
|
+
if (!arrayHasTrailingComma) {
|
|
108
|
+
text = `,${text}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (
|
|
112
|
+
arrayHasTrailingComma
|
|
113
|
+
&& (!lastArgument.isArrayLiteral || !isArrayLiteralHasTrailingComma(lastArgument.node, sourceCode))
|
|
114
|
+
) {
|
|
115
|
+
text = `${text},`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
text = `, ${text}`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return text;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
function removeArguments(fixer) {
|
|
126
|
+
const [firstArgument] = concatCallArguments;
|
|
127
|
+
const lastArgument = concatCallArguments[fixableArguments.length - 1];
|
|
128
|
+
|
|
129
|
+
const [start] = getParenthesizedRange(firstArgument, context);
|
|
130
|
+
let [, end] = sourceCode.getRange(sourceCode.getTokenAfter(lastArgument, isCommaToken));
|
|
131
|
+
|
|
132
|
+
const textAfter = sourceCode.text.slice(end);
|
|
133
|
+
const [leadingSpaces] = textAfter.match(/^\s*/);
|
|
134
|
+
end += leadingSpaces.length;
|
|
135
|
+
|
|
136
|
+
return fixer.removeRange([start, end]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return function * (fixer) {
|
|
140
|
+
// Fixed code always starts with `[`
|
|
141
|
+
if (
|
|
142
|
+
!arrayIsArrayLiteral
|
|
143
|
+
&& needsSemicolon(sourceCode.getTokenBefore(node), context, '[')
|
|
144
|
+
) {
|
|
145
|
+
yield fixer.insertTextBefore(node, ';');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
yield (
|
|
149
|
+
concatCallArguments.length - fixableArguments.length === 0
|
|
150
|
+
? removeMethodCall(fixer, node, context)
|
|
151
|
+
: removeArguments(fixer)
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const text = getFixedText();
|
|
155
|
+
|
|
156
|
+
if (arrayIsArrayLiteral) {
|
|
157
|
+
const closingBracketToken = sourceCode.getLastToken(array);
|
|
158
|
+
yield fixer.insertTextBefore(closingBracketToken, text);
|
|
159
|
+
} else {
|
|
160
|
+
// The array is already accessing `.concat`, there should not any case need add extra `()`
|
|
161
|
+
yield fixer.insertTextBeforeRange(arrayParenthesizedRange, '[...');
|
|
162
|
+
yield fixer.insertTextAfterRange(arrayParenthesizedRange, text);
|
|
163
|
+
yield fixer.insertTextAfterRange(arrayParenthesizedRange, ']');
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const getConcatArgumentSpreadable = (node, scope) => {
|
|
169
|
+
if (node.type === 'SpreadElement') {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (isArrayLiteral(node)) {
|
|
174
|
+
return {node, isArrayLiteral: true};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const result = getStaticValue(node, scope);
|
|
178
|
+
|
|
179
|
+
if (!result) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const isSpreadable = Array.isArray(result.value);
|
|
184
|
+
|
|
185
|
+
return {node, isSpreadable};
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
function getConcatFixableArguments(argumentsList, scope) {
|
|
189
|
+
const fixableArguments = [];
|
|
190
|
+
|
|
191
|
+
for (const node of argumentsList) {
|
|
192
|
+
const result = getConcatArgumentSpreadable(node, scope);
|
|
193
|
+
|
|
194
|
+
if (result) {
|
|
195
|
+
fixableArguments.push(result);
|
|
196
|
+
} else {
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return fixableArguments;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function fixArrayFrom(node, context) {
|
|
205
|
+
const {sourceCode} = context;
|
|
206
|
+
const [object] = node.arguments;
|
|
207
|
+
|
|
208
|
+
function getObjectText() {
|
|
209
|
+
if (isArrayLiteral(object)) {
|
|
210
|
+
return sourceCode.getText(object);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const [start, end] = getParenthesizedRange(object, context);
|
|
214
|
+
const text = sourceCode.text.slice(start, end);
|
|
215
|
+
|
|
216
|
+
return `[...${text}]`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return function * (fixer) {
|
|
220
|
+
// Fixed code always starts with `[`
|
|
221
|
+
if (needsSemicolon(sourceCode.getTokenBefore(node), context, '[')) {
|
|
222
|
+
yield fixer.insertTextBefore(node, ';');
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const objectText = getObjectText();
|
|
226
|
+
|
|
227
|
+
yield fixer.replaceText(node, objectText);
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function methodCallToSpread(node, context) {
|
|
232
|
+
return function * (fixer) {
|
|
233
|
+
const {sourceCode} = context;
|
|
234
|
+
// Fixed code always starts with `[`
|
|
235
|
+
if (needsSemicolon(sourceCode.getTokenBefore(node), context, '[')) {
|
|
236
|
+
yield fixer.insertTextBefore(node, ';');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
yield fixer.insertTextBefore(node, '[...');
|
|
240
|
+
yield fixer.insertTextAfter(node, ']');
|
|
241
|
+
|
|
242
|
+
// The array is already accessing `.slice` or `.split`, there should not any case need add extra `()`
|
|
243
|
+
|
|
244
|
+
yield removeMethodCall(fixer, node, context);
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isClassName(node) {
|
|
249
|
+
if (node.type === 'MemberExpression') {
|
|
250
|
+
node = node.property;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (node.type !== 'Identifier') {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const {name} = node;
|
|
258
|
+
|
|
259
|
+
return /^[A-Z]./.test(name) && name.toUpperCase() !== name;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function isNotArray(node, scope) {
|
|
263
|
+
if (
|
|
264
|
+
node.type === 'TemplateLiteral'
|
|
265
|
+
|| node.type === 'Literal'
|
|
266
|
+
|| node.type === 'BinaryExpression'
|
|
267
|
+
|| isClassName(node)
|
|
268
|
+
// `foo.join()`
|
|
269
|
+
|| (isMethodNamed(node, 'join') && node.arguments.length <= 1)
|
|
270
|
+
) {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const staticValue = getStaticValue(node, scope);
|
|
275
|
+
if (staticValue && !Array.isArray(staticValue.value)) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** @param {import('eslint').Rule.RuleContext} context */
|
|
283
|
+
const create = context => {
|
|
284
|
+
const {sourceCode} = context;
|
|
285
|
+
|
|
286
|
+
// `Array.from()`
|
|
287
|
+
context.on('CallExpression', node => {
|
|
288
|
+
if (
|
|
289
|
+
isMethodCall(node, {
|
|
290
|
+
object: 'Array',
|
|
291
|
+
method: 'from',
|
|
292
|
+
argumentsLength: 1,
|
|
293
|
+
optionalCall: false,
|
|
294
|
+
optionalMember: false,
|
|
295
|
+
})
|
|
296
|
+
// Allow `Array.from({length})`
|
|
297
|
+
&& node.arguments[0].type !== 'ObjectExpression'
|
|
298
|
+
) {
|
|
299
|
+
return {
|
|
300
|
+
node,
|
|
301
|
+
messageId: ERROR_ARRAY_FROM,
|
|
302
|
+
fix: fixArrayFrom(node, context),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// `array.concat()`
|
|
308
|
+
context.on('CallExpression', node => {
|
|
309
|
+
if (!isMethodCall(node, {
|
|
310
|
+
method: 'concat',
|
|
311
|
+
optionalCall: false,
|
|
312
|
+
optionalMember: false,
|
|
313
|
+
})) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const {object} = node.callee;
|
|
318
|
+
const scope = sourceCode.getScope(object);
|
|
319
|
+
|
|
320
|
+
if (isNotArray(object, scope)) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const staticResult = getStaticValue(object, scope);
|
|
325
|
+
if (staticResult && !Array.isArray(staticResult.value)) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const problem = {
|
|
330
|
+
node: node.callee.property,
|
|
331
|
+
messageId: ERROR_ARRAY_CONCAT,
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
const fixableArguments = getConcatFixableArguments(node.arguments, scope);
|
|
335
|
+
|
|
336
|
+
if (fixableArguments.length > 0 || node.arguments.length === 0) {
|
|
337
|
+
problem.fix = fixConcat(node, context, fixableArguments);
|
|
338
|
+
return problem;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const [firstArgument, ...restArguments] = node.arguments;
|
|
342
|
+
if (firstArgument.type === 'SpreadElement') {
|
|
343
|
+
return problem;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const fixableArgumentsAfterFirstArgument = getConcatFixableArguments(restArguments, scope);
|
|
347
|
+
const suggestions = [
|
|
348
|
+
{
|
|
349
|
+
messageId: SUGGESTION_CONCAT_ARGUMENT_IS_SPREADABLE,
|
|
350
|
+
isSpreadable: true,
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
messageId: SUGGESTION_CONCAT_ARGUMENT_IS_NOT_SPREADABLE,
|
|
354
|
+
isSpreadable: false,
|
|
355
|
+
},
|
|
356
|
+
];
|
|
357
|
+
|
|
358
|
+
if (!hasSideEffect(firstArgument, sourceCode)) {
|
|
359
|
+
suggestions.push({
|
|
360
|
+
messageId: SUGGESTION_CONCAT_TEST_ARGUMENT,
|
|
361
|
+
testArgument: true,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
problem.suggest = suggestions.map(({messageId, isSpreadable, testArgument}) => ({
|
|
366
|
+
messageId,
|
|
367
|
+
fix: fixConcat(
|
|
368
|
+
node,
|
|
369
|
+
context,
|
|
370
|
+
// When apply suggestion, we also merge fixable arguments after the first one
|
|
371
|
+
[
|
|
372
|
+
{
|
|
373
|
+
node: firstArgument,
|
|
374
|
+
isSpreadable,
|
|
375
|
+
testArgument,
|
|
376
|
+
},
|
|
377
|
+
...fixableArgumentsAfterFirstArgument,
|
|
378
|
+
],
|
|
379
|
+
),
|
|
380
|
+
}));
|
|
381
|
+
|
|
382
|
+
if (
|
|
383
|
+
fixableArgumentsAfterFirstArgument.length < restArguments.length
|
|
384
|
+
&& restArguments.every(({type}) => type !== 'SpreadElement')
|
|
385
|
+
) {
|
|
386
|
+
problem.suggest.push({
|
|
387
|
+
messageId: SUGGESTION_CONCAT_SPREAD_ALL_ARGUMENTS,
|
|
388
|
+
fix: fixConcat(
|
|
389
|
+
node,
|
|
390
|
+
context,
|
|
391
|
+
node.arguments.map(node => getConcatArgumentSpreadable(node, scope) || {node, isSpreadable: true}),
|
|
392
|
+
),
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return problem;
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// `array.slice()`
|
|
400
|
+
context.on('CallExpression', node => {
|
|
401
|
+
if (!(
|
|
402
|
+
isMethodCall(node, {
|
|
403
|
+
method: 'slice',
|
|
404
|
+
minimumArguments: 0,
|
|
405
|
+
maximumArguments: 1,
|
|
406
|
+
optionalCall: false,
|
|
407
|
+
optionalMember: false,
|
|
408
|
+
})
|
|
409
|
+
&& !isArrayLiteral(node.callee.object)
|
|
410
|
+
&& !hasOptionalChainElement(node.callee.object)
|
|
411
|
+
)) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (isNodeMatches(node.callee.object, ignoredSliceCallee)) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const [firstArgument] = node.arguments;
|
|
420
|
+
if (firstArgument && !isLiteral(firstArgument, 0)) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return {
|
|
425
|
+
node: node.callee.property,
|
|
426
|
+
messageId: ERROR_ARRAY_SLICE,
|
|
427
|
+
fix: methodCallToSpread(node, context),
|
|
428
|
+
};
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
// `array.toSpliced()`
|
|
432
|
+
context.on('CallExpression', node => {
|
|
433
|
+
if (!(
|
|
434
|
+
isMethodCall(node, {
|
|
435
|
+
method: 'toSpliced',
|
|
436
|
+
argumentsLength: 0,
|
|
437
|
+
optionalCall: false,
|
|
438
|
+
optionalMember: false,
|
|
439
|
+
})
|
|
440
|
+
&& node.callee.object.type !== 'ArrayExpression'
|
|
441
|
+
)) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return {
|
|
446
|
+
node: node.callee.property,
|
|
447
|
+
messageId: ERROR_ARRAY_TO_SPLICED,
|
|
448
|
+
fix: methodCallToSpread(node, context),
|
|
449
|
+
};
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
// `string.split()`
|
|
453
|
+
context.on('CallExpression', node => {
|
|
454
|
+
if (!isMethodCall(node, {
|
|
455
|
+
method: 'split',
|
|
456
|
+
argumentsLength: 1,
|
|
457
|
+
optionalCall: false,
|
|
458
|
+
optionalMember: false,
|
|
459
|
+
})) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const [separator] = node.arguments;
|
|
464
|
+
if (!isLiteral(separator, '')) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const string = node.callee.object;
|
|
469
|
+
const staticValue = getStaticValue(string, sourceCode.getScope(string));
|
|
470
|
+
let hasSameResult = false;
|
|
471
|
+
if (staticValue) {
|
|
472
|
+
const {value} = staticValue;
|
|
473
|
+
|
|
474
|
+
if (typeof value !== 'string') {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
|
479
|
+
const resultBySplit = value.split('');
|
|
480
|
+
const resultBySpread = [...value];
|
|
481
|
+
|
|
482
|
+
hasSameResult = resultBySplit.length === resultBySpread.length
|
|
483
|
+
&& resultBySplit.every((character, index) => character === resultBySpread[index]);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
const problem = {
|
|
487
|
+
node: node.callee.property,
|
|
488
|
+
messageId: ERROR_STRING_SPLIT,
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
if (hasSameResult) {
|
|
492
|
+
problem.fix = methodCallToSpread(node, context);
|
|
493
|
+
} else {
|
|
494
|
+
problem.suggest = [
|
|
495
|
+
{
|
|
496
|
+
messageId: SUGGESTION_USE_SPREAD,
|
|
497
|
+
fix: methodCallToSpread(node, context),
|
|
498
|
+
},
|
|
499
|
+
];
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return problem;
|
|
503
|
+
});
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
507
|
+
const config = {
|
|
508
|
+
create,
|
|
509
|
+
meta: {
|
|
510
|
+
type: 'suggestion',
|
|
511
|
+
docs: {
|
|
512
|
+
description: 'Prefer the spread operator over `Array.from(…)`, `Array#concat(…)`, `Array#{slice,toSpliced}()` and `String#split(\'\')`.',
|
|
513
|
+
recommended: true,
|
|
514
|
+
},
|
|
515
|
+
fixable: 'code',
|
|
516
|
+
hasSuggestions: true,
|
|
517
|
+
messages,
|
|
518
|
+
},
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
export default config;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {isStringLiteral, isDirective} from './ast/index.js';
|
|
2
|
+
import {fixSpaceAroundKeyword, replaceTemplateElement} from './fix/index.js';
|
|
3
|
+
|
|
4
|
+
const MESSAGE_ID = 'prefer-string-raw';
|
|
5
|
+
const messages = {
|
|
6
|
+
[MESSAGE_ID]: '`String.raw` should be used to avoid escaping `\\`.',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const BACKSLASH = '\\';
|
|
10
|
+
|
|
11
|
+
function unescapeBackslash(text, quote = '') {
|
|
12
|
+
return text.replaceAll(new RegExp(String.raw`\\(?<escapedCharacter>[\\${quote}])`, 'g'), '$<escapedCharacter>');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
Check if a string literal is restricted to replace with a `String.raw`
|
|
17
|
+
*/
|
|
18
|
+
// eslint-disable-next-line complexity
|
|
19
|
+
function isStringRawRestricted(node) {
|
|
20
|
+
const {parent} = node;
|
|
21
|
+
const {type} = parent;
|
|
22
|
+
return (
|
|
23
|
+
// Directive
|
|
24
|
+
isDirective(parent)
|
|
25
|
+
// Property, method, or accessor key (only non-computed)
|
|
26
|
+
|| (
|
|
27
|
+
(
|
|
28
|
+
type === 'Property'
|
|
29
|
+
|| type === 'PropertyDefinition'
|
|
30
|
+
|| type === 'MethodDefinition'
|
|
31
|
+
|| type === 'AccessorProperty'
|
|
32
|
+
)
|
|
33
|
+
&& !parent.computed && parent.key === node
|
|
34
|
+
)
|
|
35
|
+
// Property, method, or accessor key (always)
|
|
36
|
+
|| (
|
|
37
|
+
(
|
|
38
|
+
type === 'TSAbstractPropertyDefinition'
|
|
39
|
+
|| type === 'TSAbstractMethodDefinition'
|
|
40
|
+
|| type === 'TSAbstractAccessorProperty'
|
|
41
|
+
|| type === 'TSPropertySignature'
|
|
42
|
+
)
|
|
43
|
+
&& parent.key === node
|
|
44
|
+
)
|
|
45
|
+
// Module source
|
|
46
|
+
|| (
|
|
47
|
+
(
|
|
48
|
+
type === 'ImportDeclaration'
|
|
49
|
+
|| type === 'ExportNamedDeclaration'
|
|
50
|
+
|| type === 'ExportAllDeclaration'
|
|
51
|
+
) && parent.source === node
|
|
52
|
+
)
|
|
53
|
+
// Import attribute key and value
|
|
54
|
+
|| (type === 'ImportAttribute' && (parent.key === node || parent.value === node))
|
|
55
|
+
// Module specifier
|
|
56
|
+
|| (type === 'ImportSpecifier' && parent.imported === node)
|
|
57
|
+
|| (type === 'ExportSpecifier' && (parent.local === node || parent.exported === node))
|
|
58
|
+
|| (type === 'ExportAllDeclaration' && parent.exported === node)
|
|
59
|
+
// JSX attribute value
|
|
60
|
+
|| (type === 'JSXAttribute' && parent.value === node)
|
|
61
|
+
// (TypeScript) Enum member key and value
|
|
62
|
+
|| (type === 'TSEnumMember' && (parent.initializer === node || parent.id === node))
|
|
63
|
+
// (TypeScript) Module declaration
|
|
64
|
+
|| (type === 'TSModuleDeclaration' && parent.id === node)
|
|
65
|
+
// (TypeScript) CommonJS module reference
|
|
66
|
+
|| (type === 'TSExternalModuleReference' && parent.expression === node)
|
|
67
|
+
// (TypeScript) Literal type
|
|
68
|
+
|| (type === 'TSLiteralType' && parent.literal === node)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @param {import('eslint').Rule.RuleContext} context */
|
|
73
|
+
const create = context => {
|
|
74
|
+
context.on('Literal', node => {
|
|
75
|
+
if (!isStringLiteral(node) || isStringRawRestricted(node)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const {sourceCode} = context;
|
|
80
|
+
const {raw} = node;
|
|
81
|
+
if (
|
|
82
|
+
raw.at(-2) === BACKSLASH
|
|
83
|
+
|| !raw.includes(BACKSLASH + BACKSLASH)
|
|
84
|
+
|| raw.includes('`')
|
|
85
|
+
|| raw.includes('${')
|
|
86
|
+
|| sourceCode.getLoc(node).start.line !== sourceCode.getLoc(node).end.line
|
|
87
|
+
) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const unescaped = unescapeBackslash(raw.slice(1, -1), raw.charAt(0));
|
|
92
|
+
if (unescaped !== node.value) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
node,
|
|
98
|
+
messageId: MESSAGE_ID,
|
|
99
|
+
* fix(fixer) {
|
|
100
|
+
yield fixSpaceAroundKeyword(fixer, node, context);
|
|
101
|
+
yield fixer.replaceText(node, `String.raw\`${unescaped}\``);
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
context.on('TemplateLiteral', node => {
|
|
107
|
+
if (
|
|
108
|
+
(node.parent.type === 'TaggedTemplateExpression' && node.parent.quasi === node)
|
|
109
|
+
|| node.quasis.every(({value: {cooked, raw}}) => cooked === raw)
|
|
110
|
+
|| node.quasis.some(({value: {cooked, raw}}) => cooked.at(-1) === BACKSLASH || unescapeBackslash(raw) !== cooked)
|
|
111
|
+
) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
node,
|
|
117
|
+
messageId: MESSAGE_ID,
|
|
118
|
+
* fix(fixer) {
|
|
119
|
+
yield fixSpaceAroundKeyword(fixer, node, context);
|
|
120
|
+
yield fixer.insertTextBefore(node, 'String.raw');
|
|
121
|
+
|
|
122
|
+
for (const quasis of node.quasis) {
|
|
123
|
+
const {cooked, raw} = quasis.value;
|
|
124
|
+
if (cooked === raw) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
yield replaceTemplateElement(quasis, cooked, context, fixer);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
136
|
+
const config = {
|
|
137
|
+
create,
|
|
138
|
+
meta: {
|
|
139
|
+
type: 'suggestion',
|
|
140
|
+
docs: {
|
|
141
|
+
description: 'Prefer using the `String.raw` tag to avoid escaping `\\`.',
|
|
142
|
+
recommended: 'unopinionated',
|
|
143
|
+
},
|
|
144
|
+
fixable: 'code',
|
|
145
|
+
messages,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export default config;
|