@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,5 @@
|
|
|
1
|
+
export type MessageIds = 'unnecessaryTypeParameter';
|
|
2
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"unnecessaryTypeParameter", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
3
|
+
name: string;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,197 @@
|
|
|
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 ts = __importStar(require("typescript"));
|
|
39
|
+
const util_1 = require("../util");
|
|
40
|
+
exports.default = (0, util_1.createRule)({
|
|
41
|
+
name: 'no-unnecessary-type-arguments',
|
|
42
|
+
meta: {
|
|
43
|
+
type: 'suggestion',
|
|
44
|
+
docs: {
|
|
45
|
+
description: 'Disallow type arguments that are equal to the default',
|
|
46
|
+
recommended: 'strict',
|
|
47
|
+
requiresTypeChecking: true,
|
|
48
|
+
},
|
|
49
|
+
fixable: 'code',
|
|
50
|
+
messages: {
|
|
51
|
+
unnecessaryTypeParameter: 'This is the default value for this type parameter, so it can be omitted.',
|
|
52
|
+
},
|
|
53
|
+
schema: [],
|
|
54
|
+
},
|
|
55
|
+
defaultOptions: [],
|
|
56
|
+
create(context) {
|
|
57
|
+
const services = (0, util_1.getParserServices)(context);
|
|
58
|
+
const checker = services.program.getTypeChecker();
|
|
59
|
+
function getTypeForComparison(type) {
|
|
60
|
+
if ((0, util_1.isTypeReferenceType)(type)) {
|
|
61
|
+
return {
|
|
62
|
+
type: type.target,
|
|
63
|
+
typeArguments: checker.getTypeArguments(type),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
type,
|
|
68
|
+
typeArguments: [],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function checkTSArgsAndParameters(esParameters, typeParameters) {
|
|
72
|
+
// Just check the last one. Must specify previous type parameters if the last one is specified.
|
|
73
|
+
const i = esParameters.params.length - 1;
|
|
74
|
+
const arg = esParameters.params[i];
|
|
75
|
+
const param = typeParameters.at(i);
|
|
76
|
+
if (!param?.default) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// TODO: would like checker.areTypesEquivalent. https://github.com/Microsoft/TypeScript/issues/13502
|
|
80
|
+
const defaultType = checker.getTypeAtLocation(param.default);
|
|
81
|
+
const argType = services.getTypeAtLocation(arg);
|
|
82
|
+
// this check should handle some of the most simple cases of like strings, numbers, etc
|
|
83
|
+
if (defaultType !== argType) {
|
|
84
|
+
// For more complex types (like aliases to generic object types) - TS won't always create a
|
|
85
|
+
// global shared type object for the type - so we need to resort to manually comparing the
|
|
86
|
+
// reference type and the passed type arguments.
|
|
87
|
+
// Also - in case there are aliases - we need to resolve them before we do checks
|
|
88
|
+
const defaultTypeResolved = getTypeForComparison(defaultType);
|
|
89
|
+
const argTypeResolved = getTypeForComparison(argType);
|
|
90
|
+
if (
|
|
91
|
+
// ensure the resolved type AND all the parameters are the same
|
|
92
|
+
defaultTypeResolved.type !== argTypeResolved.type ||
|
|
93
|
+
defaultTypeResolved.typeArguments.length !==
|
|
94
|
+
argTypeResolved.typeArguments.length ||
|
|
95
|
+
defaultTypeResolved.typeArguments.some((t, i) => t !== argTypeResolved.typeArguments[i])) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
context.report({
|
|
100
|
+
node: arg,
|
|
101
|
+
messageId: 'unnecessaryTypeParameter',
|
|
102
|
+
fix: fixer => fixer.removeRange(i === 0
|
|
103
|
+
? esParameters.range
|
|
104
|
+
: [esParameters.params[i - 1].range[1], arg.range[1]]),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
TSTypeParameterInstantiation(node) {
|
|
109
|
+
const expression = services.esTreeNodeToTSNodeMap.get(node);
|
|
110
|
+
const typeParameters = getTypeParametersFromNode(node, expression, checker);
|
|
111
|
+
if (typeParameters) {
|
|
112
|
+
checkTSArgsAndParameters(node, typeParameters);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
function getTypeParametersFromNode(node, tsNode, checker) {
|
|
119
|
+
if (ts.isExpressionWithTypeArguments(tsNode)) {
|
|
120
|
+
return getTypeParametersFromType(node, tsNode.expression, checker);
|
|
121
|
+
}
|
|
122
|
+
if (ts.isTypeReferenceNode(tsNode)) {
|
|
123
|
+
return getTypeParametersFromType(node, tsNode.typeName, checker);
|
|
124
|
+
}
|
|
125
|
+
if (ts.isCallExpression(tsNode) ||
|
|
126
|
+
ts.isNewExpression(tsNode) ||
|
|
127
|
+
ts.isTaggedTemplateExpression(tsNode) ||
|
|
128
|
+
ts.isJsxOpeningElement(tsNode) ||
|
|
129
|
+
ts.isJsxSelfClosingElement(tsNode)) {
|
|
130
|
+
return getTypeParametersFromCall(node, tsNode, checker);
|
|
131
|
+
}
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
function getTypeParametersFromType(node, type, checker) {
|
|
135
|
+
const symAtLocation = checker.getSymbolAtLocation(type);
|
|
136
|
+
if (!symAtLocation) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
const sym = getAliasedSymbol(symAtLocation, checker);
|
|
140
|
+
const declarations = sym.getDeclarations();
|
|
141
|
+
if (!declarations) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
const sortedDeclarations = sortDeclarationsByTypeValueContext(node, declarations);
|
|
145
|
+
return (0, util_1.findFirstResult)(sortedDeclarations, decl => {
|
|
146
|
+
if (ts.isTypeAliasDeclaration(decl) ||
|
|
147
|
+
ts.isInterfaceDeclaration(decl) ||
|
|
148
|
+
ts.isClassLike(decl)) {
|
|
149
|
+
return decl.typeParameters;
|
|
150
|
+
}
|
|
151
|
+
if (ts.isVariableDeclaration(decl)) {
|
|
152
|
+
return getConstructSignatureDeclaration(symAtLocation, checker)
|
|
153
|
+
?.typeParameters;
|
|
154
|
+
}
|
|
155
|
+
return undefined;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function getTypeParametersFromCall(node, tsNode, checker) {
|
|
159
|
+
const sig = checker.getResolvedSignature(tsNode);
|
|
160
|
+
const sigDecl = sig?.getDeclaration();
|
|
161
|
+
if (!sigDecl) {
|
|
162
|
+
return ts.isNewExpression(tsNode)
|
|
163
|
+
? getTypeParametersFromType(node, tsNode.expression, checker)
|
|
164
|
+
: undefined;
|
|
165
|
+
}
|
|
166
|
+
return sigDecl.typeParameters;
|
|
167
|
+
}
|
|
168
|
+
function getAliasedSymbol(symbol, checker) {
|
|
169
|
+
return tsutils.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)
|
|
170
|
+
? checker.getAliasedSymbol(symbol)
|
|
171
|
+
: symbol;
|
|
172
|
+
}
|
|
173
|
+
function isInTypeContext(node) {
|
|
174
|
+
return (node.parent.type === utils_1.AST_NODE_TYPES.TSInterfaceHeritage ||
|
|
175
|
+
node.parent.type === utils_1.AST_NODE_TYPES.TSTypeReference ||
|
|
176
|
+
node.parent.type === utils_1.AST_NODE_TYPES.TSClassImplements);
|
|
177
|
+
}
|
|
178
|
+
function isTypeContextDeclaration(decl) {
|
|
179
|
+
return ts.isTypeAliasDeclaration(decl) || ts.isInterfaceDeclaration(decl);
|
|
180
|
+
}
|
|
181
|
+
function typeFirstCompare(declA, declB) {
|
|
182
|
+
const aIsType = isTypeContextDeclaration(declA);
|
|
183
|
+
const bIsType = isTypeContextDeclaration(declB);
|
|
184
|
+
return Number(bIsType) - Number(aIsType);
|
|
185
|
+
}
|
|
186
|
+
function sortDeclarationsByTypeValueContext(node, declarations) {
|
|
187
|
+
const sorted = [...declarations].sort(typeFirstCompare);
|
|
188
|
+
if (isInTypeContext(node)) {
|
|
189
|
+
return sorted;
|
|
190
|
+
}
|
|
191
|
+
return sorted.reverse();
|
|
192
|
+
}
|
|
193
|
+
function getConstructSignatureDeclaration(symbol, checker) {
|
|
194
|
+
const type = checker.getTypeOfSymbol(symbol);
|
|
195
|
+
const sig = type.getConstructSignatures();
|
|
196
|
+
return sig.at(0)?.getDeclaration();
|
|
197
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Options = [
|
|
2
|
+
{
|
|
3
|
+
checkLiteralConstAssertions?: boolean;
|
|
4
|
+
typesToIgnore?: string[];
|
|
5
|
+
}
|
|
6
|
+
];
|
|
7
|
+
export type MessageIds = 'contextuallyUnnecessary' | 'unnecessaryAssertion';
|
|
8
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,353 @@
|
|
|
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 ts = __importStar(require("typescript"));
|
|
39
|
+
const util_1 = require("../util");
|
|
40
|
+
exports.default = (0, util_1.createRule)({
|
|
41
|
+
name: 'no-unnecessary-type-assertion',
|
|
42
|
+
meta: {
|
|
43
|
+
type: 'suggestion',
|
|
44
|
+
docs: {
|
|
45
|
+
description: 'Disallow type assertions that do not change the type of an expression',
|
|
46
|
+
recommended: 'recommended',
|
|
47
|
+
requiresTypeChecking: true,
|
|
48
|
+
},
|
|
49
|
+
fixable: 'code',
|
|
50
|
+
messages: {
|
|
51
|
+
contextuallyUnnecessary: 'This assertion is unnecessary since the receiver accepts the original type of the expression.',
|
|
52
|
+
unnecessaryAssertion: 'This assertion is unnecessary since it does not change the type of the expression.',
|
|
53
|
+
},
|
|
54
|
+
schema: [
|
|
55
|
+
{
|
|
56
|
+
type: 'object',
|
|
57
|
+
additionalProperties: false,
|
|
58
|
+
properties: {
|
|
59
|
+
checkLiteralConstAssertions: {
|
|
60
|
+
type: 'boolean',
|
|
61
|
+
description: 'Whether to check literal const assertions.',
|
|
62
|
+
},
|
|
63
|
+
typesToIgnore: {
|
|
64
|
+
type: 'array',
|
|
65
|
+
description: 'A list of type names to ignore.',
|
|
66
|
+
items: {
|
|
67
|
+
type: 'string',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
defaultOptions: [{}],
|
|
75
|
+
create(context, [options]) {
|
|
76
|
+
const services = (0, util_1.getParserServices)(context);
|
|
77
|
+
const checker = services.program.getTypeChecker();
|
|
78
|
+
const compilerOptions = services.program.getCompilerOptions();
|
|
79
|
+
/**
|
|
80
|
+
* Returns true if there's a chance the variable has been used before a value has been assigned to it
|
|
81
|
+
*/
|
|
82
|
+
function isPossiblyUsedBeforeAssigned(node) {
|
|
83
|
+
const declaration = (0, util_1.getDeclaration)(services, node);
|
|
84
|
+
if (!declaration) {
|
|
85
|
+
// don't know what the declaration is for some reason, so just assume the worst
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if (
|
|
89
|
+
// non-strict mode doesn't care about used before assigned errors
|
|
90
|
+
tsutils.isStrictCompilerOptionEnabled(compilerOptions, 'strictNullChecks') &&
|
|
91
|
+
// ignore class properties as they are compile time guarded
|
|
92
|
+
// also ignore function arguments as they can't be used before defined
|
|
93
|
+
ts.isVariableDeclaration(declaration)) {
|
|
94
|
+
// For var declarations, we need to check whether the node
|
|
95
|
+
// is actually in a descendant of its declaration or not. If not,
|
|
96
|
+
// it may be used before defined.
|
|
97
|
+
// eg
|
|
98
|
+
// if (Math.random() < 0.5) {
|
|
99
|
+
// var x: number = 2;
|
|
100
|
+
// } else {
|
|
101
|
+
// x!.toFixed();
|
|
102
|
+
// }
|
|
103
|
+
if (ts.isVariableDeclarationList(declaration.parent) &&
|
|
104
|
+
// var
|
|
105
|
+
declaration.parent.flags === ts.NodeFlags.None &&
|
|
106
|
+
// If they are not in the same file it will not exist.
|
|
107
|
+
// This situation must not occur using before defined.
|
|
108
|
+
services.tsNodeToESTreeNodeMap.has(declaration)) {
|
|
109
|
+
const declaratorNode = services.tsNodeToESTreeNodeMap.get(declaration);
|
|
110
|
+
const scope = context.sourceCode.getScope(node);
|
|
111
|
+
const declaratorScope = context.sourceCode.getScope(declaratorNode);
|
|
112
|
+
let parentScope = declaratorScope;
|
|
113
|
+
while ((parentScope = parentScope.upper)) {
|
|
114
|
+
if (parentScope === scope) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (
|
|
120
|
+
// is it `const x!: number`
|
|
121
|
+
declaration.initializer == null &&
|
|
122
|
+
declaration.exclamationToken == null &&
|
|
123
|
+
declaration.type != null) {
|
|
124
|
+
// check if the defined variable type has changed since assignment
|
|
125
|
+
const declarationType = checker.getTypeFromTypeNode(declaration.type);
|
|
126
|
+
const type = (0, util_1.getConstrainedTypeAtLocation)(services, node);
|
|
127
|
+
if (declarationType === type &&
|
|
128
|
+
// `declare`s are never narrowed, so never skip them
|
|
129
|
+
!(ts.isVariableDeclarationList(declaration.parent) &&
|
|
130
|
+
ts.isVariableStatement(declaration.parent.parent) &&
|
|
131
|
+
tsutils.includesModifier((0, util_1.getModifiers)(declaration.parent.parent), ts.SyntaxKind.DeclareKeyword))) {
|
|
132
|
+
// possibly used before assigned, so just skip it
|
|
133
|
+
// better to false negative and skip it, than false positive and fix to compile erroring code
|
|
134
|
+
//
|
|
135
|
+
// no better way to figure this out right now
|
|
136
|
+
// https://github.com/Microsoft/TypeScript/issues/31124
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
function isConstAssertion(node) {
|
|
144
|
+
return (node.type === utils_1.AST_NODE_TYPES.TSTypeReference &&
|
|
145
|
+
node.typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
146
|
+
node.typeName.name === 'const');
|
|
147
|
+
}
|
|
148
|
+
function isTemplateLiteralWithExpressions(expression) {
|
|
149
|
+
return (expression.type === utils_1.AST_NODE_TYPES.TemplateLiteral &&
|
|
150
|
+
expression.expressions.length !== 0);
|
|
151
|
+
}
|
|
152
|
+
function isImplicitlyNarrowedLiteralDeclaration({ expression, parent, }) {
|
|
153
|
+
/**
|
|
154
|
+
* Even on `const` variable declarations, template literals with expressions can sometimes be widened without a type assertion.
|
|
155
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/issues/8737
|
|
156
|
+
*/
|
|
157
|
+
if (isTemplateLiteralWithExpressions(expression)) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
161
|
+
const maybeDeclarationNode = parent.parent;
|
|
162
|
+
return ((maybeDeclarationNode.type === utils_1.AST_NODE_TYPES.VariableDeclaration &&
|
|
163
|
+
maybeDeclarationNode.kind === 'const') ||
|
|
164
|
+
(parent.type === utils_1.AST_NODE_TYPES.PropertyDefinition && parent.readonly));
|
|
165
|
+
}
|
|
166
|
+
function isTypeUnchanged(uncast, cast) {
|
|
167
|
+
if (uncast === cast) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
if ((0, util_1.isTypeFlagSet)(uncast, ts.TypeFlags.Undefined) &&
|
|
171
|
+
(0, util_1.isTypeFlagSet)(cast, ts.TypeFlags.Undefined) &&
|
|
172
|
+
tsutils.isCompilerOptionEnabled(compilerOptions, 'exactOptionalPropertyTypes')) {
|
|
173
|
+
const uncastParts = tsutils
|
|
174
|
+
.unionConstituents(uncast)
|
|
175
|
+
.filter(part => !(0, util_1.isTypeFlagSet)(part, ts.TypeFlags.Undefined));
|
|
176
|
+
const castParts = tsutils
|
|
177
|
+
.unionConstituents(cast)
|
|
178
|
+
.filter(part => !(0, util_1.isTypeFlagSet)(part, ts.TypeFlags.Undefined));
|
|
179
|
+
if (uncastParts.length !== castParts.length) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
const uncastPartsSet = new Set(uncastParts);
|
|
183
|
+
return castParts.every(part => uncastPartsSet.has(part));
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
function isTypeLiteral(type) {
|
|
188
|
+
return type.isLiteral() || tsutils.isBooleanLiteralType(type);
|
|
189
|
+
}
|
|
190
|
+
function isIIFE(expression) {
|
|
191
|
+
return (expression.type === utils_1.AST_NODE_TYPES.CallExpression &&
|
|
192
|
+
(expression.callee.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
193
|
+
expression.callee.type === utils_1.AST_NODE_TYPES.FunctionExpression));
|
|
194
|
+
}
|
|
195
|
+
function getUncastType(node) {
|
|
196
|
+
// Special handling for IIFE: extract the function's return type
|
|
197
|
+
if (isIIFE(node.expression)) {
|
|
198
|
+
const callee = node.expression.callee;
|
|
199
|
+
const functionType = services.getTypeAtLocation(callee);
|
|
200
|
+
const signatures = functionType.getCallSignatures();
|
|
201
|
+
if (signatures.length > 0) {
|
|
202
|
+
const returnType = checker.getReturnTypeOfSignature(signatures[0]);
|
|
203
|
+
// If the function has no explicit return type annotation and returns undefined,
|
|
204
|
+
// treat it as void (TypeScript infers () => {} as () => undefined, but it should be void)
|
|
205
|
+
if (callee.returnType == null &&
|
|
206
|
+
(0, util_1.isTypeFlagSet)(returnType, ts.TypeFlags.Undefined)) {
|
|
207
|
+
return checker.getVoidType();
|
|
208
|
+
}
|
|
209
|
+
return returnType;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return services.getTypeAtLocation(node.expression);
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
'TSAsExpression, TSTypeAssertion'(node) {
|
|
216
|
+
if (options.typesToIgnore?.includes(context.sourceCode.getText(node.typeAnnotation))) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const castType = services.getTypeAtLocation(node);
|
|
220
|
+
const castTypeIsLiteral = isTypeLiteral(castType);
|
|
221
|
+
const typeAnnotationIsConstAssertion = isConstAssertion(node.typeAnnotation);
|
|
222
|
+
if (!options.checkLiteralConstAssertions &&
|
|
223
|
+
castTypeIsLiteral &&
|
|
224
|
+
typeAnnotationIsConstAssertion) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const uncastType = getUncastType(node);
|
|
228
|
+
const typeIsUnchanged = isTypeUnchanged(uncastType, castType);
|
|
229
|
+
const wouldSameTypeBeInferred = castTypeIsLiteral
|
|
230
|
+
? isImplicitlyNarrowedLiteralDeclaration(node)
|
|
231
|
+
: !typeAnnotationIsConstAssertion;
|
|
232
|
+
if (typeIsUnchanged && wouldSameTypeBeInferred) {
|
|
233
|
+
context.report({
|
|
234
|
+
node,
|
|
235
|
+
messageId: 'unnecessaryAssertion',
|
|
236
|
+
fix(fixer) {
|
|
237
|
+
if (node.type === utils_1.AST_NODE_TYPES.TSTypeAssertion) {
|
|
238
|
+
const openingAngleBracket = (0, util_1.nullThrows)(context.sourceCode.getTokenBefore(node.typeAnnotation, token => token.type === utils_1.AST_TOKEN_TYPES.Punctuator &&
|
|
239
|
+
token.value === '<'), util_1.NullThrowsReasons.MissingToken('<', 'type annotation'));
|
|
240
|
+
const closingAngleBracket = (0, util_1.nullThrows)(context.sourceCode.getTokenAfter(node.typeAnnotation, token => token.type === utils_1.AST_TOKEN_TYPES.Punctuator &&
|
|
241
|
+
token.value === '>'), util_1.NullThrowsReasons.MissingToken('>', 'type annotation'));
|
|
242
|
+
// < ( number ) > ( 3 + 5 )
|
|
243
|
+
// ^---remove---^
|
|
244
|
+
return fixer.removeRange([
|
|
245
|
+
openingAngleBracket.range[0],
|
|
246
|
+
closingAngleBracket.range[1],
|
|
247
|
+
]);
|
|
248
|
+
}
|
|
249
|
+
// `as` is always present in TSAsExpression
|
|
250
|
+
const asToken = (0, util_1.nullThrows)(context.sourceCode.getTokenAfter(node.expression, token => token.type === utils_1.AST_TOKEN_TYPES.Identifier &&
|
|
251
|
+
token.value === 'as'), util_1.NullThrowsReasons.MissingToken('>', 'type annotation'));
|
|
252
|
+
const tokenBeforeAs = (0, util_1.nullThrows)(context.sourceCode.getTokenBefore(asToken, {
|
|
253
|
+
includeComments: true,
|
|
254
|
+
}), util_1.NullThrowsReasons.MissingToken('comment', 'as'));
|
|
255
|
+
// ( 3 + 5 ) as number
|
|
256
|
+
// ^--remove--^
|
|
257
|
+
return fixer.removeRange([tokenBeforeAs.range[1], node.range[1]]);
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
// TODO - add contextually unnecessary check for this
|
|
262
|
+
},
|
|
263
|
+
TSNonNullExpression(node) {
|
|
264
|
+
const removeExclamationFix = fixer => {
|
|
265
|
+
const exclamationToken = (0, util_1.nullThrows)(context.sourceCode.getLastToken(node, token => token.value === '!'), util_1.NullThrowsReasons.MissingToken('exclamation mark', 'non-null assertion'));
|
|
266
|
+
return fixer.removeRange(exclamationToken.range);
|
|
267
|
+
};
|
|
268
|
+
if (node.parent.type === utils_1.AST_NODE_TYPES.AssignmentExpression &&
|
|
269
|
+
node.parent.operator === '=') {
|
|
270
|
+
if (node.parent.left === node) {
|
|
271
|
+
context.report({
|
|
272
|
+
node,
|
|
273
|
+
messageId: 'contextuallyUnnecessary',
|
|
274
|
+
fix: removeExclamationFix,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
// for all other = assignments we ignore non-null checks
|
|
278
|
+
// this is because non-null assertions can change the type-flow of the code
|
|
279
|
+
// so whilst they might be unnecessary for the assignment - they are necessary
|
|
280
|
+
// for following code
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const originalNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
284
|
+
const constrainedType = (0, util_1.getConstrainedTypeAtLocation)(services, node.expression);
|
|
285
|
+
const actualType = services.getTypeAtLocation(node.expression);
|
|
286
|
+
// Check both the constrained type and the actual type.
|
|
287
|
+
// If either is nullable, we should not report the assertion as unnecessary.
|
|
288
|
+
// This handles cases like generic constraints with `any` where the
|
|
289
|
+
// constrained type is `any` (nullable) but the actual type might be
|
|
290
|
+
// a type parameter that TypeScript treats nominally.
|
|
291
|
+
// See: https://github.com/typescript-eslint/typescript-eslint/issues/11559
|
|
292
|
+
const constrainedTypeIsNullable = (0, util_1.isNullableType)(constrainedType);
|
|
293
|
+
const actualTypeIsNullable = (0, util_1.isNullableType)(actualType);
|
|
294
|
+
if (!constrainedTypeIsNullable && !actualTypeIsNullable) {
|
|
295
|
+
if (node.expression.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
296
|
+
isPossiblyUsedBeforeAssigned(node.expression)) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
context.report({
|
|
300
|
+
node,
|
|
301
|
+
messageId: 'unnecessaryAssertion',
|
|
302
|
+
fix: removeExclamationFix,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
// we know it's a nullable type
|
|
307
|
+
// so figure out if the variable is used in a place that accepts nullable types
|
|
308
|
+
// If the constrained type differs from the actual type (e.g., when dealing
|
|
309
|
+
// with unresolved generic type parameters), we should not report the assertion
|
|
310
|
+
// as contextually unnecessary. TypeScript may still require the assertion
|
|
311
|
+
// even if the constraint is nullable (like `any`).
|
|
312
|
+
// See: https://github.com/typescript-eslint/typescript-eslint/issues/11559
|
|
313
|
+
if (constrainedType !== actualType) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const contextualType = (0, util_1.getContextualType)(checker, originalNode);
|
|
317
|
+
if (contextualType) {
|
|
318
|
+
if ((0, util_1.isTypeFlagSet)(constrainedType, ts.TypeFlags.Unknown) &&
|
|
319
|
+
!(0, util_1.isTypeFlagSet)(contextualType, ts.TypeFlags.Unknown)) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
// in strict mode you can't assign null to undefined, so we have to make sure that
|
|
323
|
+
// the two types share a nullable type
|
|
324
|
+
const typeIncludesUndefined = (0, util_1.isTypeFlagSet)(constrainedType, ts.TypeFlags.Undefined);
|
|
325
|
+
const typeIncludesNull = (0, util_1.isTypeFlagSet)(constrainedType, ts.TypeFlags.Null);
|
|
326
|
+
const typeIncludesVoid = (0, util_1.isTypeFlagSet)(constrainedType, ts.TypeFlags.Void);
|
|
327
|
+
const contextualTypeIncludesUndefined = (0, util_1.isTypeFlagSet)(contextualType, ts.TypeFlags.Undefined);
|
|
328
|
+
const contextualTypeIncludesNull = (0, util_1.isTypeFlagSet)(contextualType, ts.TypeFlags.Null);
|
|
329
|
+
const contextualTypeIncludesVoid = (0, util_1.isTypeFlagSet)(contextualType, ts.TypeFlags.Void);
|
|
330
|
+
// make sure that the parent accepts the same types
|
|
331
|
+
// i.e. assigning `string | null | undefined` to `string | undefined` is invalid
|
|
332
|
+
const isValidUndefined = typeIncludesUndefined
|
|
333
|
+
? contextualTypeIncludesUndefined
|
|
334
|
+
: true;
|
|
335
|
+
const isValidNull = typeIncludesNull
|
|
336
|
+
? contextualTypeIncludesNull
|
|
337
|
+
: true;
|
|
338
|
+
const isValidVoid = typeIncludesVoid
|
|
339
|
+
? contextualTypeIncludesVoid
|
|
340
|
+
: true;
|
|
341
|
+
if (isValidUndefined && isValidNull && isValidVoid) {
|
|
342
|
+
context.report({
|
|
343
|
+
node,
|
|
344
|
+
messageId: 'contextuallyUnnecessary',
|
|
345
|
+
fix: removeExclamationFix,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
declare const _default: TSESLint.RuleModule<"removeUnnecessaryConstraint" | "unnecessaryConstraint", [], import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
|
|
3
|
+
name: string;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|