@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,521 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const scope_manager_1 = require("@typescript-eslint/scope-manager");
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
5
|
+
const util_1 = require("../util");
|
|
6
|
+
const isTypeImport_1 = require("../util/isTypeImport");
|
|
7
|
+
const allowedFunctionVariableDefTypes = new Set([
|
|
8
|
+
utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration,
|
|
9
|
+
utils_1.AST_NODE_TYPES.TSFunctionType,
|
|
10
|
+
utils_1.AST_NODE_TYPES.TSMethodSignature,
|
|
11
|
+
utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
|
12
|
+
utils_1.AST_NODE_TYPES.TSDeclareFunction,
|
|
13
|
+
utils_1.AST_NODE_TYPES.TSConstructSignatureDeclaration,
|
|
14
|
+
utils_1.AST_NODE_TYPES.TSConstructorType,
|
|
15
|
+
]);
|
|
16
|
+
const functionsHoistedNodes = new Set([utils_1.AST_NODE_TYPES.FunctionDeclaration]);
|
|
17
|
+
const typesHoistedNodes = new Set([
|
|
18
|
+
utils_1.AST_NODE_TYPES.TSInterfaceDeclaration,
|
|
19
|
+
utils_1.AST_NODE_TYPES.TSTypeAliasDeclaration,
|
|
20
|
+
]);
|
|
21
|
+
exports.default = (0, util_1.createRule)({
|
|
22
|
+
name: 'no-shadow',
|
|
23
|
+
meta: {
|
|
24
|
+
type: 'suggestion',
|
|
25
|
+
docs: {
|
|
26
|
+
description: 'Disallow variable declarations from shadowing variables declared in the outer scope',
|
|
27
|
+
extendsBaseRule: true,
|
|
28
|
+
},
|
|
29
|
+
messages: {
|
|
30
|
+
noShadow: "'{{name}}' is already declared in the upper scope on line {{shadowedLine}} column {{shadowedColumn}}.",
|
|
31
|
+
noShadowGlobal: "'{{name}}' is already a global variable.",
|
|
32
|
+
},
|
|
33
|
+
schema: [
|
|
34
|
+
{
|
|
35
|
+
type: 'object',
|
|
36
|
+
additionalProperties: false,
|
|
37
|
+
properties: {
|
|
38
|
+
allow: {
|
|
39
|
+
type: 'array',
|
|
40
|
+
description: 'Identifier names for which shadowing is allowed.',
|
|
41
|
+
items: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
builtinGlobals: {
|
|
46
|
+
type: 'boolean',
|
|
47
|
+
description: 'Whether to report shadowing of built-in global variables.',
|
|
48
|
+
},
|
|
49
|
+
hoist: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'Whether to report shadowing before outer functions or variables are defined.',
|
|
52
|
+
enum: ['all', 'functions', 'functions-and-types', 'never', 'types'],
|
|
53
|
+
},
|
|
54
|
+
ignoreFunctionTypeParameterNameValueShadow: {
|
|
55
|
+
type: 'boolean',
|
|
56
|
+
description: 'Whether to ignore function parameters named the same as a variable.',
|
|
57
|
+
},
|
|
58
|
+
ignoreOnInitialization: {
|
|
59
|
+
type: 'boolean',
|
|
60
|
+
description: 'Whether to ignore the variable initializers when the shadowed variable is presumably still unitialized.',
|
|
61
|
+
},
|
|
62
|
+
ignoreTypeValueShadow: {
|
|
63
|
+
type: 'boolean',
|
|
64
|
+
description: 'Whether to ignore types named the same as a variable.',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
defaultOptions: [
|
|
71
|
+
{
|
|
72
|
+
allow: [],
|
|
73
|
+
builtinGlobals: false,
|
|
74
|
+
hoist: 'functions-and-types',
|
|
75
|
+
ignoreFunctionTypeParameterNameValueShadow: true,
|
|
76
|
+
ignoreOnInitialization: false,
|
|
77
|
+
ignoreTypeValueShadow: true,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
create(context, [options]) {
|
|
81
|
+
/**
|
|
82
|
+
* Check if a scope is a TypeScript module augmenting the global namespace.
|
|
83
|
+
*/
|
|
84
|
+
function isGlobalAugmentation(scope) {
|
|
85
|
+
return ((scope.type === scope_manager_1.ScopeType.tsModule && scope.block.kind === 'global') ||
|
|
86
|
+
(!!scope.upper && isGlobalAugmentation(scope.upper)));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check if variable is a `this` parameter.
|
|
90
|
+
*/
|
|
91
|
+
function isThisParam(variable) {
|
|
92
|
+
return (variable.defs[0].type === scope_manager_1.DefinitionType.Parameter &&
|
|
93
|
+
variable.name === 'this');
|
|
94
|
+
}
|
|
95
|
+
function isTypeValueShadow(variable, shadowed) {
|
|
96
|
+
if (options.ignoreTypeValueShadow !== true) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (!('isValueVariable' in variable)) {
|
|
100
|
+
// this shouldn't happen...
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const firstDefinition = shadowed.defs.at(0);
|
|
104
|
+
const isShadowedValue = !('isValueVariable' in shadowed) ||
|
|
105
|
+
!firstDefinition ||
|
|
106
|
+
(!(0, isTypeImport_1.isTypeImport)(firstDefinition) && shadowed.isValueVariable);
|
|
107
|
+
return variable.isValueVariable !== isShadowedValue;
|
|
108
|
+
}
|
|
109
|
+
function isFunctionTypeParameterNameValueShadow(variable, shadowed) {
|
|
110
|
+
if (options.ignoreFunctionTypeParameterNameValueShadow !== true) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (!('isValueVariable' in variable)) {
|
|
114
|
+
// this shouldn't happen...
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const isShadowedValue = 'isValueVariable' in shadowed ? shadowed.isValueVariable : true;
|
|
118
|
+
if (!isShadowedValue) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return variable.defs.every(def => allowedFunctionVariableDefTypes.has(def.node.type));
|
|
122
|
+
}
|
|
123
|
+
function isGenericOfStaticMethod(variable) {
|
|
124
|
+
if (!('isTypeVariable' in variable)) {
|
|
125
|
+
// this shouldn't happen...
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (!variable.isTypeVariable) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
if (variable.identifiers.length === 0) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
const typeParameter = variable.identifiers[0].parent;
|
|
135
|
+
if (typeParameter.type !== utils_1.AST_NODE_TYPES.TSTypeParameter) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const typeParameterDecl = typeParameter.parent;
|
|
139
|
+
if (typeParameterDecl.type !== utils_1.AST_NODE_TYPES.TSTypeParameterDeclaration) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
const functionExpr = typeParameterDecl.parent;
|
|
143
|
+
if (functionExpr.type !== utils_1.AST_NODE_TYPES.FunctionExpression &&
|
|
144
|
+
functionExpr.type !== utils_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
const methodDefinition = functionExpr.parent;
|
|
148
|
+
if (methodDefinition.type !== utils_1.AST_NODE_TYPES.MethodDefinition) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
return methodDefinition.static;
|
|
152
|
+
}
|
|
153
|
+
function isGenericOfClass(variable) {
|
|
154
|
+
if (!('isTypeVariable' in variable)) {
|
|
155
|
+
// this shouldn't happen...
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
if (!variable.isTypeVariable) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
if (variable.identifiers.length === 0) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
const typeParameter = variable.identifiers[0].parent;
|
|
165
|
+
if (typeParameter.type !== utils_1.AST_NODE_TYPES.TSTypeParameter) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
const typeParameterDecl = typeParameter.parent;
|
|
169
|
+
if (typeParameterDecl.type !== utils_1.AST_NODE_TYPES.TSTypeParameterDeclaration) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
const classDecl = typeParameterDecl.parent;
|
|
173
|
+
return (classDecl.type === utils_1.AST_NODE_TYPES.ClassDeclaration ||
|
|
174
|
+
classDecl.type === utils_1.AST_NODE_TYPES.ClassExpression);
|
|
175
|
+
}
|
|
176
|
+
function isGenericOfAStaticMethodShadow(variable, shadowed) {
|
|
177
|
+
return isGenericOfStaticMethod(variable) && isGenericOfClass(shadowed);
|
|
178
|
+
}
|
|
179
|
+
function isImportDeclaration(definition) {
|
|
180
|
+
return definition.type === utils_1.AST_NODE_TYPES.ImportDeclaration;
|
|
181
|
+
}
|
|
182
|
+
function isExternalModuleDeclarationWithName(scope, name) {
|
|
183
|
+
return (scope.type === scope_manager_1.ScopeType.tsModule &&
|
|
184
|
+
scope.block.id.type === utils_1.AST_NODE_TYPES.Literal &&
|
|
185
|
+
scope.block.id.value === name);
|
|
186
|
+
}
|
|
187
|
+
function isExternalDeclarationMerging(scope, variable, shadowed) {
|
|
188
|
+
const [firstDefinition] = shadowed.defs;
|
|
189
|
+
const [secondDefinition] = variable.defs;
|
|
190
|
+
return ((0, isTypeImport_1.isTypeImport)(firstDefinition) &&
|
|
191
|
+
isImportDeclaration(firstDefinition.parent) &&
|
|
192
|
+
isExternalModuleDeclarationWithName(scope, firstDefinition.parent.source.value) &&
|
|
193
|
+
(secondDefinition.node.type === utils_1.AST_NODE_TYPES.TSInterfaceDeclaration ||
|
|
194
|
+
secondDefinition.node.type === utils_1.AST_NODE_TYPES.TSTypeAliasDeclaration));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Check if variable name is allowed.
|
|
198
|
+
* @param variable The variable to check.
|
|
199
|
+
* @returns Whether or not the variable name is allowed.
|
|
200
|
+
*/
|
|
201
|
+
function isAllowed(variable) {
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
203
|
+
return options.allow.includes(variable.name);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Checks if a variable of the class name in the class scope of ClassDeclaration.
|
|
207
|
+
*
|
|
208
|
+
* ClassDeclaration creates two variables of its name into its outer scope and its class scope.
|
|
209
|
+
* So we should ignore the variable in the class scope.
|
|
210
|
+
* @param variable The variable to check.
|
|
211
|
+
* @returns Whether or not the variable of the class name in the class scope of ClassDeclaration.
|
|
212
|
+
*/
|
|
213
|
+
function isDuplicatedClassNameVariable(variable) {
|
|
214
|
+
const block = variable.scope.block;
|
|
215
|
+
return (block.type === utils_1.AST_NODE_TYPES.ClassDeclaration &&
|
|
216
|
+
block.id === variable.identifiers[0]);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Checks if a variable of the class name in the class scope of TSEnumDeclaration.
|
|
220
|
+
*
|
|
221
|
+
* TSEnumDeclaration creates two variables of its name into its outer scope and its class scope.
|
|
222
|
+
* So we should ignore the variable in the class scope.
|
|
223
|
+
* @param variable The variable to check.
|
|
224
|
+
* @returns Whether or not the variable of the class name in the class scope of TSEnumDeclaration.
|
|
225
|
+
*/
|
|
226
|
+
function isDuplicatedEnumNameVariable(variable) {
|
|
227
|
+
const block = variable.scope.block;
|
|
228
|
+
return (block.type === utils_1.AST_NODE_TYPES.TSEnumDeclaration &&
|
|
229
|
+
block.id === variable.identifiers[0]);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Checks whether or not a given location is inside of the range of a given node.
|
|
233
|
+
* @param node An node to check.
|
|
234
|
+
* @param location A location to check.
|
|
235
|
+
* @returns `true` if the location is inside of the range of the node.
|
|
236
|
+
*/
|
|
237
|
+
function isInRange(node, location) {
|
|
238
|
+
return node && node.range[0] <= location && location <= node.range[1];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Searches from the current node through its ancestry to find a matching node.
|
|
242
|
+
* @param node a node to get.
|
|
243
|
+
* @param match a callback that checks whether or not the node verifies its condition or not.
|
|
244
|
+
* @returns the matching node.
|
|
245
|
+
*/
|
|
246
|
+
function findSelfOrAncestor(node, match) {
|
|
247
|
+
let currentNode = node;
|
|
248
|
+
while (currentNode && !match(currentNode)) {
|
|
249
|
+
currentNode = currentNode.parent;
|
|
250
|
+
}
|
|
251
|
+
return currentNode;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Finds function's outer scope.
|
|
255
|
+
* @param scope Function's own scope.
|
|
256
|
+
* @returns Function's outer scope.
|
|
257
|
+
*/
|
|
258
|
+
function getOuterScope(scope) {
|
|
259
|
+
const upper = scope.upper;
|
|
260
|
+
if (upper?.type === scope_manager_1.ScopeType.functionExpressionName) {
|
|
261
|
+
return upper.upper;
|
|
262
|
+
}
|
|
263
|
+
return upper;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Checks if a variable and a shadowedVariable have the same init pattern ancestor.
|
|
267
|
+
* @param variable a variable to check.
|
|
268
|
+
* @param shadowedVariable a shadowedVariable to check.
|
|
269
|
+
* @returns Whether or not the variable and the shadowedVariable have the same init pattern ancestor.
|
|
270
|
+
*/
|
|
271
|
+
function isInitPatternNode(variable, shadowedVariable) {
|
|
272
|
+
const outerDef = shadowedVariable.defs.at(0);
|
|
273
|
+
if (!outerDef) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
const { variableScope } = variable.scope;
|
|
277
|
+
if (!((variableScope.block.type ===
|
|
278
|
+
utils_1.AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
279
|
+
variableScope.block.type === utils_1.AST_NODE_TYPES.FunctionExpression) &&
|
|
280
|
+
getOuterScope(variableScope) === shadowedVariable.scope)) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
const fun = variableScope.block;
|
|
284
|
+
const { parent } = fun;
|
|
285
|
+
const callExpression = findSelfOrAncestor(parent, node => node.type === utils_1.AST_NODE_TYPES.CallExpression);
|
|
286
|
+
if (!callExpression) {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
let node = outerDef.name;
|
|
290
|
+
const location = callExpression.range[1];
|
|
291
|
+
while (node) {
|
|
292
|
+
if (node.type === utils_1.AST_NODE_TYPES.VariableDeclarator) {
|
|
293
|
+
if (isInRange(node.init, location)) {
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
if ((node.parent.parent.type === utils_1.AST_NODE_TYPES.ForInStatement ||
|
|
297
|
+
node.parent.parent.type === utils_1.AST_NODE_TYPES.ForOfStatement) &&
|
|
298
|
+
isInRange(node.parent.parent.right, location)) {
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
else if (node.type === utils_1.AST_NODE_TYPES.AssignmentPattern) {
|
|
304
|
+
if (isInRange(node.right, location)) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else if ([
|
|
309
|
+
utils_1.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
310
|
+
utils_1.AST_NODE_TYPES.CatchClause,
|
|
311
|
+
utils_1.AST_NODE_TYPES.ClassDeclaration,
|
|
312
|
+
utils_1.AST_NODE_TYPES.ClassExpression,
|
|
313
|
+
utils_1.AST_NODE_TYPES.ExportNamedDeclaration,
|
|
314
|
+
utils_1.AST_NODE_TYPES.FunctionDeclaration,
|
|
315
|
+
utils_1.AST_NODE_TYPES.FunctionExpression,
|
|
316
|
+
utils_1.AST_NODE_TYPES.ImportDeclaration,
|
|
317
|
+
].includes(node.type)) {
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
node = node.parent;
|
|
321
|
+
}
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Checks if a variable is inside the initializer of scopeVar.
|
|
326
|
+
*
|
|
327
|
+
* To avoid reporting at declarations such as `var a = function a() {};`.
|
|
328
|
+
* But it should report `var a = function(a) {};` or `var a = function() { function a() {} };`.
|
|
329
|
+
* @param variable The variable to check.
|
|
330
|
+
* @param scopeVar The scope variable to look for.
|
|
331
|
+
* @returns Whether or not the variable is inside initializer of scopeVar.
|
|
332
|
+
*/
|
|
333
|
+
function isOnInitializer(variable, scopeVar) {
|
|
334
|
+
const outerScope = scopeVar.scope;
|
|
335
|
+
const outerDef = scopeVar.defs.at(0);
|
|
336
|
+
const outer = outerDef?.parent?.range;
|
|
337
|
+
const innerScope = variable.scope;
|
|
338
|
+
const innerDef = variable.defs.at(0);
|
|
339
|
+
const inner = innerDef?.name.range;
|
|
340
|
+
return !!(outer &&
|
|
341
|
+
inner &&
|
|
342
|
+
outer[0] < inner[0] &&
|
|
343
|
+
inner[1] < outer[1] &&
|
|
344
|
+
((innerDef.type === scope_manager_1.DefinitionType.FunctionName &&
|
|
345
|
+
innerDef.node.type === utils_1.AST_NODE_TYPES.FunctionExpression) ||
|
|
346
|
+
innerDef.node.type === utils_1.AST_NODE_TYPES.ClassExpression) &&
|
|
347
|
+
outerScope === innerScope.upper);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get a range of a variable's identifier node.
|
|
351
|
+
* @param variable The variable to get.
|
|
352
|
+
* @returns The range of the variable's identifier node.
|
|
353
|
+
*/
|
|
354
|
+
function getNameRange(variable) {
|
|
355
|
+
const def = variable.defs.at(0);
|
|
356
|
+
return def?.name.range;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Checks if a variable is in TDZ of scopeVar.
|
|
360
|
+
* @param variable The variable to check.
|
|
361
|
+
* @param scopeVar The variable of TDZ.
|
|
362
|
+
* @returns Whether or not the variable is in TDZ of scopeVar.
|
|
363
|
+
*/
|
|
364
|
+
function isInTdz(variable, scopeVar) {
|
|
365
|
+
const outerDef = scopeVar.defs.at(0);
|
|
366
|
+
const inner = getNameRange(variable);
|
|
367
|
+
const outer = getNameRange(scopeVar);
|
|
368
|
+
if (!inner || !outer || inner[1] >= outer[0]) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
if (!outerDef) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
if (options.hoist === 'functions') {
|
|
375
|
+
return !functionsHoistedNodes.has(outerDef.node.type);
|
|
376
|
+
}
|
|
377
|
+
if (options.hoist === 'types') {
|
|
378
|
+
return !typesHoistedNodes.has(outerDef.node.type);
|
|
379
|
+
}
|
|
380
|
+
if (options.hoist === 'functions-and-types') {
|
|
381
|
+
return (!functionsHoistedNodes.has(outerDef.node.type) &&
|
|
382
|
+
!typesHoistedNodes.has(outerDef.node.type));
|
|
383
|
+
}
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Get declared line and column of a variable.
|
|
388
|
+
* @param variable The variable to get.
|
|
389
|
+
* @returns The declared line and column of the variable.
|
|
390
|
+
*/
|
|
391
|
+
function getDeclaredLocation(variable) {
|
|
392
|
+
const identifier = variable.identifiers.at(0);
|
|
393
|
+
if (identifier) {
|
|
394
|
+
return {
|
|
395
|
+
column: identifier.loc.start.column + 1,
|
|
396
|
+
global: false,
|
|
397
|
+
line: identifier.loc.start.line,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
global: true,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Checks if the initialization of a variable has the declare modifier in a
|
|
406
|
+
* definition file.
|
|
407
|
+
*/
|
|
408
|
+
function isDeclareInDTSFile(variable) {
|
|
409
|
+
const fileName = context.filename;
|
|
410
|
+
if (!(0, util_1.isDefinitionFile)(fileName)) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
return variable.defs.some(def => {
|
|
414
|
+
return ((def.type === scope_manager_1.DefinitionType.Variable && def.parent.declare) ||
|
|
415
|
+
(def.type === scope_manager_1.DefinitionType.ClassName && def.node.declare) ||
|
|
416
|
+
(def.type === scope_manager_1.DefinitionType.TSEnumName && def.node.declare) ||
|
|
417
|
+
(def.type === scope_manager_1.DefinitionType.TSModuleName && def.node.declare));
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Checks the current context for shadowed variables.
|
|
422
|
+
* @param scope Fixme
|
|
423
|
+
*/
|
|
424
|
+
function checkForShadows(scope) {
|
|
425
|
+
// ignore global augmentation
|
|
426
|
+
if (isGlobalAugmentation(scope)) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const variables = scope.variables;
|
|
430
|
+
for (const variable of variables) {
|
|
431
|
+
// ignore "arguments"
|
|
432
|
+
if (variable.identifiers.length === 0) {
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
// this params are pseudo-params that cannot be shadowed
|
|
436
|
+
if (isThisParam(variable)) {
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
// ignore variables of a class name in the class scope of ClassDeclaration
|
|
440
|
+
if (isDuplicatedClassNameVariable(variable)) {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
// ignore variables of a class name in the class scope of ClassDeclaration
|
|
444
|
+
if (isDuplicatedEnumNameVariable(variable)) {
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
// ignore configured allowed names
|
|
448
|
+
if (isAllowed(variable)) {
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
// ignore variables with the declare keyword in .d.ts files
|
|
452
|
+
if (isDeclareInDTSFile(variable)) {
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
// Gets shadowed variable.
|
|
456
|
+
const shadowed = scope.upper
|
|
457
|
+
? utils_1.ASTUtils.findVariable(scope.upper, variable.name)
|
|
458
|
+
: null;
|
|
459
|
+
if (!shadowed) {
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
// ignore type value variable shadowing if configured
|
|
463
|
+
if (isTypeValueShadow(variable, shadowed)) {
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
// ignore function type parameter name shadowing if configured
|
|
467
|
+
if (isFunctionTypeParameterNameValueShadow(variable, shadowed)) {
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
// ignore static class method generic shadowing class generic
|
|
471
|
+
// this is impossible for the scope analyser to understand
|
|
472
|
+
// so we have to handle this manually in this rule
|
|
473
|
+
if (isGenericOfAStaticMethodShadow(variable, shadowed)) {
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
if (isExternalDeclarationMerging(scope, variable, shadowed)) {
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
const isESLintGlobal = 'writeable' in shadowed;
|
|
480
|
+
if ((shadowed.identifiers.length > 0 ||
|
|
481
|
+
(options.builtinGlobals && isESLintGlobal)) &&
|
|
482
|
+
!isOnInitializer(variable, shadowed) &&
|
|
483
|
+
!(options.ignoreOnInitialization &&
|
|
484
|
+
isInitPatternNode(variable, shadowed)) &&
|
|
485
|
+
!(options.hoist !== 'all' && isInTdz(variable, shadowed))) {
|
|
486
|
+
const location = getDeclaredLocation(shadowed);
|
|
487
|
+
context.report({
|
|
488
|
+
node: variable.identifiers[0],
|
|
489
|
+
...(location.global
|
|
490
|
+
? {
|
|
491
|
+
messageId: 'noShadowGlobal',
|
|
492
|
+
data: {
|
|
493
|
+
name: variable.name,
|
|
494
|
+
},
|
|
495
|
+
}
|
|
496
|
+
: {
|
|
497
|
+
messageId: 'noShadow',
|
|
498
|
+
data: {
|
|
499
|
+
name: variable.name,
|
|
500
|
+
shadowedColumn: location.column,
|
|
501
|
+
shadowedLine: location.line,
|
|
502
|
+
},
|
|
503
|
+
}),
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
'Program:exit'(node) {
|
|
510
|
+
const globalScope = context.sourceCode.getScope(node);
|
|
511
|
+
const stack = [...globalScope.childScopes];
|
|
512
|
+
while (stack.length) {
|
|
513
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
514
|
+
const scope = stack.pop();
|
|
515
|
+
stack.push(...scope.childScopes);
|
|
516
|
+
checkForShadows(scope);
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
};
|
|
520
|
+
},
|
|
521
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Options = [
|
|
2
|
+
{
|
|
3
|
+
allowDestructuring?: boolean;
|
|
4
|
+
allowedNames?: string[];
|
|
5
|
+
}
|
|
6
|
+
];
|
|
7
|
+
export type MessageIds = 'thisAssignment' | 'thisDestructure';
|
|
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,66 @@
|
|
|
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: 'no-this-alias',
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'suggestion',
|
|
9
|
+
docs: {
|
|
10
|
+
description: 'Disallow aliasing `this`',
|
|
11
|
+
recommended: 'recommended',
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
thisAssignment: "Unexpected aliasing of 'this' to local variable.",
|
|
15
|
+
thisDestructure: "Unexpected aliasing of members of 'this' to local variables.",
|
|
16
|
+
},
|
|
17
|
+
schema: [
|
|
18
|
+
{
|
|
19
|
+
type: 'object',
|
|
20
|
+
additionalProperties: false,
|
|
21
|
+
properties: {
|
|
22
|
+
allowDestructuring: {
|
|
23
|
+
type: 'boolean',
|
|
24
|
+
description: 'Whether to ignore destructurings, such as `const { props, state } = this`.',
|
|
25
|
+
},
|
|
26
|
+
allowedNames: {
|
|
27
|
+
type: 'array',
|
|
28
|
+
description: 'Names to ignore, such as ["self"] for `const self = this;`.',
|
|
29
|
+
items: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
defaultOptions: [
|
|
38
|
+
{
|
|
39
|
+
allowDestructuring: true,
|
|
40
|
+
allowedNames: [],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
create(context, [{ allowDestructuring, allowedNames }]) {
|
|
44
|
+
return {
|
|
45
|
+
"VariableDeclarator[init.type='ThisExpression'], AssignmentExpression[right.type='ThisExpression']"(node) {
|
|
46
|
+
const id = node.type === utils_1.AST_NODE_TYPES.VariableDeclarator ? node.id : node.left;
|
|
47
|
+
if (allowDestructuring && id.type !== utils_1.AST_NODE_TYPES.Identifier) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const hasAllowedName = id.type === utils_1.AST_NODE_TYPES.Identifier
|
|
51
|
+
? // https://github.com/typescript-eslint/typescript-eslint/issues/5439
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
53
|
+
allowedNames.includes(id.name)
|
|
54
|
+
: false;
|
|
55
|
+
if (!hasAllowedName) {
|
|
56
|
+
context.report({
|
|
57
|
+
node: id,
|
|
58
|
+
messageId: id.type === utils_1.AST_NODE_TYPES.Identifier
|
|
59
|
+
? 'thisAssignment'
|
|
60
|
+
: 'thisDestructure',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type Values = 'always' | 'in-intersections' | 'in-unions' | 'in-unions-and-intersections' | 'never';
|
|
2
|
+
export type Options = [
|
|
3
|
+
{
|
|
4
|
+
allowAliases?: Values;
|
|
5
|
+
allowCallbacks?: 'always' | 'never';
|
|
6
|
+
allowConditionalTypes?: 'always' | 'never';
|
|
7
|
+
allowConstructors?: 'always' | 'never';
|
|
8
|
+
allowGenerics?: 'always' | 'never';
|
|
9
|
+
allowLiterals?: Values;
|
|
10
|
+
allowMappedTypes?: Values;
|
|
11
|
+
allowTupleTypes?: Values;
|
|
12
|
+
}
|
|
13
|
+
];
|
|
14
|
+
export type MessageIds = 'noCompositionAlias' | 'noTypeAlias';
|
|
15
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
16
|
+
name: string;
|
|
17
|
+
};
|
|
18
|
+
export default _default;
|