@depup/typescript-eslint__eslint-plugin 8.57.1-depup.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/LICENSE +21 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/configs/eslint-recommended-raw.d.ts +10 -0
- package/dist/configs/eslint-recommended-raw.js +46 -0
- package/dist/configs/eslintrc/all.d.ts +159 -0
- package/dist/configs/eslintrc/all.js +165 -0
- package/dist/configs/eslintrc/base.d.ts +8 -0
- package/dist/configs/eslintrc/base.js +6 -0
- package/dist/configs/eslintrc/disable-type-checked.d.ts +71 -0
- package/dist/configs/eslintrc/disable-type-checked.js +73 -0
- package/dist/configs/eslintrc/eslint-recommended.d.ts +12 -0
- package/dist/configs/eslintrc/eslint-recommended.js +13 -0
- package/dist/configs/eslintrc/recommended-type-checked-only.d.ts +33 -0
- package/dist/configs/eslintrc/recommended-type-checked-only.js +39 -0
- package/dist/configs/eslintrc/recommended-type-checked.d.ts +56 -0
- package/dist/configs/eslintrc/recommended-type-checked.js +62 -0
- package/dist/configs/eslintrc/recommended.d.ts +29 -0
- package/dist/configs/eslintrc/recommended.js +35 -0
- package/dist/configs/eslintrc/strict-type-checked-only.d.ts +64 -0
- package/dist/configs/eslintrc/strict-type-checked-only.js +79 -0
- package/dist/configs/eslintrc/strict-type-checked.d.ts +98 -0
- package/dist/configs/eslintrc/strict-type-checked.js +114 -0
- package/dist/configs/eslintrc/strict.d.ts +40 -0
- package/dist/configs/eslintrc/strict.js +47 -0
- package/dist/configs/eslintrc/stylistic-type-checked-only.d.ts +15 -0
- package/dist/configs/eslintrc/stylistic-type-checked-only.js +21 -0
- package/dist/configs/eslintrc/stylistic-type-checked.d.ts +29 -0
- package/dist/configs/eslintrc/stylistic-type-checked.js +35 -0
- package/dist/configs/eslintrc/stylistic.d.ts +20 -0
- package/dist/configs/eslintrc/stylistic.js +26 -0
- package/dist/configs/flat/all.d.ts +7 -0
- package/dist/configs/flat/all.js +179 -0
- package/dist/configs/flat/base.d.ts +8 -0
- package/dist/configs/flat/base.js +17 -0
- package/dist/configs/flat/disable-type-checked.d.ts +7 -0
- package/dist/configs/flat/disable-type-checked.js +81 -0
- package/dist/configs/flat/eslint-recommended.d.ts +9 -0
- package/dist/configs/flat/eslint-recommended.js +16 -0
- package/dist/configs/flat/recommended-type-checked-only.d.ts +7 -0
- package/dist/configs/flat/recommended-type-checked-only.js +53 -0
- package/dist/configs/flat/recommended-type-checked.d.ts +7 -0
- package/dist/configs/flat/recommended-type-checked.js +76 -0
- package/dist/configs/flat/recommended.d.ts +7 -0
- package/dist/configs/flat/recommended.js +49 -0
- package/dist/configs/flat/strict-type-checked-only.d.ts +7 -0
- package/dist/configs/flat/strict-type-checked-only.js +93 -0
- package/dist/configs/flat/strict-type-checked.d.ts +7 -0
- package/dist/configs/flat/strict-type-checked.js +128 -0
- package/dist/configs/flat/strict.d.ts +7 -0
- package/dist/configs/flat/strict.js +61 -0
- package/dist/configs/flat/stylistic-type-checked-only.d.ts +7 -0
- package/dist/configs/flat/stylistic-type-checked-only.js +35 -0
- package/dist/configs/flat/stylistic-type-checked.d.ts +7 -0
- package/dist/configs/flat/stylistic-type-checked.js +49 -0
- package/dist/configs/flat/stylistic.d.ts +7 -0
- package/dist/configs/flat/stylistic.js +40 -0
- package/dist/index.d.ts +1128 -0
- package/dist/index.js +6 -0
- package/dist/raw-plugin.d.ts +1152 -0
- package/dist/raw-plugin.js +122 -0
- package/dist/rules/adjacent-overload-signatures.d.ts +4 -0
- package/dist/rules/adjacent-overload-signatures.js +124 -0
- package/dist/rules/array-type.d.ts +12 -0
- package/dist/rules/array-type.js +232 -0
- package/dist/rules/await-thenable.d.ts +6 -0
- package/dist/rules/await-thenable.js +228 -0
- package/dist/rules/ban-ts-comment.d.ts +17 -0
- package/dist/rules/ban-ts-comment.js +195 -0
- package/dist/rules/ban-tslint-comment.d.ts +4 -0
- package/dist/rules/ban-tslint-comment.js +53 -0
- package/dist/rules/class-literal-property-style.d.ts +7 -0
- package/dist/rules/class-literal-property-style.js +160 -0
- package/dist/rules/class-methods-use-this.d.ts +13 -0
- package/dist/rules/class-methods-use-this.js +219 -0
- package/dist/rules/consistent-generic-constructors.d.ts +6 -0
- package/dist/rules/consistent-generic-constructors.js +126 -0
- package/dist/rules/consistent-indexed-object-style.d.ts +7 -0
- package/dist/rules/consistent-indexed-object-style.js +256 -0
- package/dist/rules/consistent-return.d.ts +18 -0
- package/dist/rules/consistent-return.js +135 -0
- package/dist/rules/consistent-type-assertions.d.ts +14 -0
- package/dist/rules/consistent-type-assertions.js +256 -0
- package/dist/rules/consistent-type-definitions.d.ts +5 -0
- package/dist/rules/consistent-type-definitions.js +100 -0
- package/dist/rules/consistent-type-exports.d.ts +11 -0
- package/dist/rules/consistent-type-exports.js +335 -0
- package/dist/rules/consistent-type-imports.d.ts +15 -0
- package/dist/rules/consistent-type-imports.js +608 -0
- package/dist/rules/default-param-last.d.ts +4 -0
- package/dist/rules/default-param-last.js +68 -0
- package/dist/rules/dot-notation.d.ts +23 -0
- package/dist/rules/dot-notation.js +139 -0
- package/dist/rules/enum-utils/shared.d.ts +36 -0
- package/dist/rules/enum-utils/shared.js +121 -0
- package/dist/rules/explicit-function-return-type.d.ts +17 -0
- package/dist/rules/explicit-function-return-type.js +179 -0
- package/dist/rules/explicit-member-accessibility.d.ts +19 -0
- package/dist/rules/explicit-member-accessibility.js +299 -0
- package/dist/rules/explicit-module-boundary-types.d.ts +15 -0
- package/dist/rules/explicit-module-boundary-types.js +386 -0
- package/dist/rules/index.d.ts +448 -0
- package/dist/rules/index.js +275 -0
- package/dist/rules/init-declarations.d.ts +15 -0
- package/dist/rules/init-declarations.js +105 -0
- package/dist/rules/max-params.d.ts +25 -0
- package/dist/rules/max-params.js +72 -0
- package/dist/rules/member-ordering.d.ts +33 -0
- package/dist/rules/member-ordering.js +833 -0
- package/dist/rules/method-signature-style.d.ts +6 -0
- package/dist/rules/method-signature-style.js +186 -0
- package/dist/rules/naming-convention-utils/enums.d.ts +79 -0
- package/dist/rules/naming-convention-utils/enums.js +102 -0
- package/dist/rules/naming-convention-utils/format.d.ts +2 -0
- package/dist/rules/naming-convention-utils/format.js +89 -0
- package/dist/rules/naming-convention-utils/index.d.ts +6 -0
- package/dist/rules/naming-convention-utils/index.js +11 -0
- package/dist/rules/naming-convention-utils/parse-options.d.ts +2 -0
- package/dist/rules/naming-convention-utils/parse-options.js +69 -0
- package/dist/rules/naming-convention-utils/schema.d.ts +2 -0
- package/dist/rules/naming-convention-utils/schema.js +305 -0
- package/dist/rules/naming-convention-utils/shared.d.ts +5 -0
- package/dist/rules/naming-convention-utils/shared.js +16 -0
- package/dist/rules/naming-convention-utils/types.d.ts +39 -0
- package/dist/rules/naming-convention-utils/types.js +2 -0
- package/dist/rules/naming-convention-utils/validator.d.ts +3 -0
- package/dist/rules/naming-convention-utils/validator.js +349 -0
- package/dist/rules/naming-convention.d.ts +8 -0
- package/dist/rules/naming-convention.js +505 -0
- package/dist/rules/no-array-constructor.d.ts +4 -0
- package/dist/rules/no-array-constructor.js +62 -0
- package/dist/rules/no-array-delete.d.ts +6 -0
- package/dist/rules/no-array-delete.js +80 -0
- package/dist/rules/no-base-to-string.d.ts +11 -0
- package/dist/rules/no-base-to-string.js +324 -0
- package/dist/rules/no-confusing-non-null-assertion.d.ts +6 -0
- package/dist/rules/no-confusing-non-null-assertion.js +142 -0
- package/dist/rules/no-confusing-void-expression.d.ts +13 -0
- package/dist/rules/no-confusing-void-expression.js +357 -0
- package/dist/rules/no-deprecated.d.ts +11 -0
- package/dist/rules/no-deprecated.js +402 -0
- package/dist/rules/no-dupe-class-members.d.ts +14 -0
- package/dist/rules/no-dupe-class-members.js +39 -0
- package/dist/rules/no-duplicate-enum-values.d.ts +4 -0
- package/dist/rules/no-duplicate-enum-values.js +83 -0
- package/dist/rules/no-duplicate-type-constituents.d.ts +11 -0
- package/dist/rules/no-duplicate-type-constituents.js +219 -0
- package/dist/rules/no-dynamic-delete.d.ts +4 -0
- package/dist/rules/no-dynamic-delete.js +42 -0
- package/dist/rules/no-empty-function.d.ts +16 -0
- package/dist/rules/no-empty-function.js +134 -0
- package/dist/rules/no-empty-interface.d.ts +11 -0
- package/dist/rules/no-empty-interface.js +102 -0
- package/dist/rules/no-empty-object-type.d.ts +15 -0
- package/dist/rules/no-empty-object-type.js +143 -0
- package/dist/rules/no-explicit-any.d.ts +12 -0
- package/dist/rules/no-explicit-any.js +197 -0
- package/dist/rules/no-extra-non-null-assertion.d.ts +4 -0
- package/dist/rules/no-extra-non-null-assertion.js +35 -0
- package/dist/rules/no-extraneous-class.d.ts +13 -0
- package/dist/rules/no-extraneous-class.js +120 -0
- package/dist/rules/no-floating-promises.d.ts +16 -0
- package/dist/rules/no-floating-promises.js +365 -0
- package/dist/rules/no-for-in-array.d.ts +4 -0
- package/dist/rules/no-for-in-array.js +86 -0
- package/dist/rules/no-implied-eval.d.ts +4 -0
- package/dist/rules/no-implied-eval.js +152 -0
- package/dist/rules/no-import-type-side-effects.d.ts +7 -0
- package/dist/rules/no-import-type-side-effects.js +53 -0
- package/dist/rules/no-inferrable-types.d.ts +11 -0
- package/dist/rules/no-inferrable-types.js +182 -0
- package/dist/rules/no-invalid-this.d.ts +15 -0
- package/dist/rules/no-invalid-this.js +75 -0
- package/dist/rules/no-invalid-void-type.d.ts +9 -0
- package/dist/rules/no-invalid-void-type.js +210 -0
- package/dist/rules/no-loop-func.d.ts +13 -0
- package/dist/rules/no-loop-func.js +187 -0
- package/dist/rules/no-loss-of-precision.d.ts +9 -0
- package/dist/rules/no-loss-of-precision.js +35 -0
- package/dist/rules/no-magic-numbers.d.ts +29 -0
- package/dist/rules/no-magic-numbers.js +248 -0
- package/dist/rules/no-meaningless-void-operator.d.ts +10 -0
- package/dist/rules/no-meaningless-void-operator.js +102 -0
- package/dist/rules/no-misused-new.d.ts +4 -0
- package/dist/rules/no-misused-new.js +81 -0
- package/dist/rules/no-misused-promises.d.ts +21 -0
- package/dist/rules/no-misused-promises.js +765 -0
- package/dist/rules/no-misused-spread.d.ts +12 -0
- package/dist/rules/no-misused-spread.js +260 -0
- package/dist/rules/no-mixed-enums.d.ts +4 -0
- package/dist/rules/no-mixed-enums.js +200 -0
- package/dist/rules/no-namespace.d.ts +11 -0
- package/dist/rules/no-namespace.js +60 -0
- package/dist/rules/no-non-null-asserted-nullish-coalescing.d.ts +5 -0
- package/dist/rules/no-non-null-asserted-nullish-coalescing.js +73 -0
- package/dist/rules/no-non-null-asserted-optional-chain.d.ts +5 -0
- package/dist/rules/no-non-null-asserted-optional-chain.js +65 -0
- package/dist/rules/no-non-null-assertion.d.ts +6 -0
- package/dist/rules/no-non-null-assertion.js +93 -0
- package/dist/rules/no-redeclare.d.ts +12 -0
- package/dist/rules/no-redeclare.js +199 -0
- package/dist/rules/no-redundant-type-constituents.d.ts +4 -0
- package/dist/rules/no-redundant-type-constituents.js +431 -0
- package/dist/rules/no-require-imports.d.ts +11 -0
- package/dist/rules/no-require-imports.js +115 -0
- package/dist/rules/no-restricted-imports.d.ts +9 -0
- package/dist/rules/no-restricted-imports.js +243 -0
- package/dist/rules/no-restricted-types.d.ts +16 -0
- package/dist/rules/no-restricted-types.js +165 -0
- package/dist/rules/no-shadow.d.ts +16 -0
- package/dist/rules/no-shadow.js +521 -0
- package/dist/rules/no-this-alias.d.ts +11 -0
- package/dist/rules/no-this-alias.js +66 -0
- package/dist/rules/no-type-alias.d.ts +18 -0
- package/dist/rules/no-type-alias.js +268 -0
- package/dist/rules/no-unnecessary-boolean-literal-compare.d.ts +12 -0
- package/dist/rules/no-unnecessary-boolean-literal-compare.js +263 -0
- package/dist/rules/no-unnecessary-condition.d.ts +14 -0
- package/dist/rules/no-unnecessary-condition.js +675 -0
- package/dist/rules/no-unnecessary-parameter-property-assignment.d.ts +4 -0
- package/dist/rules/no-unnecessary-parameter-property-assignment.js +148 -0
- package/dist/rules/no-unnecessary-qualifier.d.ts +4 -0
- package/dist/rules/no-unnecessary-qualifier.js +156 -0
- package/dist/rules/no-unnecessary-template-expression.d.ts +6 -0
- package/dist/rules/no-unnecessary-template-expression.js +361 -0
- package/dist/rules/no-unnecessary-type-arguments.d.ts +5 -0
- package/dist/rules/no-unnecessary-type-arguments.js +197 -0
- package/dist/rules/no-unnecessary-type-assertion.d.ts +11 -0
- package/dist/rules/no-unnecessary-type-assertion.js +353 -0
- package/dist/rules/no-unnecessary-type-constraint.d.ts +5 -0
- package/dist/rules/no-unnecessary-type-constraint.js +119 -0
- package/dist/rules/no-unnecessary-type-conversion.d.ts +5 -0
- package/dist/rules/no-unnecessary-type-conversion.js +356 -0
- package/dist/rules/no-unnecessary-type-parameters.d.ts +5 -0
- package/dist/rules/no-unnecessary-type-parameters.js +422 -0
- package/dist/rules/no-unsafe-argument.d.ts +5 -0
- package/dist/rules/no-unsafe-argument.js +272 -0
- package/dist/rules/no-unsafe-assignment.d.ts +4 -0
- package/dist/rules/no-unsafe-assignment.js +322 -0
- package/dist/rules/no-unsafe-call.d.ts +5 -0
- package/dist/rules/no-unsafe-call.js +136 -0
- package/dist/rules/no-unsafe-declaration-merging.d.ts +4 -0
- package/dist/rules/no-unsafe-declaration-merging.js +54 -0
- package/dist/rules/no-unsafe-enum-comparison.d.ts +5 -0
- package/dist/rules/no-unsafe-enum-comparison.js +192 -0
- package/dist/rules/no-unsafe-function-type.d.ts +4 -0
- package/dist/rules/no-unsafe-function-type.js +45 -0
- package/dist/rules/no-unsafe-member-access.d.ts +10 -0
- package/dist/rules/no-unsafe-member-access.js +183 -0
- package/dist/rules/no-unsafe-return.d.ts +4 -0
- package/dist/rules/no-unsafe-return.js +183 -0
- package/dist/rules/no-unsafe-type-assertion.d.ts +4 -0
- package/dist/rules/no-unsafe-type-assertion.js +158 -0
- package/dist/rules/no-unsafe-unary-minus.d.ts +6 -0
- package/dist/rules/no-unsafe-unary-minus.js +78 -0
- package/dist/rules/no-unused-expressions.d.ts +19 -0
- package/dist/rules/no-unused-expressions.js +64 -0
- package/dist/rules/no-unused-private-class-members.d.ts +6 -0
- package/dist/rules/no-unused-private-class-members.js +44 -0
- package/dist/rules/no-unused-vars.d.ts +24 -0
- package/dist/rules/no-unused-vars.js +1033 -0
- package/dist/rules/no-use-before-define.d.ts +16 -0
- package/dist/rules/no-use-before-define.js +303 -0
- package/dist/rules/no-useless-constructor.d.ts +11 -0
- package/dist/rules/no-useless-constructor.js +57 -0
- package/dist/rules/no-useless-default-assignment.d.ts +11 -0
- package/dist/rules/no-useless-default-assignment.js +318 -0
- package/dist/rules/no-useless-empty-export.d.ts +4 -0
- package/dist/rules/no-useless-empty-export.js +70 -0
- package/dist/rules/no-var-requires.d.ts +10 -0
- package/dist/rules/no-var-requires.js +83 -0
- package/dist/rules/no-wrapper-object-types.d.ts +5 -0
- package/dist/rules/no-wrapper-object-types.js +60 -0
- package/dist/rules/non-nullable-type-assertion-style.d.ts +4 -0
- package/dist/rules/non-nullable-type-assertion-style.js +132 -0
- package/dist/rules/only-throw-error.d.ts +14 -0
- package/dist/rules/only-throw-error.js +158 -0
- package/dist/rules/parameter-properties.d.ts +13 -0
- package/dist/rules/parameter-properties.js +164 -0
- package/dist/rules/prefer-as-const.d.ts +5 -0
- package/dist/rules/prefer-as-const.js +72 -0
- package/dist/rules/prefer-destructuring.d.ts +19 -0
- package/dist/rules/prefer-destructuring.js +216 -0
- package/dist/rules/prefer-enum-initializers.d.ts +6 -0
- package/dist/rules/prefer-enum-initializers.js +62 -0
- package/dist/rules/prefer-find.d.ts +5 -0
- package/dist/rules/prefer-find.js +247 -0
- package/dist/rules/prefer-for-of.d.ts +5 -0
- package/dist/rules/prefer-for-of.js +115 -0
- package/dist/rules/prefer-function-type.d.ts +9 -0
- package/dist/rules/prefer-function-type.js +186 -0
- package/dist/rules/prefer-includes.d.ts +5 -0
- package/dist/rules/prefer-includes.js +242 -0
- package/dist/rules/prefer-literal-enum-member.d.ts +6 -0
- package/dist/rules/prefer-literal-enum-member.js +116 -0
- package/dist/rules/prefer-namespace-keyword.d.ts +4 -0
- package/dist/rules/prefer-namespace-keyword.js +42 -0
- package/dist/rules/prefer-nullish-coalescing.d.ts +22 -0
- package/dist/rules/prefer-nullish-coalescing.js +647 -0
- package/dist/rules/prefer-optional-chain-utils/PreferOptionalChainOptions.d.ts +11 -0
- package/dist/rules/prefer-optional-chain-utils/PreferOptionalChainOptions.js +2 -0
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.d.ts +7 -0
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +569 -0
- package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.d.ts +6 -0
- package/dist/rules/prefer-optional-chain-utils/checkNullishAndReport.js +45 -0
- package/dist/rules/prefer-optional-chain-utils/compareNodes.d.ts +15 -0
- package/dist/rules/prefer-optional-chain-utils/compareNodes.js +326 -0
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.d.ts +61 -0
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +411 -0
- package/dist/rules/prefer-optional-chain.d.ts +5 -0
- package/dist/rules/prefer-optional-chain.js +150 -0
- package/dist/rules/prefer-promise-reject-errors.d.ts +14 -0
- package/dist/rules/prefer-promise-reject-errors.js +124 -0
- package/dist/rules/prefer-readonly-parameter-types.d.ts +14 -0
- package/dist/rules/prefer-readonly-parameter-types.js +89 -0
- package/dist/rules/prefer-readonly.d.ts +10 -0
- package/dist/rules/prefer-readonly.js +439 -0
- package/dist/rules/prefer-reduce-type-parameter.d.ts +4 -0
- package/dist/rules/prefer-reduce-type-parameter.js +114 -0
- package/dist/rules/prefer-regexp-exec.d.ts +4 -0
- package/dist/rules/prefer-regexp-exec.js +178 -0
- package/dist/rules/prefer-return-this-type.d.ts +4 -0
- package/dist/rules/prefer-return-this-type.js +154 -0
- package/dist/rules/prefer-string-starts-ends-with.d.ts +12 -0
- package/dist/rules/prefer-string-starts-ends-with.js +512 -0
- package/dist/rules/prefer-ts-expect-error.d.ts +5 -0
- package/dist/rules/prefer-ts-expect-error.js +71 -0
- package/dist/rules/promise-function-async.d.ts +15 -0
- package/dist/rules/promise-function-async.js +204 -0
- package/dist/rules/related-getter-setter-pairs.d.ts +4 -0
- package/dist/rules/related-getter-setter-pairs.js +71 -0
- package/dist/rules/require-array-sort-compare.d.ts +10 -0
- package/dist/rules/require-array-sort-compare.js +63 -0
- package/dist/rules/require-await.d.ts +4 -0
- package/dist/rules/require-await.js +263 -0
- package/dist/rules/restrict-plus-operands.d.ts +15 -0
- package/dist/rules/restrict-plus-operands.js +231 -0
- package/dist/rules/restrict-template-expressions.d.ts +19 -0
- package/dist/rules/restrict-template-expressions.js +119 -0
- package/dist/rules/return-await.d.ts +5 -0
- package/dist/rules/return-await.js +363 -0
- package/dist/rules/sort-type-constituents.d.ts +14 -0
- package/dist/rules/sort-type-constituents.js +272 -0
- package/dist/rules/strict-boolean-expressions.d.ts +19 -0
- package/dist/rules/strict-boolean-expressions.js +882 -0
- package/dist/rules/strict-void-return.d.ts +10 -0
- package/dist/rules/strict-void-return.js +374 -0
- package/dist/rules/switch-exhaustiveness-check.d.ts +33 -0
- package/dist/rules/switch-exhaustiveness-check.js +291 -0
- package/dist/rules/triple-slash-reference.d.ts +12 -0
- package/dist/rules/triple-slash-reference.js +110 -0
- package/dist/rules/typedef.d.ts +16 -0
- package/dist/rules/typedef.js +239 -0
- package/dist/rules/unbound-method.d.ts +9 -0
- package/dist/rules/unbound-method.js +334 -0
- package/dist/rules/unified-signatures.d.ts +11 -0
- package/dist/rules/unified-signatures.js +465 -0
- package/dist/rules/use-unknown-in-catch-callback-variable.d.ts +6 -0
- package/dist/rules/use-unknown-in-catch-callback-variable.js +261 -0
- package/dist/util/assertionFunctionUtils.d.ts +16 -0
- package/dist/util/assertionFunctionUtils.js +116 -0
- package/dist/util/astUtils.d.ts +17 -0
- package/dist/util/astUtils.js +143 -0
- package/dist/util/baseTypeUtils.d.ts +13 -0
- package/dist/util/baseTypeUtils.js +75 -0
- package/dist/util/class-scope-analyzer/classScopeAnalyzer.d.ts +52 -0
- package/dist/util/class-scope-analyzer/classScopeAnalyzer.js +566 -0
- package/dist/util/class-scope-analyzer/extractComputedName.d.ts +17 -0
- package/dist/util/class-scope-analyzer/extractComputedName.js +70 -0
- package/dist/util/class-scope-analyzer/types.d.ts +12 -0
- package/dist/util/class-scope-analyzer/types.js +10 -0
- package/dist/util/collectUnusedVariables.d.ts +15 -0
- package/dist/util/collectUnusedVariables.js +598 -0
- package/dist/util/createRule.d.ts +5 -0
- package/dist/util/createRule.js +5 -0
- package/dist/util/escapeRegExp.d.ts +1 -0
- package/dist/util/escapeRegExp.js +14 -0
- package/dist/util/explicitReturnTypeUtils.d.ts +47 -0
- package/dist/util/explicitReturnTypeUtils.js +238 -0
- package/dist/util/getBaseTypesOfClassMember.d.ts +11 -0
- package/dist/util/getBaseTypesOfClassMember.js +31 -0
- package/dist/util/getConstraintInfo.d.ts +35 -0
- package/dist/util/getConstraintInfo.js +70 -0
- package/dist/util/getESLintCoreRule.d.ts +27 -0
- package/dist/util/getESLintCoreRule.js +16 -0
- package/dist/util/getFixOrSuggest.d.ts +9 -0
- package/dist/util/getFixOrSuggest.js +13 -0
- package/dist/util/getForStatementHeadLoc.d.ts +17 -0
- package/dist/util/getForStatementHeadLoc.js +26 -0
- package/dist/util/getFunctionHeadLoc.d.ts +101 -0
- package/dist/util/getFunctionHeadLoc.js +161 -0
- package/dist/util/getMemberHeadLoc.d.ts +36 -0
- package/dist/util/getMemberHeadLoc.js +79 -0
- package/dist/util/getOperatorPrecedence.d.ts +39 -0
- package/dist/util/getOperatorPrecedence.js +421 -0
- package/dist/util/getParentFunctionNode.d.ts +2 -0
- package/dist/util/getParentFunctionNode.js +18 -0
- package/dist/util/getStaticStringValue.d.ts +11 -0
- package/dist/util/getStaticStringValue.js +44 -0
- package/dist/util/getStringLength.d.ts +1 -0
- package/dist/util/getStringLength.js +14 -0
- package/dist/util/getTextWithParentheses.d.ts +3 -0
- package/dist/util/getTextWithParentheses.js +16 -0
- package/dist/util/getThisExpression.d.ts +2 -0
- package/dist/util/getThisExpression.js +24 -0
- package/dist/util/getValueOfLiteralType.d.ts +2 -0
- package/dist/util/getValueOfLiteralType.js +16 -0
- package/dist/util/getWrappedCode.d.ts +2 -0
- package/dist/util/getWrappedCode.js +6 -0
- package/dist/util/getWrappingFixer.d.ts +42 -0
- package/dist/util/getWrappingFixer.js +184 -0
- package/dist/util/hasOverloadSignatures.d.ts +6 -0
- package/dist/util/hasOverloadSignatures.js +47 -0
- package/dist/util/index.d.ts +40 -0
- package/dist/util/index.js +53 -0
- package/dist/util/isArrayMethodCallWithPredicate.d.ts +3 -0
- package/dist/util/isArrayMethodCallWithPredicate.js +64 -0
- package/dist/util/isAssignee.d.ts +2 -0
- package/dist/util/isAssignee.js +50 -0
- package/dist/util/isHigherPrecedenceThanAwait.d.ts +2 -0
- package/dist/util/isHigherPrecedenceThanAwait.js +46 -0
- package/dist/util/isNodeEqual.d.ts +2 -0
- package/dist/util/isNodeEqual.js +25 -0
- package/dist/util/isNullLiteral.d.ts +2 -0
- package/dist/util/isNullLiteral.js +7 -0
- package/dist/util/isPromiseAggregatorMethod.d.ts +3 -0
- package/dist/util/isPromiseAggregatorMethod.js +22 -0
- package/dist/util/isStartOfExpressionStatement.d.ts +7 -0
- package/dist/util/isStartOfExpressionStatement.js +22 -0
- package/dist/util/isTypeImport.d.ts +12 -0
- package/dist/util/isTypeImport.js +21 -0
- package/dist/util/isUndefinedIdentifier.d.ts +2 -0
- package/dist/util/isUndefinedIdentifier.js +7 -0
- package/dist/util/misc.d.ts +115 -0
- package/dist/util/misc.js +270 -0
- package/dist/util/needsPrecedingSemiColon.d.ts +11 -0
- package/dist/util/needsPrecedingSemiColon.js +97 -0
- package/dist/util/needsToBeAwaited.d.ts +7 -0
- package/dist/util/needsToBeAwaited.js +63 -0
- package/dist/util/objectIterators.d.ts +3 -0
- package/dist/util/objectIterators.js +25 -0
- package/dist/util/promiseUtils.d.ts +27 -0
- package/dist/util/promiseUtils.js +98 -0
- package/dist/util/rangeToLoc.d.ts +2 -0
- package/dist/util/rangeToLoc.js +9 -0
- package/dist/util/referenceContainsTypeQuery.d.ts +5 -0
- package/dist/util/referenceContainsTypeQuery.js +19 -0
- package/dist/util/scopeUtils.d.ts +3 -0
- package/dist/util/scopeUtils.js +10 -0
- package/dist/util/skipChainExpression.d.ts +2 -0
- package/dist/util/skipChainExpression.js +7 -0
- package/dist/util/truthinessUtils.d.ts +3 -0
- package/dist/util/truthinessUtils.js +60 -0
- package/dist/util/types.d.ts +2 -0
- package/dist/util/types.js +2 -0
- package/dist/util/walkStatements.d.ts +7 -0
- package/dist/util/walkStatements.js +56 -0
- package/index.d.ts +13 -0
- package/package.json +137 -0
- package/raw-plugin.d.ts +25 -0
- package/rules.d.ts +87 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
37
|
+
const tsutils = __importStar(require("ts-api-utils"));
|
|
38
|
+
const util_1 = require("../util");
|
|
39
|
+
const getESLintCoreRule_1 = require("../util/getESLintCoreRule");
|
|
40
|
+
const baseRule = (0, getESLintCoreRule_1.getESLintCoreRule)('prefer-destructuring');
|
|
41
|
+
const destructuringTypeConfig = {
|
|
42
|
+
type: 'object',
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
properties: {
|
|
45
|
+
array: {
|
|
46
|
+
type: 'boolean',
|
|
47
|
+
},
|
|
48
|
+
object: {
|
|
49
|
+
type: 'boolean',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const schema = [
|
|
54
|
+
{
|
|
55
|
+
oneOf: [
|
|
56
|
+
{
|
|
57
|
+
type: 'object',
|
|
58
|
+
additionalProperties: false,
|
|
59
|
+
properties: {
|
|
60
|
+
AssignmentExpression: destructuringTypeConfig,
|
|
61
|
+
VariableDeclarator: destructuringTypeConfig,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
destructuringTypeConfig,
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: 'object',
|
|
69
|
+
additionalProperties: false,
|
|
70
|
+
properties: {
|
|
71
|
+
enforceForDeclarationWithTypeAnnotation: {
|
|
72
|
+
type: 'boolean',
|
|
73
|
+
description: 'Whether to enforce destructuring on variable declarations with type annotations.',
|
|
74
|
+
},
|
|
75
|
+
enforceForRenamedProperties: {
|
|
76
|
+
type: 'boolean',
|
|
77
|
+
description: 'Whether to enforce destructuring that use a different variable name than the property name.',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
exports.default = (0, util_1.createRule)({
|
|
83
|
+
name: 'prefer-destructuring',
|
|
84
|
+
meta: {
|
|
85
|
+
type: 'suggestion',
|
|
86
|
+
// defaultOptions, -- base rule does not use defaultOptions
|
|
87
|
+
docs: {
|
|
88
|
+
description: 'Require destructuring from arrays and/or objects',
|
|
89
|
+
extendsBaseRule: true,
|
|
90
|
+
frozen: true,
|
|
91
|
+
requiresTypeChecking: true,
|
|
92
|
+
},
|
|
93
|
+
fixable: baseRule.meta.fixable,
|
|
94
|
+
hasSuggestions: baseRule.meta.hasSuggestions,
|
|
95
|
+
messages: baseRule.meta.messages,
|
|
96
|
+
schema,
|
|
97
|
+
},
|
|
98
|
+
defaultOptions: [
|
|
99
|
+
{
|
|
100
|
+
AssignmentExpression: {
|
|
101
|
+
array: true,
|
|
102
|
+
object: true,
|
|
103
|
+
},
|
|
104
|
+
VariableDeclarator: {
|
|
105
|
+
array: true,
|
|
106
|
+
object: true,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{},
|
|
110
|
+
],
|
|
111
|
+
create(context, [enabledTypes, options]) {
|
|
112
|
+
const { enforceForDeclarationWithTypeAnnotation = false, enforceForRenamedProperties = false, } = options;
|
|
113
|
+
const { esTreeNodeToTSNodeMap, program } = (0, util_1.getParserServices)(context);
|
|
114
|
+
const typeChecker = program.getTypeChecker();
|
|
115
|
+
const baseRules = baseRule.create(context);
|
|
116
|
+
let baseRulesWithoutFixCache = null;
|
|
117
|
+
return {
|
|
118
|
+
AssignmentExpression(node) {
|
|
119
|
+
if (node.operator !== '=') {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
performCheck(node.left, node.right, node);
|
|
123
|
+
},
|
|
124
|
+
VariableDeclarator(node) {
|
|
125
|
+
performCheck(node.id, node.init, node);
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
function performCheck(leftNode, rightNode, reportNode) {
|
|
129
|
+
const rules = leftNode.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
130
|
+
leftNode.typeAnnotation == null
|
|
131
|
+
? baseRules
|
|
132
|
+
: baseRulesWithoutFix();
|
|
133
|
+
if ((leftNode.type === utils_1.AST_NODE_TYPES.ArrayPattern ||
|
|
134
|
+
leftNode.type === utils_1.AST_NODE_TYPES.Identifier ||
|
|
135
|
+
leftNode.type === utils_1.AST_NODE_TYPES.ObjectPattern) &&
|
|
136
|
+
leftNode.typeAnnotation != null &&
|
|
137
|
+
!enforceForDeclarationWithTypeAnnotation) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (rightNode != null &&
|
|
141
|
+
isArrayLiteralIntegerIndexAccess(rightNode) &&
|
|
142
|
+
rightNode.object.type !== utils_1.AST_NODE_TYPES.Super) {
|
|
143
|
+
const tsObj = esTreeNodeToTSNodeMap.get(rightNode.object);
|
|
144
|
+
const objType = typeChecker.getTypeAtLocation(tsObj);
|
|
145
|
+
if (!isTypeAnyOrIterableType(objType, typeChecker)) {
|
|
146
|
+
if (!enforceForRenamedProperties ||
|
|
147
|
+
!getNormalizedEnabledType(reportNode.type, 'object')) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
context.report({
|
|
151
|
+
node: reportNode,
|
|
152
|
+
messageId: 'preferDestructuring',
|
|
153
|
+
data: { type: 'object' },
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (reportNode.type === utils_1.AST_NODE_TYPES.AssignmentExpression) {
|
|
159
|
+
rules.AssignmentExpression(reportNode);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
rules.VariableDeclarator(reportNode);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function getNormalizedEnabledType(nodeType, destructuringType) {
|
|
166
|
+
if ('object' in enabledTypes || 'array' in enabledTypes) {
|
|
167
|
+
return enabledTypes[destructuringType];
|
|
168
|
+
}
|
|
169
|
+
return enabledTypes[nodeType][destructuringType];
|
|
170
|
+
}
|
|
171
|
+
function baseRulesWithoutFix() {
|
|
172
|
+
baseRulesWithoutFixCache ??= baseRule.create(noFixContext(context));
|
|
173
|
+
return baseRulesWithoutFixCache;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
function noFixContext(context) {
|
|
178
|
+
const customContext = {
|
|
179
|
+
report: (descriptor) => {
|
|
180
|
+
context.report({
|
|
181
|
+
...descriptor,
|
|
182
|
+
fix: undefined,
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
// we can't directly proxy `context` because its `report` property is non-configurable
|
|
187
|
+
// and non-writable. So we proxy `customContext` and redirect all
|
|
188
|
+
// property access to the original context except for `report`
|
|
189
|
+
return new Proxy(customContext, {
|
|
190
|
+
get(target, path, receiver) {
|
|
191
|
+
if (path !== 'report') {
|
|
192
|
+
return Reflect.get(context, path, receiver);
|
|
193
|
+
}
|
|
194
|
+
return Reflect.get(target, path, receiver);
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function isTypeAnyOrIterableType(type, typeChecker) {
|
|
199
|
+
if ((0, util_1.isTypeAnyType)(type)) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
if (!type.isUnion()) {
|
|
203
|
+
const iterator = tsutils.getWellKnownSymbolPropertyOfType(type, 'iterator', typeChecker);
|
|
204
|
+
return iterator != null;
|
|
205
|
+
}
|
|
206
|
+
return type.types.every(t => isTypeAnyOrIterableType(t, typeChecker));
|
|
207
|
+
}
|
|
208
|
+
function isArrayLiteralIntegerIndexAccess(node) {
|
|
209
|
+
if (node.type !== utils_1.AST_NODE_TYPES.MemberExpression) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
if (node.property.type !== utils_1.AST_NODE_TYPES.Literal) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return Number.isInteger(node.property.value);
|
|
216
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
export type MessageIds = 'defineInitializer' | 'defineInitializerSuggestion';
|
|
3
|
+
declare const _default: TSESLint.RuleModule<MessageIds, [], import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("../util");
|
|
4
|
+
exports.default = (0, util_1.createRule)({
|
|
5
|
+
name: 'prefer-enum-initializers',
|
|
6
|
+
meta: {
|
|
7
|
+
type: 'suggestion',
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'Require each enum member value to be explicitly initialized',
|
|
10
|
+
},
|
|
11
|
+
hasSuggestions: true,
|
|
12
|
+
messages: {
|
|
13
|
+
defineInitializer: "The value of the member '{{ name }}' should be explicitly defined.",
|
|
14
|
+
defineInitializerSuggestion: 'Can be fixed to {{ name }} = {{ suggested }}',
|
|
15
|
+
},
|
|
16
|
+
schema: [],
|
|
17
|
+
},
|
|
18
|
+
defaultOptions: [],
|
|
19
|
+
create(context) {
|
|
20
|
+
function TSEnumDeclaration(node) {
|
|
21
|
+
const { members } = node.body;
|
|
22
|
+
members.forEach((member, index) => {
|
|
23
|
+
if (member.initializer == null) {
|
|
24
|
+
const name = context.sourceCode.getText(member);
|
|
25
|
+
context.report({
|
|
26
|
+
node: member,
|
|
27
|
+
messageId: 'defineInitializer',
|
|
28
|
+
data: {
|
|
29
|
+
name,
|
|
30
|
+
},
|
|
31
|
+
suggest: [
|
|
32
|
+
{
|
|
33
|
+
messageId: 'defineInitializerSuggestion',
|
|
34
|
+
data: { name, suggested: index },
|
|
35
|
+
fix: (fixer) => {
|
|
36
|
+
return fixer.replaceText(member, `${name} = ${index}`);
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
messageId: 'defineInitializerSuggestion',
|
|
41
|
+
data: { name, suggested: index + 1 },
|
|
42
|
+
fix: (fixer) => {
|
|
43
|
+
return fixer.replaceText(member, `${name} = ${index + 1}`);
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
messageId: 'defineInitializerSuggestion',
|
|
48
|
+
data: { name, suggested: `'${name}'` },
|
|
49
|
+
fix: (fixer) => {
|
|
50
|
+
return fixer.replaceText(member, `${name} = '${name}'`);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
TSEnumDeclaration,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
});
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
37
|
+
const tsutils = __importStar(require("ts-api-utils"));
|
|
38
|
+
const util_1 = require("../util");
|
|
39
|
+
exports.default = (0, util_1.createRule)({
|
|
40
|
+
name: 'prefer-find',
|
|
41
|
+
meta: {
|
|
42
|
+
type: 'suggestion',
|
|
43
|
+
docs: {
|
|
44
|
+
description: 'Enforce the use of Array.prototype.find() over Array.prototype.filter() followed by [0] when looking for a single result',
|
|
45
|
+
recommended: 'stylistic',
|
|
46
|
+
requiresTypeChecking: true,
|
|
47
|
+
},
|
|
48
|
+
hasSuggestions: true,
|
|
49
|
+
messages: {
|
|
50
|
+
preferFind: 'Prefer .find(...) instead of .filter(...)[0].',
|
|
51
|
+
preferFindSuggestion: 'Use .find(...) instead of .filter(...)[0].',
|
|
52
|
+
},
|
|
53
|
+
schema: [],
|
|
54
|
+
},
|
|
55
|
+
defaultOptions: [],
|
|
56
|
+
create(context) {
|
|
57
|
+
const globalScope = context.sourceCode.getScope(context.sourceCode.ast);
|
|
58
|
+
const services = (0, util_1.getParserServices)(context);
|
|
59
|
+
const checker = services.program.getTypeChecker();
|
|
60
|
+
function parseArrayFilterExpressions(expression) {
|
|
61
|
+
const node = (0, util_1.skipChainExpression)(expression);
|
|
62
|
+
if (node.type === utils_1.AST_NODE_TYPES.SequenceExpression) {
|
|
63
|
+
// Only the last expression in (a, b, [1, 2, 3].filter(condition))[0] matters
|
|
64
|
+
const lastExpression = (0, util_1.nullThrows)(node.expressions.at(-1), 'Expected to have more than zero expressions in a sequence expression');
|
|
65
|
+
return parseArrayFilterExpressions(lastExpression);
|
|
66
|
+
}
|
|
67
|
+
// This is the only reason we're returning a list rather than a single value.
|
|
68
|
+
if (node.type === utils_1.AST_NODE_TYPES.ConditionalExpression) {
|
|
69
|
+
// Both branches of the ternary _must_ return results.
|
|
70
|
+
const consequentResult = parseArrayFilterExpressions(node.consequent);
|
|
71
|
+
if (consequentResult.length === 0) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const alternateResult = parseArrayFilterExpressions(node.alternate);
|
|
75
|
+
if (alternateResult.length === 0) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
// Accumulate the results from both sides and pass up the chain.
|
|
79
|
+
return [...consequentResult, ...alternateResult];
|
|
80
|
+
}
|
|
81
|
+
// Check if it looks like <<stuff>>(...), but not <<stuff>>?.(...)
|
|
82
|
+
if (node.type === utils_1.AST_NODE_TYPES.CallExpression && !node.optional) {
|
|
83
|
+
const callee = node.callee;
|
|
84
|
+
// Check if it looks like <<stuff>>.filter(...) or <<stuff>>['filter'](...),
|
|
85
|
+
// or the optional chaining variants.
|
|
86
|
+
if (callee.type === utils_1.AST_NODE_TYPES.MemberExpression) {
|
|
87
|
+
const isBracketSyntaxForFilter = callee.computed;
|
|
88
|
+
if ((0, util_1.isStaticMemberAccessOfValue)(callee, context, 'filter')) {
|
|
89
|
+
const filterNode = callee.property;
|
|
90
|
+
const filteredObjectType = (0, util_1.getConstrainedTypeAtLocation)(services, callee.object);
|
|
91
|
+
// As long as the object is a (possibly nullable) array,
|
|
92
|
+
// this is an Array.prototype.filter expression.
|
|
93
|
+
if (isArrayish(filteredObjectType)) {
|
|
94
|
+
return [
|
|
95
|
+
{
|
|
96
|
+
filterNode,
|
|
97
|
+
isBracketSyntaxForFilter,
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// not a filter expression.
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Tells whether the type is a possibly nullable array/tuple or union thereof.
|
|
109
|
+
*/
|
|
110
|
+
function isArrayish(type) {
|
|
111
|
+
let isAtLeastOneArrayishComponent = false;
|
|
112
|
+
for (const unionPart of tsutils.unionConstituents(type)) {
|
|
113
|
+
if (tsutils.isIntrinsicNullType(unionPart) ||
|
|
114
|
+
tsutils.isIntrinsicUndefinedType(unionPart)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// apparently checker.isArrayType(T[] & S[]) => false.
|
|
118
|
+
// so we need to check the intersection parts individually.
|
|
119
|
+
const isArrayOrIntersectionThereof = tsutils
|
|
120
|
+
.intersectionConstituents(unionPart)
|
|
121
|
+
.every(intersectionPart => checker.isArrayType(intersectionPart) ||
|
|
122
|
+
checker.isTupleType(intersectionPart));
|
|
123
|
+
if (!isArrayOrIntersectionThereof) {
|
|
124
|
+
// There is a non-array, non-nullish type component,
|
|
125
|
+
// so it's not an array.
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
isAtLeastOneArrayishComponent = true;
|
|
129
|
+
}
|
|
130
|
+
return isAtLeastOneArrayishComponent;
|
|
131
|
+
}
|
|
132
|
+
function getObjectIfArrayAtZeroExpression(node) {
|
|
133
|
+
// .at() should take exactly one argument.
|
|
134
|
+
if (node.arguments.length !== 1) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const callee = node.callee;
|
|
138
|
+
if (callee.type === utils_1.AST_NODE_TYPES.MemberExpression &&
|
|
139
|
+
!callee.optional &&
|
|
140
|
+
(0, util_1.isStaticMemberAccessOfValue)(callee, context, 'at')) {
|
|
141
|
+
const atArgument = (0, util_1.getStaticValue)(node.arguments[0], globalScope);
|
|
142
|
+
if (atArgument != null && isTreatedAsZeroByArrayAt(atArgument.value)) {
|
|
143
|
+
return callee.object;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Implements the algorithm for array indexing by `.at()` method.
|
|
150
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at#parameters
|
|
151
|
+
*/
|
|
152
|
+
function isTreatedAsZeroByArrayAt(value) {
|
|
153
|
+
// This would cause the number constructor coercion to throw. Other static
|
|
154
|
+
// values are safe.
|
|
155
|
+
if (typeof value === 'symbol') {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const asNumber = Number(value);
|
|
159
|
+
if (isNaN(asNumber)) {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
return Math.trunc(asNumber) === 0;
|
|
163
|
+
}
|
|
164
|
+
function isMemberAccessOfZero(node) {
|
|
165
|
+
const property = (0, util_1.getStaticValue)(node.property, globalScope);
|
|
166
|
+
// Check if it looks like <<stuff>>[0] or <<stuff>>['0'], but not <<stuff>>?.[0]
|
|
167
|
+
return (!node.optional &&
|
|
168
|
+
property != null &&
|
|
169
|
+
isTreatedAsZeroByMemberAccess(property.value));
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Implements the algorithm for array indexing by member operator.
|
|
173
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#array_indices
|
|
174
|
+
*/
|
|
175
|
+
function isTreatedAsZeroByMemberAccess(value) {
|
|
176
|
+
return String(value) === '0';
|
|
177
|
+
}
|
|
178
|
+
function generateFixToRemoveArrayElementAccess(fixer, arrayNode, wholeExpressionBeingFlagged) {
|
|
179
|
+
const tokenToStartDeletingFrom = (0, util_1.nullThrows)(
|
|
180
|
+
// The next `.` or `[` is what we're looking for.
|
|
181
|
+
// think of (...).at(0) or (...)[0] or even (...)["at"](0).
|
|
182
|
+
context.sourceCode.getTokenAfter(arrayNode, token => token.value === '.' || token.value === '['), 'Expected to find a member access token!');
|
|
183
|
+
return fixer.removeRange([
|
|
184
|
+
tokenToStartDeletingFrom.range[0],
|
|
185
|
+
wholeExpressionBeingFlagged.range[1],
|
|
186
|
+
]);
|
|
187
|
+
}
|
|
188
|
+
function generateFixToReplaceFilterWithFind(fixer, filterExpression) {
|
|
189
|
+
return fixer.replaceText(filterExpression.filterNode, filterExpression.isBracketSyntaxForFilter ? '"find"' : 'find');
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
// This query will be used to find things like `filteredResults.at(0)`.
|
|
193
|
+
CallExpression(node) {
|
|
194
|
+
const object = getObjectIfArrayAtZeroExpression(node);
|
|
195
|
+
if (object) {
|
|
196
|
+
const filterExpressions = parseArrayFilterExpressions(object);
|
|
197
|
+
if (filterExpressions.length !== 0) {
|
|
198
|
+
context.report({
|
|
199
|
+
node,
|
|
200
|
+
messageId: 'preferFind',
|
|
201
|
+
suggest: [
|
|
202
|
+
{
|
|
203
|
+
messageId: 'preferFindSuggestion',
|
|
204
|
+
fix: (fixer) => {
|
|
205
|
+
return [
|
|
206
|
+
...filterExpressions.map(filterExpression => generateFixToReplaceFilterWithFind(fixer, filterExpression)),
|
|
207
|
+
// Get rid of the .at(0) or ['at'](0).
|
|
208
|
+
generateFixToRemoveArrayElementAccess(fixer, object, node),
|
|
209
|
+
];
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
// This query will be used to find things like `filteredResults[0]`.
|
|
218
|
+
//
|
|
219
|
+
// Note: we're always looking for array member access to be "computed",
|
|
220
|
+
// i.e. `filteredResults[0]`, since `filteredResults.0` isn't a thing.
|
|
221
|
+
'MemberExpression[computed=true]'(node) {
|
|
222
|
+
if (isMemberAccessOfZero(node)) {
|
|
223
|
+
const object = node.object;
|
|
224
|
+
const filterExpressions = parseArrayFilterExpressions(object);
|
|
225
|
+
if (filterExpressions.length !== 0) {
|
|
226
|
+
context.report({
|
|
227
|
+
node,
|
|
228
|
+
messageId: 'preferFind',
|
|
229
|
+
suggest: [
|
|
230
|
+
{
|
|
231
|
+
messageId: 'preferFindSuggestion',
|
|
232
|
+
fix: (fixer) => {
|
|
233
|
+
return [
|
|
234
|
+
...filterExpressions.map(filterExpression => generateFixToReplaceFilterWithFind(fixer, filterExpression)),
|
|
235
|
+
// Get rid of the [0].
|
|
236
|
+
generateFixToRemoveArrayElementAccess(fixer, object, node),
|
|
237
|
+
];
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
},
|
|
247
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
const util_1 = require("../util");
|
|
5
|
+
exports.default = (0, util_1.createRule)({
|
|
6
|
+
name: 'prefer-for-of',
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'suggestion',
|
|
9
|
+
docs: {
|
|
10
|
+
description: 'Enforce the use of `for-of` loop over the standard `for` loop where possible',
|
|
11
|
+
recommended: 'stylistic',
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
preferForOf: 'Expected a `for-of` loop instead of a `for` loop with this simple iteration.',
|
|
15
|
+
},
|
|
16
|
+
schema: [],
|
|
17
|
+
},
|
|
18
|
+
defaultOptions: [],
|
|
19
|
+
create(context) {
|
|
20
|
+
function isSingleVariableDeclaration(node) {
|
|
21
|
+
return (node?.type === utils_1.AST_NODE_TYPES.VariableDeclaration &&
|
|
22
|
+
node.kind !== 'const' &&
|
|
23
|
+
node.declarations.length === 1);
|
|
24
|
+
}
|
|
25
|
+
function isLiteral(node, value) {
|
|
26
|
+
return node.type === utils_1.AST_NODE_TYPES.Literal && node.value === value;
|
|
27
|
+
}
|
|
28
|
+
function isZeroInitialized(node) {
|
|
29
|
+
return node.init != null && isLiteral(node.init, 0);
|
|
30
|
+
}
|
|
31
|
+
function isMatchingIdentifier(node, name) {
|
|
32
|
+
return node.type === utils_1.AST_NODE_TYPES.Identifier && node.name === name;
|
|
33
|
+
}
|
|
34
|
+
function isLessThanLengthExpression(node, name) {
|
|
35
|
+
if (node?.type === utils_1.AST_NODE_TYPES.BinaryExpression &&
|
|
36
|
+
node.operator === '<' &&
|
|
37
|
+
isMatchingIdentifier(node.left, name) &&
|
|
38
|
+
node.right.type === utils_1.AST_NODE_TYPES.MemberExpression &&
|
|
39
|
+
isMatchingIdentifier(node.right.property, 'length')) {
|
|
40
|
+
return node.right.object;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
function isIncrement(node, name) {
|
|
45
|
+
if (!node) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
switch (node.type) {
|
|
49
|
+
case utils_1.AST_NODE_TYPES.UpdateExpression:
|
|
50
|
+
// x++ or ++x
|
|
51
|
+
return (node.operator === '++' && isMatchingIdentifier(node.argument, name));
|
|
52
|
+
case utils_1.AST_NODE_TYPES.AssignmentExpression:
|
|
53
|
+
if (isMatchingIdentifier(node.left, name)) {
|
|
54
|
+
if (node.operator === '+=') {
|
|
55
|
+
// x += 1
|
|
56
|
+
return isLiteral(node.right, 1);
|
|
57
|
+
}
|
|
58
|
+
if (node.operator === '=') {
|
|
59
|
+
// x = x + 1 or x = 1 + x
|
|
60
|
+
const expr = node.right;
|
|
61
|
+
return (expr.type === utils_1.AST_NODE_TYPES.BinaryExpression &&
|
|
62
|
+
expr.operator === '+' &&
|
|
63
|
+
((isMatchingIdentifier(expr.left, name) &&
|
|
64
|
+
isLiteral(expr.right, 1)) ||
|
|
65
|
+
(isLiteral(expr.left, 1) &&
|
|
66
|
+
isMatchingIdentifier(expr.right, name))));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
function contains(outer, inner) {
|
|
73
|
+
return (outer.range[0] <= inner.range[0] && outer.range[1] >= inner.range[1]);
|
|
74
|
+
}
|
|
75
|
+
function isIndexOnlyUsedWithArray(body, indexVar, arrayExpression) {
|
|
76
|
+
const arrayText = context.sourceCode.getText(arrayExpression);
|
|
77
|
+
return indexVar.references.every(reference => {
|
|
78
|
+
const id = reference.identifier;
|
|
79
|
+
const node = id.parent;
|
|
80
|
+
return (!contains(body, id) ||
|
|
81
|
+
(node.type === utils_1.AST_NODE_TYPES.MemberExpression &&
|
|
82
|
+
node.object.type !== utils_1.AST_NODE_TYPES.ThisExpression &&
|
|
83
|
+
node.property === id &&
|
|
84
|
+
context.sourceCode.getText(node.object) === arrayText &&
|
|
85
|
+
!(0, util_1.isAssignee)(node)));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
'ForStatement:exit'(node) {
|
|
90
|
+
if (!isSingleVariableDeclaration(node.init)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const declarator = node.init.declarations[0];
|
|
94
|
+
if (!declarator ||
|
|
95
|
+
!isZeroInitialized(declarator) ||
|
|
96
|
+
declarator.id.type !== utils_1.AST_NODE_TYPES.Identifier) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const indexName = declarator.id.name;
|
|
100
|
+
const arrayExpression = isLessThanLengthExpression(node.test, indexName);
|
|
101
|
+
if (!arrayExpression) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const [indexVar] = context.sourceCode.getDeclaredVariables(node.init);
|
|
105
|
+
if (isIncrement(node.update, indexName) &&
|
|
106
|
+
isIndexOnlyUsedWithArray(node.body, indexVar, arrayExpression)) {
|
|
107
|
+
context.report({
|
|
108
|
+
node,
|
|
109
|
+
messageId: 'preferForOf',
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
export declare const phrases: {
|
|
3
|
+
readonly TSInterfaceDeclaration: "Interface";
|
|
4
|
+
readonly TSTypeLiteral: "Type literal";
|
|
5
|
+
};
|
|
6
|
+
declare const _default: TSESLint.RuleModule<"functionTypeOverCallableType" | "unexpectedThisOnFunctionOnlyInterface", [], import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|