@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,512 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const regexpp_1 = require("@eslint-community/regexpp");
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
5
|
+
const util_1 = require("../util");
|
|
6
|
+
const EQ_OPERATORS = /^[=!]=/;
|
|
7
|
+
const regexpp = new regexpp_1.RegExpParser();
|
|
8
|
+
exports.default = (0, util_1.createRule)({
|
|
9
|
+
name: 'prefer-string-starts-ends-with',
|
|
10
|
+
meta: {
|
|
11
|
+
type: 'suggestion',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings',
|
|
14
|
+
recommended: 'stylistic',
|
|
15
|
+
requiresTypeChecking: true,
|
|
16
|
+
},
|
|
17
|
+
fixable: 'code',
|
|
18
|
+
messages: {
|
|
19
|
+
preferEndsWith: "Use the 'String#endsWith' method instead.",
|
|
20
|
+
preferStartsWith: "Use 'String#startsWith' method instead.",
|
|
21
|
+
},
|
|
22
|
+
schema: [
|
|
23
|
+
{
|
|
24
|
+
type: 'object',
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
properties: {
|
|
27
|
+
allowSingleElementEquality: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'Whether to allow equality checks against the first or last element of a string.',
|
|
30
|
+
enum: ['always', 'never'],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
defaultOptions: [{ allowSingleElementEquality: 'never' }],
|
|
37
|
+
create(context, [{ allowSingleElementEquality }]) {
|
|
38
|
+
const globalScope = context.sourceCode.getScope(context.sourceCode.ast);
|
|
39
|
+
const services = (0, util_1.getParserServices)(context);
|
|
40
|
+
const checker = services.program.getTypeChecker();
|
|
41
|
+
/**
|
|
42
|
+
* Check if a given node is a string.
|
|
43
|
+
* @param node The node to check.
|
|
44
|
+
*/
|
|
45
|
+
function isStringType(node) {
|
|
46
|
+
const objectType = services.getTypeAtLocation(node);
|
|
47
|
+
return (0, util_1.getTypeName)(checker, objectType) === 'string';
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if a given node is a `Literal` node that is null.
|
|
51
|
+
* @param node The node to check.
|
|
52
|
+
*/
|
|
53
|
+
function isNull(node) {
|
|
54
|
+
const evaluated = (0, util_1.getStaticValue)(node, globalScope);
|
|
55
|
+
return evaluated != null && evaluated.value == null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if a given node is a `Literal` node that is a given value.
|
|
59
|
+
* @param node The node to check.
|
|
60
|
+
* @param value The expected value of the `Literal` node.
|
|
61
|
+
*/
|
|
62
|
+
function isNumber(node, value) {
|
|
63
|
+
const evaluated = (0, util_1.getStaticValue)(node, globalScope);
|
|
64
|
+
return evaluated?.value === value;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if a given node is a `Literal` node that is a character.
|
|
68
|
+
* @param node The node to check.
|
|
69
|
+
*/
|
|
70
|
+
function isCharacter(node) {
|
|
71
|
+
const evaluated = (0, util_1.getStaticValue)(node, globalScope);
|
|
72
|
+
return (evaluated != null &&
|
|
73
|
+
typeof evaluated.value === 'string' &&
|
|
74
|
+
// checks if the string is a character long
|
|
75
|
+
evaluated.value[0] === evaluated.value);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if a given node is `==`, `===`, `!=`, or `!==`.
|
|
79
|
+
* @param node The node to check.
|
|
80
|
+
*/
|
|
81
|
+
function isEqualityComparison(node) {
|
|
82
|
+
return (node.type === utils_1.AST_NODE_TYPES.BinaryExpression &&
|
|
83
|
+
EQ_OPERATORS.test(node.operator));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if two given nodes are the same meaning.
|
|
87
|
+
* @param node1 A node to compare.
|
|
88
|
+
* @param node2 Another node to compare.
|
|
89
|
+
*/
|
|
90
|
+
function isSameTokens(node1, node2) {
|
|
91
|
+
const tokens1 = context.sourceCode.getTokens(node1);
|
|
92
|
+
const tokens2 = context.sourceCode.getTokens(node2);
|
|
93
|
+
if (tokens1.length !== tokens2.length) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
for (let i = 0; i < tokens1.length; ++i) {
|
|
97
|
+
const token1 = tokens1[i];
|
|
98
|
+
const token2 = tokens2[i];
|
|
99
|
+
if (token1.type !== token2.type || token1.value !== token2.value) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if a given node is the expression of the length of a string.
|
|
107
|
+
*
|
|
108
|
+
* - If `length` property access of `expectedObjectNode`, it's `true`.
|
|
109
|
+
* E.g., `foo` → `foo.length` / `"foo"` → `"foo".length`
|
|
110
|
+
* - If `expectedObjectNode` is a string literal, `node` can be a number.
|
|
111
|
+
* E.g., `"foo"` → `3`
|
|
112
|
+
*
|
|
113
|
+
* @param node The node to check.
|
|
114
|
+
* @param expectedObjectNode The node which is expected as the receiver of `length` property.
|
|
115
|
+
*/
|
|
116
|
+
function isLengthExpression(node, expectedObjectNode) {
|
|
117
|
+
if (node.type === utils_1.AST_NODE_TYPES.MemberExpression) {
|
|
118
|
+
return ((0, util_1.getPropertyName)(node, globalScope) === 'length' &&
|
|
119
|
+
isSameTokens(node.object, expectedObjectNode));
|
|
120
|
+
}
|
|
121
|
+
const evaluatedLength = (0, util_1.getStaticValue)(node, globalScope);
|
|
122
|
+
const evaluatedString = (0, util_1.getStaticValue)(expectedObjectNode, globalScope);
|
|
123
|
+
return (evaluatedLength != null &&
|
|
124
|
+
evaluatedString != null &&
|
|
125
|
+
typeof evaluatedLength.value === 'number' &&
|
|
126
|
+
typeof evaluatedString.value === 'string' &&
|
|
127
|
+
evaluatedLength.value === evaluatedString.value.length);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns true if `node` is `-substring.length` or
|
|
131
|
+
* `parentString.length - substring.length`
|
|
132
|
+
*/
|
|
133
|
+
function isLengthAheadOfEnd(node, substring, parentString) {
|
|
134
|
+
return ((node.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
|
|
135
|
+
node.operator === '-' &&
|
|
136
|
+
isLengthExpression(node.argument, substring)) ||
|
|
137
|
+
(node.type === utils_1.AST_NODE_TYPES.BinaryExpression &&
|
|
138
|
+
node.operator === '-' &&
|
|
139
|
+
isLengthExpression(node.left, parentString) &&
|
|
140
|
+
isLengthExpression(node.right, substring)));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check if a given node is the expression of the last index.
|
|
144
|
+
*
|
|
145
|
+
* E.g. `foo.length - 1`
|
|
146
|
+
*
|
|
147
|
+
* @param node The node to check.
|
|
148
|
+
* @param expectedObjectNode The node which is expected as the receiver of `length` property.
|
|
149
|
+
*/
|
|
150
|
+
function isLastIndexExpression(node, expectedObjectNode) {
|
|
151
|
+
return (node.type === utils_1.AST_NODE_TYPES.BinaryExpression &&
|
|
152
|
+
node.operator === '-' &&
|
|
153
|
+
isLengthExpression(node.left, expectedObjectNode) &&
|
|
154
|
+
isNumber(node.right, 1));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get the range of the property of a given `MemberExpression` node.
|
|
158
|
+
*
|
|
159
|
+
* - `obj[foo]` → the range of `[foo]`
|
|
160
|
+
* - `obf.foo` → the range of `.foo`
|
|
161
|
+
* - `(obj).foo` → the range of `.foo`
|
|
162
|
+
*
|
|
163
|
+
* @param node The member expression node to get.
|
|
164
|
+
*/
|
|
165
|
+
function getPropertyRange(node) {
|
|
166
|
+
const dotOrOpenBracket = (0, util_1.nullThrows)(context.sourceCode.getTokenAfter(node.object, util_1.isNotClosingParenToken), util_1.NullThrowsReasons.MissingToken('closing parenthesis', 'member'));
|
|
167
|
+
return [dotOrOpenBracket.range[0], node.range[1]];
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Parse a given `RegExp` pattern to that string if it's a static string.
|
|
171
|
+
* @param pattern The RegExp pattern text to parse.
|
|
172
|
+
* @param unicode Whether the RegExp is unicode.
|
|
173
|
+
*/
|
|
174
|
+
function parseRegExpText(pattern, unicode) {
|
|
175
|
+
// Parse it.
|
|
176
|
+
const ast = regexpp.parsePattern(pattern, undefined, undefined, {
|
|
177
|
+
unicode,
|
|
178
|
+
});
|
|
179
|
+
if (ast.alternatives.length !== 1) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
// Drop `^`/`$` assertion.
|
|
183
|
+
const chars = ast.alternatives[0].elements;
|
|
184
|
+
const first = chars[0];
|
|
185
|
+
if (first.type === 'Assertion' && first.kind === 'start') {
|
|
186
|
+
chars.shift();
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
chars.pop();
|
|
190
|
+
}
|
|
191
|
+
// Check if it can determine a unique string.
|
|
192
|
+
if (!chars.every(c => c.type === 'Character')) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
// To string.
|
|
196
|
+
return String.fromCodePoint(...chars.map(c => c.value));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Parse a given node if it's a `RegExp` instance.
|
|
200
|
+
* @param node The node to parse.
|
|
201
|
+
*/
|
|
202
|
+
function parseRegExp(node) {
|
|
203
|
+
const evaluated = (0, util_1.getStaticValue)(node, globalScope);
|
|
204
|
+
if (evaluated == null || !(evaluated.value instanceof RegExp)) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
const { flags, source } = evaluated.value;
|
|
208
|
+
const isStartsWith = source.startsWith('^');
|
|
209
|
+
const isEndsWith = source.endsWith('$');
|
|
210
|
+
if (isStartsWith === isEndsWith ||
|
|
211
|
+
flags.includes('i') ||
|
|
212
|
+
flags.includes('m')) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const text = parseRegExpText(source, flags.includes('u'));
|
|
216
|
+
if (text == null) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
return { isEndsWith, isStartsWith, text };
|
|
220
|
+
}
|
|
221
|
+
function getLeftNode(init) {
|
|
222
|
+
const node = (0, util_1.skipChainExpression)(init);
|
|
223
|
+
const leftNode = node.type === utils_1.AST_NODE_TYPES.CallExpression ? node.callee : node;
|
|
224
|
+
if (leftNode.type !== utils_1.AST_NODE_TYPES.MemberExpression) {
|
|
225
|
+
throw new Error(`Expected a MemberExpression, got ${leftNode.type}`);
|
|
226
|
+
}
|
|
227
|
+
return leftNode;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Fix code with using the right operand as the search string.
|
|
231
|
+
* For example: `foo.slice(0, 3) === 'bar'` → `foo.startsWith('bar')`
|
|
232
|
+
* @param fixer The rule fixer.
|
|
233
|
+
* @param node The node which was reported.
|
|
234
|
+
* @param kind The kind of the report.
|
|
235
|
+
* @param isNegative The flag to fix to negative condition.
|
|
236
|
+
*/
|
|
237
|
+
function* fixWithRightOperand(fixer, node, kind, isNegative, isOptional) {
|
|
238
|
+
// left is CallExpression or MemberExpression.
|
|
239
|
+
const leftNode = getLeftNode(node.left);
|
|
240
|
+
const propertyRange = getPropertyRange(leftNode);
|
|
241
|
+
if (isNegative) {
|
|
242
|
+
yield fixer.insertTextBefore(node, '!');
|
|
243
|
+
}
|
|
244
|
+
yield fixer.replaceTextRange([propertyRange[0], node.right.range[0]], `${isOptional ? '?.' : '.'}${kind}sWith(`);
|
|
245
|
+
yield fixer.replaceTextRange([node.right.range[1], node.range[1]], ')');
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Fix code with using the first argument as the search string.
|
|
249
|
+
* For example: `foo.indexOf('bar') === 0` → `foo.startsWith('bar')`
|
|
250
|
+
* @param fixer The rule fixer.
|
|
251
|
+
* @param node The node which was reported.
|
|
252
|
+
* @param kind The kind of the report.
|
|
253
|
+
* @param negative The flag to fix to negative condition.
|
|
254
|
+
*/
|
|
255
|
+
function* fixWithArgument(fixer, node, callNode, calleeNode, kind, negative, isOptional) {
|
|
256
|
+
if (negative) {
|
|
257
|
+
yield fixer.insertTextBefore(node, '!');
|
|
258
|
+
}
|
|
259
|
+
yield fixer.replaceTextRange(getPropertyRange(calleeNode), `${isOptional ? '?.' : '.'}${kind}sWith`);
|
|
260
|
+
yield fixer.removeRange([callNode.range[1], node.range[1]]);
|
|
261
|
+
}
|
|
262
|
+
function getParent(node) {
|
|
263
|
+
return node.parent.type === utils_1.AST_NODE_TYPES.ChainExpression
|
|
264
|
+
? node.parent.parent
|
|
265
|
+
: node.parent;
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
// foo[0] === "a"
|
|
269
|
+
// foo.charAt(0) === "a"
|
|
270
|
+
// foo[foo.length - 1] === "a"
|
|
271
|
+
// foo.charAt(foo.length - 1) === "a"
|
|
272
|
+
[[
|
|
273
|
+
'BinaryExpression > MemberExpression.left[computed=true]',
|
|
274
|
+
'BinaryExpression > CallExpression.left > MemberExpression.callee[property.name="charAt"][computed=false]',
|
|
275
|
+
'BinaryExpression > ChainExpression.left > MemberExpression[computed=true]',
|
|
276
|
+
'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name="charAt"][computed=false]',
|
|
277
|
+
].join(', ')](node) {
|
|
278
|
+
let parentNode = getParent(node);
|
|
279
|
+
let indexNode = null;
|
|
280
|
+
if (parentNode.type === utils_1.AST_NODE_TYPES.CallExpression) {
|
|
281
|
+
if (parentNode.arguments.length === 1) {
|
|
282
|
+
indexNode = parentNode.arguments[0];
|
|
283
|
+
}
|
|
284
|
+
parentNode = getParent(parentNode);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
indexNode = node.property;
|
|
288
|
+
}
|
|
289
|
+
if (indexNode == null ||
|
|
290
|
+
!isEqualityComparison(parentNode) ||
|
|
291
|
+
!isStringType(node.object)) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const isEndsWith = isLastIndexExpression(indexNode, node.object);
|
|
295
|
+
if (allowSingleElementEquality === 'always' && isEndsWith) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const isStartsWith = !isEndsWith && isNumber(indexNode, 0);
|
|
299
|
+
if ((allowSingleElementEquality === 'always' && isStartsWith) ||
|
|
300
|
+
(!isStartsWith && !isEndsWith)) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const eqNode = parentNode;
|
|
304
|
+
context.report({
|
|
305
|
+
node: parentNode,
|
|
306
|
+
messageId: isStartsWith ? 'preferStartsWith' : 'preferEndsWith',
|
|
307
|
+
fix(fixer) {
|
|
308
|
+
// Don't fix if it can change the behavior.
|
|
309
|
+
if (!isCharacter(eqNode.right)) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
return fixWithRightOperand(fixer, eqNode, isStartsWith ? 'start' : 'end', eqNode.operator.startsWith('!'), node.optional);
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
// foo.indexOf('bar') === 0
|
|
317
|
+
[[
|
|
318
|
+
'BinaryExpression > CallExpression.left > MemberExpression.callee[property.name="indexOf"][computed=false]',
|
|
319
|
+
'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name="indexOf"][computed=false]',
|
|
320
|
+
].join(', ')](node) {
|
|
321
|
+
const callNode = getParent(node);
|
|
322
|
+
const parentNode = getParent(callNode);
|
|
323
|
+
if (callNode.arguments.length !== 1 ||
|
|
324
|
+
!isEqualityComparison(parentNode) ||
|
|
325
|
+
!isNumber(parentNode.right, 0) ||
|
|
326
|
+
!isStringType(node.object)) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
context.report({
|
|
330
|
+
node: parentNode,
|
|
331
|
+
messageId: 'preferStartsWith',
|
|
332
|
+
fix(fixer) {
|
|
333
|
+
return fixWithArgument(fixer, parentNode, callNode, node, 'start', parentNode.operator.startsWith('!'), node.optional);
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
|
+
// foo.lastIndexOf('bar') === foo.length - 3
|
|
338
|
+
// foo.lastIndexOf(bar) === foo.length - bar.length
|
|
339
|
+
[[
|
|
340
|
+
'BinaryExpression > CallExpression.left > MemberExpression.callee[property.name="lastIndexOf"][computed=false]',
|
|
341
|
+
'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name="lastIndexOf"][computed=false]',
|
|
342
|
+
].join(', ')](node) {
|
|
343
|
+
const callNode = getParent(node);
|
|
344
|
+
const parentNode = getParent(callNode);
|
|
345
|
+
if (callNode.arguments.length !== 1 ||
|
|
346
|
+
!isEqualityComparison(parentNode) ||
|
|
347
|
+
parentNode.right.type !== utils_1.AST_NODE_TYPES.BinaryExpression ||
|
|
348
|
+
parentNode.right.operator !== '-' ||
|
|
349
|
+
!isLengthExpression(parentNode.right.left, node.object) ||
|
|
350
|
+
!isLengthExpression(parentNode.right.right, callNode.arguments[0]) ||
|
|
351
|
+
!isStringType(node.object)) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
context.report({
|
|
355
|
+
node: parentNode,
|
|
356
|
+
messageId: 'preferEndsWith',
|
|
357
|
+
fix(fixer) {
|
|
358
|
+
return fixWithArgument(fixer, parentNode, callNode, node, 'end', parentNode.operator.startsWith('!'), node.optional);
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
},
|
|
362
|
+
// foo.match(/^bar/) === null
|
|
363
|
+
// foo.match(/bar$/) === null
|
|
364
|
+
[[
|
|
365
|
+
'BinaryExpression > CallExpression.left > MemberExpression.callee[property.name="match"][computed=false]',
|
|
366
|
+
'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression.callee[property.name="match"][computed=false]',
|
|
367
|
+
].join(', ')](node) {
|
|
368
|
+
const callNode = getParent(node);
|
|
369
|
+
const parentNode = getParent(callNode);
|
|
370
|
+
if (!isNull(parentNode.right) || !isStringType(node.object)) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const parsed = callNode.arguments.length === 1
|
|
374
|
+
? parseRegExp(callNode.arguments[0])
|
|
375
|
+
: null;
|
|
376
|
+
if (parsed == null) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const { isStartsWith, text } = parsed;
|
|
380
|
+
context.report({
|
|
381
|
+
node: callNode,
|
|
382
|
+
messageId: isStartsWith ? 'preferStartsWith' : 'preferEndsWith',
|
|
383
|
+
*fix(fixer) {
|
|
384
|
+
if (!parentNode.operator.startsWith('!')) {
|
|
385
|
+
yield fixer.insertTextBefore(parentNode, '!');
|
|
386
|
+
}
|
|
387
|
+
yield fixer.replaceTextRange(getPropertyRange(node), `${node.optional ? '?.' : '.'}${isStartsWith ? 'start' : 'end'}sWith`);
|
|
388
|
+
yield fixer.replaceText(callNode.arguments[0], JSON.stringify(text));
|
|
389
|
+
yield fixer.removeRange([callNode.range[1], parentNode.range[1]]);
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
},
|
|
393
|
+
// foo.slice(0, 3) === 'bar'
|
|
394
|
+
// foo.slice(-3) === 'bar'
|
|
395
|
+
// foo.slice(-3, foo.length) === 'bar'
|
|
396
|
+
// foo.substring(0, 3) === 'bar'
|
|
397
|
+
// foo.substring(foo.length - 3) === 'bar'
|
|
398
|
+
// foo.substring(foo.length - 3, foo.length) === 'bar'
|
|
399
|
+
[[
|
|
400
|
+
'BinaryExpression > CallExpression.left > MemberExpression',
|
|
401
|
+
'BinaryExpression > ChainExpression.left > CallExpression > MemberExpression',
|
|
402
|
+
].join(', ')](node) {
|
|
403
|
+
if (!(0, util_1.isStaticMemberAccessOfValue)(node, context, 'slice', 'substring')) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const callNode = getParent(node);
|
|
407
|
+
const parentNode = getParent(callNode);
|
|
408
|
+
if (!isEqualityComparison(parentNode) || !isStringType(node.object)) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
let isEndsWith = false;
|
|
412
|
+
let isStartsWith = false;
|
|
413
|
+
if (callNode.arguments.length === 1) {
|
|
414
|
+
if (
|
|
415
|
+
// foo.slice(-bar.length) === bar
|
|
416
|
+
// foo.slice(foo.length - bar.length) === bar
|
|
417
|
+
isLengthAheadOfEnd(callNode.arguments[0], parentNode.right, node.object)) {
|
|
418
|
+
isEndsWith = true;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
else if (callNode.arguments.length === 2) {
|
|
422
|
+
if (
|
|
423
|
+
// foo.slice(0, bar.length) === bar
|
|
424
|
+
isNumber(callNode.arguments[0], 0) &&
|
|
425
|
+
isLengthExpression(callNode.arguments[1], parentNode.right)) {
|
|
426
|
+
isStartsWith = true;
|
|
427
|
+
}
|
|
428
|
+
else if (
|
|
429
|
+
// foo.slice(foo.length - bar.length, foo.length) === bar
|
|
430
|
+
// foo.slice(foo.length - bar.length, 0) === bar
|
|
431
|
+
// foo.slice(-bar.length, foo.length) === bar
|
|
432
|
+
// foo.slice(-bar.length, 0) === bar
|
|
433
|
+
(isLengthExpression(callNode.arguments[1], node.object) ||
|
|
434
|
+
isNumber(callNode.arguments[1], 0)) &&
|
|
435
|
+
isLengthAheadOfEnd(callNode.arguments[0], parentNode.right, node.object)) {
|
|
436
|
+
isEndsWith = true;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if (!isStartsWith && !isEndsWith) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const eqNode = parentNode;
|
|
443
|
+
const negativeIndexSupported = node.property.name === 'slice';
|
|
444
|
+
context.report({
|
|
445
|
+
node: parentNode,
|
|
446
|
+
messageId: isStartsWith ? 'preferStartsWith' : 'preferEndsWith',
|
|
447
|
+
fix(fixer) {
|
|
448
|
+
// Don't fix if it can change the behavior.
|
|
449
|
+
if (eqNode.operator.length === 2 &&
|
|
450
|
+
(eqNode.right.type !== utils_1.AST_NODE_TYPES.Literal ||
|
|
451
|
+
typeof eqNode.right.value !== 'string')) {
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
// code being checked is likely mistake:
|
|
455
|
+
// unequal length of strings being checked for equality
|
|
456
|
+
// or reliant on behavior of substring (negative indices interpreted as 0)
|
|
457
|
+
if (isStartsWith) {
|
|
458
|
+
if (!isLengthExpression(callNode.arguments[1], eqNode.right)) {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
const posNode = callNode.arguments[0];
|
|
464
|
+
const posNodeIsAbsolutelyValid = (posNode.type === utils_1.AST_NODE_TYPES.BinaryExpression &&
|
|
465
|
+
posNode.operator === '-' &&
|
|
466
|
+
isLengthExpression(posNode.left, node.object) &&
|
|
467
|
+
isLengthExpression(posNode.right, eqNode.right)) ||
|
|
468
|
+
(negativeIndexSupported &&
|
|
469
|
+
posNode.type === utils_1.AST_NODE_TYPES.UnaryExpression &&
|
|
470
|
+
posNode.operator === '-' &&
|
|
471
|
+
isLengthExpression(posNode.argument, eqNode.right));
|
|
472
|
+
if (!posNodeIsAbsolutelyValid) {
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return fixWithRightOperand(fixer, parentNode, isStartsWith ? 'start' : 'end', parentNode.operator.startsWith('!'), node.optional);
|
|
477
|
+
},
|
|
478
|
+
});
|
|
479
|
+
},
|
|
480
|
+
// /^bar/.test(foo)
|
|
481
|
+
// /bar$/.test(foo)
|
|
482
|
+
'CallExpression > MemberExpression.callee[property.name="test"][computed=false]'(node) {
|
|
483
|
+
const callNode = getParent(node);
|
|
484
|
+
const parsed = callNode.arguments.length === 1 ? parseRegExp(node.object) : null;
|
|
485
|
+
if (parsed == null) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const { isStartsWith, text } = parsed;
|
|
489
|
+
const messageId = isStartsWith ? 'preferStartsWith' : 'preferEndsWith';
|
|
490
|
+
const methodName = isStartsWith ? 'startsWith' : 'endsWith';
|
|
491
|
+
context.report({
|
|
492
|
+
node: callNode,
|
|
493
|
+
messageId,
|
|
494
|
+
*fix(fixer) {
|
|
495
|
+
const argNode = callNode.arguments[0];
|
|
496
|
+
const needsParen = argNode.type !== utils_1.AST_NODE_TYPES.Literal &&
|
|
497
|
+
argNode.type !== utils_1.AST_NODE_TYPES.TemplateLiteral &&
|
|
498
|
+
argNode.type !== utils_1.AST_NODE_TYPES.Identifier &&
|
|
499
|
+
argNode.type !== utils_1.AST_NODE_TYPES.MemberExpression &&
|
|
500
|
+
argNode.type !== utils_1.AST_NODE_TYPES.CallExpression;
|
|
501
|
+
yield fixer.removeRange([callNode.range[0], argNode.range[0]]);
|
|
502
|
+
if (needsParen) {
|
|
503
|
+
yield fixer.insertTextBefore(argNode, '(');
|
|
504
|
+
yield fixer.insertTextAfter(argNode, ')');
|
|
505
|
+
}
|
|
506
|
+
yield fixer.insertTextAfter(argNode, `${node.optional ? '?.' : '.'}${methodName}(${JSON.stringify(text)}`);
|
|
507
|
+
},
|
|
508
|
+
});
|
|
509
|
+
},
|
|
510
|
+
};
|
|
511
|
+
},
|
|
512
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type MessageIds = 'preferExpectErrorComment';
|
|
2
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferExpectErrorComment", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
3
|
+
name: string;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
const util_1 = require("../util");
|
|
5
|
+
exports.default = (0, util_1.createRule)({
|
|
6
|
+
name: 'prefer-ts-expect-error',
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'problem',
|
|
9
|
+
deprecated: {
|
|
10
|
+
deprecatedSince: '7.11.0',
|
|
11
|
+
replacedBy: [
|
|
12
|
+
{
|
|
13
|
+
rule: {
|
|
14
|
+
name: '@typescript-eslint/ban-ts-comment',
|
|
15
|
+
url: 'https://typescript-eslint.io/rules/ban-ts-comment',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
url: 'https://github.com/typescript-eslint/typescript-eslint/pull/9081',
|
|
20
|
+
},
|
|
21
|
+
docs: {
|
|
22
|
+
description: 'Enforce using `@ts-expect-error` over `@ts-ignore`',
|
|
23
|
+
},
|
|
24
|
+
fixable: 'code',
|
|
25
|
+
messages: {
|
|
26
|
+
preferExpectErrorComment: 'Use "@ts-expect-error" to ensure an error is actually being suppressed.',
|
|
27
|
+
},
|
|
28
|
+
replacedBy: ['@typescript-eslint/ban-ts-comment'],
|
|
29
|
+
schema: [],
|
|
30
|
+
},
|
|
31
|
+
defaultOptions: [],
|
|
32
|
+
create(context) {
|
|
33
|
+
const tsIgnoreRegExpSingleLine = /^\s*\/?\s*@ts-ignore/;
|
|
34
|
+
const tsIgnoreRegExpMultiLine = /^\s*(?:\/|\*)*\s*@ts-ignore/;
|
|
35
|
+
function isLineComment(comment) {
|
|
36
|
+
return comment.type === utils_1.AST_TOKEN_TYPES.Line;
|
|
37
|
+
}
|
|
38
|
+
function getLastCommentLine(comment) {
|
|
39
|
+
if (isLineComment(comment)) {
|
|
40
|
+
return comment.value;
|
|
41
|
+
}
|
|
42
|
+
// For multiline comments - we look at only the last line.
|
|
43
|
+
const commentlines = comment.value.split('\n');
|
|
44
|
+
return commentlines[commentlines.length - 1];
|
|
45
|
+
}
|
|
46
|
+
function isValidTsIgnorePresent(comment) {
|
|
47
|
+
const line = getLastCommentLine(comment);
|
|
48
|
+
return isLineComment(comment)
|
|
49
|
+
? tsIgnoreRegExpSingleLine.test(line)
|
|
50
|
+
: tsIgnoreRegExpMultiLine.test(line);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
Program() {
|
|
54
|
+
const comments = context.sourceCode.getAllComments();
|
|
55
|
+
comments.forEach(comment => {
|
|
56
|
+
if (isValidTsIgnorePresent(comment)) {
|
|
57
|
+
const lineCommentRuleFixer = (fixer) => fixer.replaceText(comment, `//${comment.value.replace('@ts-ignore', '@ts-expect-error')}`);
|
|
58
|
+
const blockCommentRuleFixer = (fixer) => fixer.replaceText(comment, `/*${comment.value.replace('@ts-ignore', '@ts-expect-error')}*/`);
|
|
59
|
+
context.report({
|
|
60
|
+
node: comment,
|
|
61
|
+
messageId: 'preferExpectErrorComment',
|
|
62
|
+
fix: isLineComment(comment)
|
|
63
|
+
? lineCommentRuleFixer
|
|
64
|
+
: blockCommentRuleFixer,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Options = [
|
|
2
|
+
{
|
|
3
|
+
allowAny?: boolean;
|
|
4
|
+
allowedPromiseNames?: string[];
|
|
5
|
+
checkArrowFunctions?: boolean;
|
|
6
|
+
checkFunctionDeclarations?: boolean;
|
|
7
|
+
checkFunctionExpressions?: boolean;
|
|
8
|
+
checkMethodDeclarations?: boolean;
|
|
9
|
+
}
|
|
10
|
+
];
|
|
11
|
+
export type MessageIds = 'missingAsync' | 'missingAsyncHybridReturn';
|
|
12
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|