@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
package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-keyboard-event-key.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import escapeString from './utils/escape-string.js';
|
|
2
|
+
import translateToKey from './shared/event-keys.js';
|
|
3
|
+
import {isNumericLiteral} from './ast/index.js';
|
|
4
|
+
|
|
5
|
+
const MESSAGE_ID = 'prefer-keyboard-event-key';
|
|
6
|
+
const messages = {
|
|
7
|
+
[MESSAGE_ID]: 'Use `.key` instead of `.{{name}}`.',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const keys = new Set([
|
|
11
|
+
'keyCode',
|
|
12
|
+
'charCode',
|
|
13
|
+
'which',
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const isPropertyNamedAddEventListener = node =>
|
|
17
|
+
node?.type === 'CallExpression'
|
|
18
|
+
&& node.callee.type === 'MemberExpression'
|
|
19
|
+
&& node.callee.property.name === 'addEventListener';
|
|
20
|
+
|
|
21
|
+
const getEventNodeAndReferences = (context, node) => {
|
|
22
|
+
const eventListener = getMatchingAncestorOfType(node, 'CallExpression', isPropertyNamedAddEventListener);
|
|
23
|
+
const callback = eventListener?.arguments[1];
|
|
24
|
+
switch (callback?.type) {
|
|
25
|
+
case 'ArrowFunctionExpression':
|
|
26
|
+
case 'FunctionExpression': {
|
|
27
|
+
const eventVariable = context.sourceCode.getDeclaredVariables(callback)[0];
|
|
28
|
+
const references = eventVariable?.references;
|
|
29
|
+
return {
|
|
30
|
+
event: callback.params[0],
|
|
31
|
+
references,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
default: {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const isPropertyOf = (node, eventNode) =>
|
|
42
|
+
node?.parent?.type === 'MemberExpression'
|
|
43
|
+
&& node.parent.object === eventNode;
|
|
44
|
+
|
|
45
|
+
// The third argument is a condition function, as one passed to `Array#filter()`
|
|
46
|
+
// Helpful if nearest node of type also needs to have some other property
|
|
47
|
+
const getMatchingAncestorOfType = (node, type, testFunction = () => true) => {
|
|
48
|
+
let current = node;
|
|
49
|
+
while (current) {
|
|
50
|
+
if (current.type === type && testFunction(current)) {
|
|
51
|
+
return current;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
current = current.parent;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const getParentByLevel = (node, level) => {
|
|
59
|
+
let current = node;
|
|
60
|
+
while (current && level) {
|
|
61
|
+
level--;
|
|
62
|
+
current = current.parent;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* c8 ignore next 3 */
|
|
66
|
+
if (level === 0) {
|
|
67
|
+
return current;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const fix = node => fixer => {
|
|
72
|
+
// Since we're only fixing direct property access usages, like `event.keyCode`
|
|
73
|
+
const nearestIf = getParentByLevel(node, 3);
|
|
74
|
+
if (!nearestIf || nearestIf.type !== 'IfStatement') {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const {type, operator, right} = nearestIf.test;
|
|
79
|
+
if (
|
|
80
|
+
!(
|
|
81
|
+
type === 'BinaryExpression'
|
|
82
|
+
&& (operator === '==' || operator === '===')
|
|
83
|
+
&& isNumericLiteral(right)
|
|
84
|
+
)
|
|
85
|
+
) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Either a meta key or a printable character
|
|
90
|
+
const key = translateToKey[right.value] || String.fromCodePoint(right.value);
|
|
91
|
+
// And if we recognize the `.keyCode`
|
|
92
|
+
if (!key) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Apply fixes
|
|
97
|
+
return [
|
|
98
|
+
fixer.replaceText(node, 'key'),
|
|
99
|
+
fixer.replaceText(right, escapeString(key)),
|
|
100
|
+
];
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const getProblem = node => ({
|
|
104
|
+
messageId: MESSAGE_ID,
|
|
105
|
+
data: {name: node.name},
|
|
106
|
+
node,
|
|
107
|
+
fix: fix(node),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/** @param {import('eslint').Rule.RuleContext} context */
|
|
111
|
+
const create = context => ({
|
|
112
|
+
Identifier(node) {
|
|
113
|
+
if (
|
|
114
|
+
node.name !== 'keyCode'
|
|
115
|
+
&& node.name !== 'charCode'
|
|
116
|
+
&& node.name !== 'which'
|
|
117
|
+
) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Normal case when usage is direct -> `event.keyCode`
|
|
122
|
+
const {event, references} = getEventNodeAndReferences(context, node);
|
|
123
|
+
if (!event) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (
|
|
128
|
+
references
|
|
129
|
+
&& references.some(reference => isPropertyOf(node, reference.identifier))
|
|
130
|
+
) {
|
|
131
|
+
return getProblem(node);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
Property(node) {
|
|
136
|
+
// Destructured case
|
|
137
|
+
const propertyName = node.value.name;
|
|
138
|
+
if (!keys.has(propertyName)) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const {event, references} = getEventNodeAndReferences(context, node);
|
|
143
|
+
if (!event) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const nearestVariableDeclarator = getMatchingAncestorOfType(
|
|
148
|
+
node,
|
|
149
|
+
'VariableDeclarator',
|
|
150
|
+
);
|
|
151
|
+
const initObject = nearestVariableDeclarator?.init;
|
|
152
|
+
|
|
153
|
+
// Make sure initObject is a reference of eventVariable
|
|
154
|
+
if (
|
|
155
|
+
references
|
|
156
|
+
&& references.some(reference => reference.identifier === initObject)
|
|
157
|
+
) {
|
|
158
|
+
return getProblem(node.value);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// When the event parameter itself is destructured directly
|
|
162
|
+
const isEventParameterDestructured = event.type === 'ObjectPattern';
|
|
163
|
+
if (isEventParameterDestructured) {
|
|
164
|
+
// Check for properties
|
|
165
|
+
for (const property of event.properties) {
|
|
166
|
+
if (property === node) {
|
|
167
|
+
return getProblem(node.value);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
175
|
+
const config = {
|
|
176
|
+
create,
|
|
177
|
+
meta: {
|
|
178
|
+
type: 'suggestion',
|
|
179
|
+
docs: {
|
|
180
|
+
description: 'Prefer `KeyboardEvent#key` over `KeyboardEvent#keyCode`.',
|
|
181
|
+
recommended: 'unopinionated',
|
|
182
|
+
},
|
|
183
|
+
fixable: 'code',
|
|
184
|
+
messages,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export default config;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import {isParenthesized, getParenthesizedText} from './utils/parentheses.js';
|
|
2
|
+
import isSameReference from './utils/is-same-reference.js';
|
|
3
|
+
import shouldAddParenthesesToLogicalExpressionChild from './utils/should-add-parentheses-to-logical-expression-child.js';
|
|
4
|
+
import needsSemicolon from './utils/needs-semicolon.js';
|
|
5
|
+
|
|
6
|
+
const MESSAGE_ID_ERROR = 'prefer-logical-operator-over-ternary/error';
|
|
7
|
+
const MESSAGE_ID_SUGGESTION = 'prefer-logical-operator-over-ternary/suggestion';
|
|
8
|
+
const messages = {
|
|
9
|
+
[MESSAGE_ID_ERROR]: 'Prefer using a logical operator over a ternary.',
|
|
10
|
+
[MESSAGE_ID_SUGGESTION]: 'Switch to `{{operator}}` operator.',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function isSameNode(left, right, sourceCode) {
|
|
14
|
+
if (isSameReference(left, right)) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (left.type !== right.type) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
switch (left.type) {
|
|
23
|
+
case 'AwaitExpression': {
|
|
24
|
+
return isSameNode(left.argument, right.argument, sourceCode);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
case 'LogicalExpression': {
|
|
28
|
+
return (
|
|
29
|
+
left.operator === right.operator
|
|
30
|
+
&& isSameNode(left.left, right.left, sourceCode)
|
|
31
|
+
&& isSameNode(left.right, right.right, sourceCode)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
case 'UnaryExpression': {
|
|
36
|
+
return (
|
|
37
|
+
left.operator === right.operator
|
|
38
|
+
&& left.prefix === right.prefix
|
|
39
|
+
&& isSameNode(left.argument, right.argument, sourceCode)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
case 'UpdateExpression': {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// No default
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return sourceCode.getText(left) === sourceCode.getText(right);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function fix({
|
|
54
|
+
fixer,
|
|
55
|
+
context,
|
|
56
|
+
conditionalExpression,
|
|
57
|
+
left,
|
|
58
|
+
right,
|
|
59
|
+
operator,
|
|
60
|
+
}) {
|
|
61
|
+
const {sourceCode} = context;
|
|
62
|
+
let text = [left, right].map((node, index) => {
|
|
63
|
+
const isNodeParenthesized = isParenthesized(node, sourceCode);
|
|
64
|
+
let text = isNodeParenthesized ? getParenthesizedText(node, context) : sourceCode.getText(node);
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
!isNodeParenthesized
|
|
68
|
+
&& shouldAddParenthesesToLogicalExpressionChild(node, {operator, property: index === 0 ? 'left' : 'right'})
|
|
69
|
+
) {
|
|
70
|
+
text = `(${text})`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return text;
|
|
74
|
+
}).join(` ${operator} `);
|
|
75
|
+
|
|
76
|
+
// According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table
|
|
77
|
+
// There should be no cases need add parentheses when switching ternary to logical expression
|
|
78
|
+
|
|
79
|
+
// ASI
|
|
80
|
+
if (needsSemicolon(sourceCode.getTokenBefore(conditionalExpression), context, text)) {
|
|
81
|
+
text = `;${text}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return fixer.replaceText(conditionalExpression, text);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getProblem({
|
|
88
|
+
context,
|
|
89
|
+
conditionalExpression,
|
|
90
|
+
left,
|
|
91
|
+
right,
|
|
92
|
+
}) {
|
|
93
|
+
return {
|
|
94
|
+
node: conditionalExpression,
|
|
95
|
+
messageId: MESSAGE_ID_ERROR,
|
|
96
|
+
suggest: ['??', '||'].map(operator => ({
|
|
97
|
+
messageId: MESSAGE_ID_SUGGESTION,
|
|
98
|
+
data: {operator},
|
|
99
|
+
fix: fixer => fix({
|
|
100
|
+
fixer,
|
|
101
|
+
context,
|
|
102
|
+
conditionalExpression,
|
|
103
|
+
left,
|
|
104
|
+
right,
|
|
105
|
+
operator,
|
|
106
|
+
}),
|
|
107
|
+
})),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @param {import('eslint').Rule.RuleContext} context */
|
|
112
|
+
const create = context => {
|
|
113
|
+
const {sourceCode} = context;
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
ConditionalExpression(conditionalExpression) {
|
|
117
|
+
const {test, consequent, alternate} = conditionalExpression;
|
|
118
|
+
|
|
119
|
+
// `foo ? foo : bar`
|
|
120
|
+
if (isSameNode(test, consequent, sourceCode)) {
|
|
121
|
+
return getProblem({
|
|
122
|
+
context,
|
|
123
|
+
conditionalExpression,
|
|
124
|
+
left: test,
|
|
125
|
+
right: alternate,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// `!bar ? foo : bar`
|
|
130
|
+
if (
|
|
131
|
+
test.type === 'UnaryExpression'
|
|
132
|
+
&& test.operator === '!'
|
|
133
|
+
&& test.prefix
|
|
134
|
+
&& isSameNode(test.argument, alternate, sourceCode)
|
|
135
|
+
) {
|
|
136
|
+
return getProblem({
|
|
137
|
+
context,
|
|
138
|
+
conditionalExpression,
|
|
139
|
+
left: test.argument,
|
|
140
|
+
right: consequent,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
148
|
+
const config = {
|
|
149
|
+
create,
|
|
150
|
+
meta: {
|
|
151
|
+
type: 'suggestion',
|
|
152
|
+
docs: {
|
|
153
|
+
description: 'Prefer using a logical operator over a ternary.',
|
|
154
|
+
recommended: 'unopinionated',
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
hasSuggestions: true,
|
|
158
|
+
messages,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export default config;
|
package/packages/config-eslint/node_modules/eslint-plugin-unicorn/rules/prefer-math-min-max.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/* eslint-disable complexity */
|
|
2
|
+
import {isBigIntLiteral, isCallExpression} from './ast/index.js';
|
|
3
|
+
import {fixSpaceAroundKeyword} from './fix/index.js';
|
|
4
|
+
|
|
5
|
+
const MESSAGE_ID = 'prefer-math-min-max';
|
|
6
|
+
const messages = {
|
|
7
|
+
[MESSAGE_ID]: 'Prefer `Math.{{method}}()` to simplify ternary expressions.',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const isNumberTypeAnnotation = typeAnnotation => {
|
|
11
|
+
if (typeAnnotation.type === 'TSNumberKeyword') {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (typeAnnotation.type === 'TSTypeAnnotation' && typeAnnotation.typeAnnotation.type === 'TSNumberKeyword') {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeAnnotation.type === 'TSTypeReference' && typeAnnotation.typeName.name === 'Number') {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const getExpressionText = (node, sourceCode) => {
|
|
27
|
+
const expressionNode = node.type === 'TSAsExpression' ? node.expression : node;
|
|
28
|
+
|
|
29
|
+
if (node.type === 'TSAsExpression') {
|
|
30
|
+
return getExpressionText(expressionNode, sourceCode);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return sourceCode.getText(expressionNode);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** @param {import('eslint').Rule.RuleContext} context */
|
|
37
|
+
const create = context => ({
|
|
38
|
+
/** @param {import('estree').ConditionalExpression} conditionalExpression */
|
|
39
|
+
ConditionalExpression(conditionalExpression) {
|
|
40
|
+
const {test, consequent, alternate} = conditionalExpression;
|
|
41
|
+
|
|
42
|
+
if (test.type !== 'BinaryExpression') {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const {operator, left, right} = test;
|
|
47
|
+
|
|
48
|
+
const hasBigInt = [left, right].some(
|
|
49
|
+
node =>
|
|
50
|
+
isBigIntLiteral(node)
|
|
51
|
+
|| isCallExpression(node, {
|
|
52
|
+
name: 'BigInt',
|
|
53
|
+
argumentsLength: 1,
|
|
54
|
+
optional: false,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
if (hasBigInt) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const [leftText, rightText, alternateText, consequentText] = [left, right, alternate, consequent].map(node => getExpressionText(node, context.sourceCode));
|
|
63
|
+
|
|
64
|
+
const isGreaterOrEqual = operator === '>' || operator === '>=';
|
|
65
|
+
const isLessOrEqual = operator === '<' || operator === '<=';
|
|
66
|
+
|
|
67
|
+
let method;
|
|
68
|
+
|
|
69
|
+
// Prefer `Math.min()`
|
|
70
|
+
if (
|
|
71
|
+
// `height > 50 ? 50 : height`
|
|
72
|
+
(isGreaterOrEqual && leftText === alternateText && rightText === consequentText)
|
|
73
|
+
// `height < 50 ? height : 50`
|
|
74
|
+
|| (isLessOrEqual && leftText === consequentText && rightText === alternateText)
|
|
75
|
+
) {
|
|
76
|
+
method = 'min';
|
|
77
|
+
} else if (
|
|
78
|
+
// `height > 50 ? height : 50`
|
|
79
|
+
(isGreaterOrEqual && leftText === consequentText && rightText === alternateText)
|
|
80
|
+
// `height < 50 ? 50 : height`
|
|
81
|
+
|| (isLessOrEqual && leftText === alternateText && rightText === consequentText)
|
|
82
|
+
) {
|
|
83
|
+
method = 'max';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!method) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const node of [left, right]) {
|
|
91
|
+
let expressionNode = node;
|
|
92
|
+
|
|
93
|
+
if (expressionNode.typeAnnotation && expressionNode.type === 'TSAsExpression') {
|
|
94
|
+
// Ignore if the test is not a number comparison operator
|
|
95
|
+
if (!isNumberTypeAnnotation(expressionNode.typeAnnotation)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
expressionNode = expressionNode.expression;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Find variable declaration
|
|
103
|
+
if (expressionNode.type === 'Identifier') {
|
|
104
|
+
const variable = context.sourceCode.getScope(expressionNode).variables.find(variable => variable.name === expressionNode.name);
|
|
105
|
+
|
|
106
|
+
for (const definition of variable?.defs ?? []) {
|
|
107
|
+
switch (definition.type) {
|
|
108
|
+
case 'Parameter': {
|
|
109
|
+
const identifier = definition.name;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
Capture the following statement
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
function foo(a: number) {}
|
|
116
|
+
```
|
|
117
|
+
*/
|
|
118
|
+
if (identifier.typeAnnotation?.type === 'TSTypeAnnotation' && !isNumberTypeAnnotation(identifier.typeAnnotation)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
Capture the following statement
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
function foo(a = 10) {}
|
|
127
|
+
```
|
|
128
|
+
*/
|
|
129
|
+
if (identifier.parent.type === 'AssignmentPattern' && identifier.parent.right.type === 'Literal' && typeof identifier.parent.right.value !== 'number') {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
case 'Variable': {
|
|
137
|
+
/** @type {import('estree').VariableDeclarator} */
|
|
138
|
+
const variableDeclarator = definition.node;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
Capture the following statement
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
var foo: number
|
|
145
|
+
```
|
|
146
|
+
*/
|
|
147
|
+
if (variableDeclarator.id.typeAnnotation?.type === 'TSTypeAnnotation' && !isNumberTypeAnnotation(variableDeclarator.id.typeAnnotation)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
Capture the following statement
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
var foo = 10
|
|
156
|
+
```
|
|
157
|
+
*/
|
|
158
|
+
if (variableDeclarator.init?.type === 'Literal' && typeof variableDeclarator.init.value !== 'number') {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
default:
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
node: conditionalExpression,
|
|
173
|
+
messageId: MESSAGE_ID,
|
|
174
|
+
data: {method},
|
|
175
|
+
/** @param {import('eslint').Rule.RuleFixer} fixer */
|
|
176
|
+
* fix(fixer) {
|
|
177
|
+
const {sourceCode} = context;
|
|
178
|
+
|
|
179
|
+
yield fixSpaceAroundKeyword(fixer, conditionalExpression, context);
|
|
180
|
+
|
|
181
|
+
const argumentsText = [left, right]
|
|
182
|
+
.map(node => node.type === 'SequenceExpression' ? `(${sourceCode.getText(node)})` : sourceCode.getText(node))
|
|
183
|
+
.join(', ');
|
|
184
|
+
|
|
185
|
+
yield fixer.replaceText(conditionalExpression, `Math.${method}(${argumentsText})`);
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
192
|
+
const config = {
|
|
193
|
+
create,
|
|
194
|
+
meta: {
|
|
195
|
+
type: 'problem',
|
|
196
|
+
docs: {
|
|
197
|
+
description: 'Prefer `Math.min()` and `Math.max()` over ternaries for simple comparisons.',
|
|
198
|
+
recommended: 'unopinionated',
|
|
199
|
+
},
|
|
200
|
+
fixable: 'code',
|
|
201
|
+
messages,
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export default config;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {hasSideEffect} from '@eslint-community/eslint-utils';
|
|
2
|
+
import {fixSpaceAroundKeyword} from './fix/index.js';
|
|
3
|
+
import {isLiteral} from './ast/index.js';
|
|
4
|
+
|
|
5
|
+
const ERROR_BITWISE = 'error-bitwise';
|
|
6
|
+
const ERROR_BITWISE_NOT = 'error-bitwise-not';
|
|
7
|
+
const SUGGESTION_BITWISE = 'suggestion-bitwise';
|
|
8
|
+
const messages = {
|
|
9
|
+
[ERROR_BITWISE]: 'Use `Math.trunc` instead of `{{operator}} {{value}}`.',
|
|
10
|
+
[ERROR_BITWISE_NOT]: 'Use `Math.trunc` instead of `~~`.',
|
|
11
|
+
[SUGGESTION_BITWISE]: 'Replace `{{operator}} {{value}}` with `Math.trunc`.',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Bitwise operators
|
|
15
|
+
const bitwiseOperators = new Set(['|', '>>', '<<', '^']);
|
|
16
|
+
const isBitwiseNot = node =>
|
|
17
|
+
node.type === 'UnaryExpression'
|
|
18
|
+
&& node.operator === '~';
|
|
19
|
+
|
|
20
|
+
/** @param {import('eslint').Rule.RuleContext} context */
|
|
21
|
+
const create = context => {
|
|
22
|
+
const {sourceCode} = context;
|
|
23
|
+
|
|
24
|
+
const mathTruncFunctionCall = node => {
|
|
25
|
+
const text = sourceCode.getText(node);
|
|
26
|
+
const parenthesized = node.type === 'SequenceExpression' ? `(${text})` : text;
|
|
27
|
+
return `Math.trunc(${parenthesized})`;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
context.on(['BinaryExpression', 'AssignmentExpression'], node => {
|
|
31
|
+
const {type, operator, right, left} = node;
|
|
32
|
+
const isAssignment = type === 'AssignmentExpression';
|
|
33
|
+
if (
|
|
34
|
+
!isLiteral(right, 0)
|
|
35
|
+
|| !bitwiseOperators.has(isAssignment ? operator.slice(0, -1) : operator)
|
|
36
|
+
) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const problem = {
|
|
41
|
+
node,
|
|
42
|
+
messageId: ERROR_BITWISE,
|
|
43
|
+
data: {
|
|
44
|
+
operator,
|
|
45
|
+
value: right.raw,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
if (!isAssignment || !hasSideEffect(left, sourceCode)) {
|
|
50
|
+
const fix = function * (fixer) {
|
|
51
|
+
const fixed = mathTruncFunctionCall(left);
|
|
52
|
+
if (isAssignment) {
|
|
53
|
+
const operatorToken = sourceCode.getTokenAfter(left, token => token.type === 'Punctuator' && token.value === operator);
|
|
54
|
+
yield fixer.replaceText(operatorToken, '=');
|
|
55
|
+
yield fixer.replaceText(right, fixed);
|
|
56
|
+
} else {
|
|
57
|
+
yield fixSpaceAroundKeyword(fixer, node, context);
|
|
58
|
+
yield fixer.replaceText(node, fixed);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if (operator === '|') {
|
|
63
|
+
problem.suggest = [
|
|
64
|
+
{
|
|
65
|
+
messageId: SUGGESTION_BITWISE,
|
|
66
|
+
fix,
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
} else {
|
|
70
|
+
problem.fix = fix;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return problem;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Unary Expression Selector: Inner-most 2 bitwise NOT
|
|
78
|
+
context.on('UnaryExpression', node => {
|
|
79
|
+
if (
|
|
80
|
+
isBitwiseNot(node)
|
|
81
|
+
&& isBitwiseNot(node.argument)
|
|
82
|
+
&& !isBitwiseNot(node.argument.argument)
|
|
83
|
+
) {
|
|
84
|
+
return {
|
|
85
|
+
node,
|
|
86
|
+
messageId: ERROR_BITWISE_NOT,
|
|
87
|
+
* fix(fixer) {
|
|
88
|
+
yield fixer.replaceText(node, mathTruncFunctionCall(node.argument.argument));
|
|
89
|
+
yield fixSpaceAroundKeyword(fixer, node, context);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
97
|
+
const config = {
|
|
98
|
+
create,
|
|
99
|
+
meta: {
|
|
100
|
+
type: 'suggestion',
|
|
101
|
+
docs: {
|
|
102
|
+
description: 'Enforce the use of `Math.trunc` instead of bitwise operators.',
|
|
103
|
+
recommended: 'unopinionated',
|
|
104
|
+
},
|
|
105
|
+
fixable: 'code',
|
|
106
|
+
hasSuggestions: true,
|
|
107
|
+
messages,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export default config;
|