@typescript-eslint/eslint-plugin 7.0.0-alpha.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/configs/all.js +12 -40
- package/dist/configs/all.js.map +1 -1
- package/dist/configs/base.js +0 -6
- package/dist/configs/base.js.map +1 -1
- package/dist/configs/disable-type-checked.js +7 -1
- package/dist/configs/disable-type-checked.js.map +1 -1
- package/dist/configs/eslint-recommended-raw.js +40 -0
- package/dist/configs/eslint-recommended-raw.js.map +1 -0
- package/dist/configs/eslint-recommended.js +10 -27
- package/dist/configs/eslint-recommended.js.map +1 -1
- package/dist/configs/recommended-type-checked.js.map +1 -1
- package/dist/configs/recommended.js.map +1 -1
- package/dist/configs/strict-type-checked.js +4 -0
- package/dist/configs/strict-type-checked.js.map +1 -1
- package/dist/configs/strict.js.map +1 -1
- package/dist/configs/stylistic-type-checked.js.map +1 -1
- package/dist/configs/stylistic.js.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/rules/adjacent-overload-signatures.js +31 -60
- package/dist/rules/adjacent-overload-signatures.js.map +1 -1
- package/dist/rules/array-type.js +7 -32
- package/dist/rules/array-type.js.map +1 -1
- package/dist/rules/await-thenable.js +15 -4
- package/dist/rules/await-thenable.js.map +1 -1
- package/dist/rules/ban-ts-comment.js +32 -34
- package/dist/rules/ban-ts-comment.js.map +1 -1
- package/dist/rules/ban-tslint-comment.js +5 -29
- package/dist/rules/ban-tslint-comment.js.map +1 -1
- package/dist/rules/ban-types.js +4 -27
- package/dist/rules/ban-types.js.map +1 -1
- package/dist/rules/block-spacing.js +11 -34
- package/dist/rules/block-spacing.js.map +1 -1
- package/dist/rules/brace-style.js +10 -9
- package/dist/rules/brace-style.js.map +1 -1
- package/dist/rules/class-literal-property-style.js +20 -31
- package/dist/rules/class-literal-property-style.js.map +1 -1
- package/dist/rules/class-methods-use-this.js +209 -0
- package/dist/rules/class-methods-use-this.js.map +1 -0
- package/dist/rules/comma-dangle.js +11 -31
- package/dist/rules/comma-dangle.js.map +1 -1
- package/dist/rules/comma-spacing.js +11 -12
- package/dist/rules/comma-spacing.js.map +1 -1
- package/dist/rules/consistent-generic-constructors.js +23 -25
- package/dist/rules/consistent-generic-constructors.js.map +1 -1
- package/dist/rules/consistent-indexed-object-style.js +10 -14
- package/dist/rules/consistent-indexed-object-style.js.map +1 -1
- package/dist/rules/consistent-type-assertions.js +36 -21
- package/dist/rules/consistent-type-assertions.js.map +1 -1
- package/dist/rules/consistent-type-definitions.js +14 -40
- package/dist/rules/consistent-type-definitions.js.map +1 -1
- package/dist/rules/consistent-type-exports.js +19 -39
- package/dist/rules/consistent-type-exports.js.map +1 -1
- package/dist/rules/consistent-type-imports.js +88 -101
- package/dist/rules/consistent-type-imports.js.map +1 -1
- package/dist/rules/default-param-last.js +1 -1
- package/dist/rules/default-param-last.js.map +1 -1
- package/dist/rules/dot-notation.js.map +1 -1
- package/dist/rules/enum-utils/shared.js +57 -6
- package/dist/rules/enum-utils/shared.js.map +1 -1
- package/dist/rules/explicit-function-return-type.js +6 -31
- package/dist/rules/explicit-function-return-type.js.map +1 -1
- package/dist/rules/explicit-member-accessibility.js +8 -32
- package/dist/rules/explicit-member-accessibility.js.map +1 -1
- package/dist/rules/explicit-module-boundary-types.js +11 -35
- package/dist/rules/explicit-module-boundary-types.js.map +1 -1
- package/dist/rules/func-call-spacing.js +12 -35
- package/dist/rules/func-call-spacing.js.map +1 -1
- package/dist/rules/indent.js +18 -42
- package/dist/rules/indent.js.map +1 -1
- package/dist/rules/index.js +16 -0
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/init-declarations.js.map +1 -1
- package/dist/rules/key-spacing.js +27 -59
- package/dist/rules/key-spacing.js.map +1 -1
- package/dist/rules/keyword-spacing.js +9 -31
- package/dist/rules/keyword-spacing.js.map +1 -1
- package/dist/rules/lines-around-comment.js +24 -48
- package/dist/rules/lines-around-comment.js.map +1 -1
- package/dist/rules/lines-between-class-members.js +5 -26
- package/dist/rules/lines-between-class-members.js.map +1 -1
- package/dist/rules/max-params.js +67 -0
- package/dist/rules/max-params.js.map +1 -0
- package/dist/rules/member-delimiter-style.js +12 -34
- package/dist/rules/member-delimiter-style.js.map +1 -1
- package/dist/rules/member-ordering.js +48 -40
- package/dist/rules/member-ordering.js.map +1 -1
- package/dist/rules/method-signature-style.js +14 -38
- package/dist/rules/method-signature-style.js.map +1 -1
- package/dist/rules/naming-convention-utils/enums.js +13 -5
- package/dist/rules/naming-convention-utils/enums.js.map +1 -1
- package/dist/rules/naming-convention-utils/format.js.map +1 -1
- package/dist/rules/naming-convention-utils/parse-options.js +3 -25
- package/dist/rules/naming-convention-utils/parse-options.js.map +1 -1
- package/dist/rules/naming-convention-utils/schema.js +8 -33
- package/dist/rules/naming-convention-utils/schema.js.map +1 -1
- package/dist/rules/naming-convention-utils/validator.js +3 -26
- package/dist/rules/naming-convention-utils/validator.js.map +1 -1
- package/dist/rules/naming-convention.js +59 -60
- package/dist/rules/naming-convention.js.map +1 -1
- package/dist/rules/no-array-constructor.js +4 -27
- package/dist/rules/no-array-constructor.js.map +1 -1
- package/dist/rules/no-array-delete.js +81 -0
- package/dist/rules/no-array-delete.js.map +1 -0
- package/dist/rules/no-base-to-string.js +7 -7
- package/dist/rules/no-base-to-string.js.map +1 -1
- package/dist/rules/no-confusing-non-null-assertion.js +5 -30
- package/dist/rules/no-confusing-non-null-assertion.js.map +1 -1
- package/dist/rules/no-confusing-void-expression.js +33 -20
- package/dist/rules/no-confusing-void-expression.js.map +1 -1
- package/dist/rules/no-dupe-class-members.js +3 -37
- package/dist/rules/no-dupe-class-members.js.map +1 -1
- package/dist/rules/no-duplicate-enum-values.js +2 -25
- package/dist/rules/no-duplicate-enum-values.js.map +1 -1
- package/dist/rules/no-duplicate-type-constituents.js +7 -31
- package/dist/rules/no-duplicate-type-constituents.js.map +1 -1
- package/dist/rules/no-dynamic-delete.js +4 -5
- package/dist/rules/no-dynamic-delete.js.map +1 -1
- package/dist/rules/no-empty-function.js +9 -32
- package/dist/rules/no-empty-function.js.map +1 -1
- package/dist/rules/no-empty-interface.js +8 -33
- package/dist/rules/no-empty-interface.js.map +1 -1
- package/dist/rules/no-explicit-any.js +12 -36
- package/dist/rules/no-explicit-any.js.map +1 -1
- package/dist/rules/no-extra-non-null-assertion.js +2 -25
- package/dist/rules/no-extra-non-null-assertion.js.map +1 -1
- package/dist/rules/no-extra-parens.js +47 -86
- package/dist/rules/no-extra-parens.js.map +1 -1
- package/dist/rules/no-extra-semi.js +5 -37
- package/dist/rules/no-extra-semi.js.map +1 -1
- package/dist/rules/no-extraneous-class.js +2 -25
- package/dist/rules/no-extraneous-class.js.map +1 -1
- package/dist/rules/no-floating-promises.js +137 -54
- package/dist/rules/no-floating-promises.js.map +1 -1
- package/dist/rules/no-for-in-array.js +6 -6
- package/dist/rules/no-for-in-array.js.map +1 -1
- package/dist/rules/no-implied-eval.js +7 -7
- package/dist/rules/no-implied-eval.js.map +1 -1
- package/dist/rules/no-import-type-side-effects.js +4 -28
- package/dist/rules/no-import-type-side-effects.js.map +1 -1
- package/dist/rules/no-inferrable-types.js +12 -36
- package/dist/rules/no-inferrable-types.js.map +1 -1
- package/dist/rules/no-invalid-this.js +2 -10
- package/dist/rules/no-invalid-this.js.map +1 -1
- package/dist/rules/no-invalid-void-type.js +6 -30
- package/dist/rules/no-invalid-void-type.js.map +1 -1
- package/dist/rules/no-loop-func.js +4 -28
- package/dist/rules/no-loop-func.js.map +1 -1
- package/dist/rules/no-loss-of-precision.js +5 -32
- package/dist/rules/no-loss-of-precision.js.map +1 -1
- package/dist/rules/no-magic-numbers.js +5 -28
- package/dist/rules/no-magic-numbers.js.map +1 -1
- package/dist/rules/no-meaningless-void-operator.js +4 -5
- package/dist/rules/no-meaningless-void-operator.js.map +1 -1
- package/dist/rules/no-misused-new.js +2 -25
- package/dist/rules/no-misused-new.js.map +1 -1
- package/dist/rules/no-misused-promises.js +5 -5
- package/dist/rules/no-misused-promises.js.map +1 -1
- package/dist/rules/no-mixed-enums.js +6 -7
- package/dist/rules/no-mixed-enums.js.map +1 -1
- package/dist/rules/no-namespace.js +4 -29
- package/dist/rules/no-namespace.js.map +1 -1
- package/dist/rules/no-non-null-asserted-nullish-coalescing.js +5 -29
- package/dist/rules/no-non-null-asserted-nullish-coalescing.js.map +1 -1
- package/dist/rules/no-non-null-asserted-optional-chain.js +2 -25
- package/dist/rules/no-non-null-asserted-optional-chain.js.map +1 -1
- package/dist/rules/no-non-null-assertion.js +20 -46
- package/dist/rules/no-non-null-assertion.js.map +1 -1
- package/dist/rules/no-redeclare.js +7 -31
- package/dist/rules/no-redeclare.js.map +1 -1
- package/dist/rules/no-redundant-type-constituents.js +12 -13
- package/dist/rules/no-redundant-type-constituents.js.map +1 -1
- package/dist/rules/no-require-imports.js +30 -4
- package/dist/rules/no-require-imports.js.map +1 -1
- package/dist/rules/no-restricted-imports.js +100 -77
- package/dist/rules/no-restricted-imports.js.map +1 -1
- package/dist/rules/no-shadow.js +30 -56
- package/dist/rules/no-shadow.js.map +1 -1
- package/dist/rules/no-this-alias.js +2 -25
- package/dist/rules/no-this-alias.js.map +1 -1
- package/dist/rules/no-throw-literal.js +6 -36
- package/dist/rules/no-throw-literal.js.map +1 -1
- package/dist/rules/no-type-alias.js +2 -25
- package/dist/rules/no-type-alias.js.map +1 -1
- package/dist/rules/no-unnecessary-boolean-literal-compare.js +6 -7
- package/dist/rules/no-unnecessary-boolean-literal-compare.js.map +1 -1
- package/dist/rules/no-unnecessary-condition.js +62 -22
- package/dist/rules/no-unnecessary-condition.js.map +1 -1
- package/dist/rules/no-unnecessary-qualifier.js +8 -7
- package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
- package/dist/rules/no-unnecessary-type-arguments.js +5 -6
- package/dist/rules/no-unnecessary-type-arguments.js.map +1 -1
- package/dist/rules/no-unnecessary-type-assertion.js +37 -32
- package/dist/rules/no-unnecessary-type-assertion.js.map +1 -1
- package/dist/rules/no-unnecessary-type-constraint.js +18 -6
- package/dist/rules/no-unnecessary-type-constraint.js.map +1 -1
- package/dist/rules/no-unsafe-argument.js +11 -11
- package/dist/rules/no-unsafe-argument.js.map +1 -1
- package/dist/rules/no-unsafe-assignment.js +15 -17
- package/dist/rules/no-unsafe-assignment.js.map +1 -1
- package/dist/rules/no-unsafe-call.js +5 -6
- package/dist/rules/no-unsafe-call.js.map +1 -1
- package/dist/rules/no-unsafe-declaration-merging.js +4 -27
- package/dist/rules/no-unsafe-declaration-merging.js.map +1 -1
- package/dist/rules/no-unsafe-enum-comparison.js +94 -45
- package/dist/rules/no-unsafe-enum-comparison.js.map +1 -1
- package/dist/rules/no-unsafe-member-access.js +8 -10
- package/dist/rules/no-unsafe-member-access.js.map +1 -1
- package/dist/rules/no-unsafe-return.js +15 -15
- package/dist/rules/no-unsafe-return.js.map +1 -1
- package/dist/rules/no-unsafe-unary-minus.js +68 -0
- package/dist/rules/no-unsafe-unary-minus.js.map +1 -0
- package/dist/rules/no-unused-expressions.js +10 -25
- package/dist/rules/no-unused-expressions.js.map +1 -1
- package/dist/rules/no-unused-vars.js +37 -79
- package/dist/rules/no-unused-vars.js.map +1 -1
- package/dist/rules/no-use-before-define.js +8 -35
- package/dist/rules/no-use-before-define.js.map +1 -1
- package/dist/rules/no-useless-constructor.js +3 -27
- package/dist/rules/no-useless-constructor.js.map +1 -1
- package/dist/rules/no-useless-empty-export.js +18 -36
- package/dist/rules/no-useless-empty-export.js.map +1 -1
- package/dist/rules/no-useless-template-literals.js +138 -0
- package/dist/rules/no-useless-template-literals.js.map +1 -0
- package/dist/rules/no-var-requires.js +36 -39
- package/dist/rules/no-var-requires.js.map +1 -1
- package/dist/rules/non-nullable-type-assertion-style.js +9 -8
- package/dist/rules/non-nullable-type-assertion-style.js.map +1 -1
- package/dist/rules/object-curly-spacing.js +20 -19
- package/dist/rules/object-curly-spacing.js.map +1 -1
- package/dist/rules/padding-line-between-statements.js +28 -54
- package/dist/rules/padding-line-between-statements.js.map +1 -1
- package/dist/rules/parameter-properties.js +4 -29
- package/dist/rules/parameter-properties.js.map +1 -1
- package/dist/rules/prefer-as-const.js +2 -25
- package/dist/rules/prefer-as-const.js.map +1 -1
- package/dist/rules/prefer-destructuring.js +200 -0
- package/dist/rules/prefer-destructuring.js.map +1 -0
- package/dist/rules/prefer-enum-initializers.js +3 -27
- package/dist/rules/prefer-enum-initializers.js.map +1 -1
- package/dist/rules/prefer-find.js +237 -0
- package/dist/rules/prefer-find.js.map +1 -0
- package/dist/rules/prefer-for-of.js +7 -32
- package/dist/rules/prefer-for-of.js.map +1 -1
- package/dist/rules/prefer-function-type.js +9 -32
- package/dist/rules/prefer-function-type.js.map +1 -1
- package/dist/rules/prefer-includes.js +2 -2
- package/dist/rules/prefer-includes.js.map +1 -1
- package/dist/rules/prefer-literal-enum-member.js.map +1 -1
- package/dist/rules/prefer-namespace-keyword.js +4 -28
- package/dist/rules/prefer-namespace-keyword.js.map +1 -1
- package/dist/rules/prefer-nullish-coalescing.js +42 -30
- package/dist/rules/prefer-nullish-coalescing.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +20 -22
- package/dist/rules/prefer-optional-chain-utils/analyzeChain.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/compareNodes.js.map +1 -1
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +8 -10
- package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js.map +1 -1
- package/dist/rules/prefer-optional-chain.js +9 -11
- package/dist/rules/prefer-optional-chain.js.map +1 -1
- package/dist/rules/prefer-promise-reject-errors.js +108 -0
- package/dist/rules/prefer-promise-reject-errors.js.map +1 -0
- package/dist/rules/prefer-readonly-parameter-types.js +8 -31
- package/dist/rules/prefer-readonly-parameter-types.js.map +1 -1
- package/dist/rules/prefer-readonly.js +61 -17
- package/dist/rules/prefer-readonly.js.map +1 -1
- package/dist/rules/prefer-reduce-type-parameter.js +6 -32
- package/dist/rules/prefer-reduce-type-parameter.js.map +1 -1
- package/dist/rules/prefer-regexp-exec.js +8 -10
- package/dist/rules/prefer-regexp-exec.js.map +1 -1
- package/dist/rules/prefer-return-this-type.js +2 -4
- package/dist/rules/prefer-return-this-type.js.map +1 -1
- package/dist/rules/prefer-string-starts-ends-with.js +44 -26
- package/dist/rules/prefer-string-starts-ends-with.js.map +1 -1
- package/dist/rules/prefer-ts-expect-error.js +3 -27
- package/dist/rules/prefer-ts-expect-error.js.map +1 -1
- package/dist/rules/promise-function-async.js +11 -12
- package/dist/rules/promise-function-async.js.map +1 -1
- package/dist/rules/quotes.js +5 -26
- package/dist/rules/quotes.js.map +1 -1
- package/dist/rules/require-array-sort-compare.js +17 -39
- package/dist/rules/require-array-sort-compare.js.map +1 -1
- package/dist/rules/require-await.js +22 -50
- package/dist/rules/require-await.js.map +1 -1
- package/dist/rules/restrict-plus-operands.js +7 -7
- package/dist/rules/restrict-plus-operands.js.map +1 -1
- package/dist/rules/restrict-template-expressions.js +11 -11
- package/dist/rules/restrict-template-expressions.js.map +1 -1
- package/dist/rules/return-await.js +12 -15
- package/dist/rules/return-await.js.map +1 -1
- package/dist/rules/semi.js +4 -25
- package/dist/rules/semi.js.map +1 -1
- package/dist/rules/sort-type-constituents.js +5 -30
- package/dist/rules/sort-type-constituents.js.map +1 -1
- package/dist/rules/space-before-blocks.js +8 -31
- package/dist/rules/space-before-blocks.js.map +1 -1
- package/dist/rules/space-before-function-paren.js +14 -39
- package/dist/rules/space-before-function-paren.js.map +1 -1
- package/dist/rules/space-infix-ops.js +18 -40
- package/dist/rules/space-infix-ops.js.map +1 -1
- package/dist/rules/strict-boolean-expressions.js +94 -85
- package/dist/rules/strict-boolean-expressions.js.map +1 -1
- package/dist/rules/switch-exhaustiveness-check.js +153 -50
- package/dist/rules/switch-exhaustiveness-check.js.map +1 -1
- package/dist/rules/triple-slash-reference.js +3 -27
- package/dist/rules/triple-slash-reference.js.map +1 -1
- package/dist/rules/type-annotation-spacing.js +17 -46
- package/dist/rules/type-annotation-spacing.js.map +1 -1
- package/dist/rules/typedef.js +6 -30
- package/dist/rules/typedef.js.map +1 -1
- package/dist/rules/unbound-method.js +21 -61
- package/dist/rules/unbound-method.js.map +1 -1
- package/dist/rules/unified-signatures.js +12 -37
- package/dist/rules/unified-signatures.js.map +1 -1
- package/dist/util/astUtils.js +4 -4
- package/dist/util/astUtils.js.map +1 -1
- package/dist/util/collectUnusedVariables.js +8 -9
- package/dist/util/collectUnusedVariables.js.map +1 -1
- package/dist/util/explicitReturnTypeUtils.js +43 -34
- package/dist/util/explicitReturnTypeUtils.js.map +1 -1
- package/dist/util/getESLintCoreRule.js +3 -31
- package/dist/util/getESLintCoreRule.js.map +1 -1
- package/dist/util/getFunctionHeadLoc.js +146 -36
- package/dist/util/getFunctionHeadLoc.js.map +1 -1
- package/dist/util/getOperatorPrecedence.js +1 -0
- package/dist/util/getOperatorPrecedence.js.map +1 -1
- package/dist/util/getStaticStringValue.js +46 -0
- package/dist/util/getStaticStringValue.js.map +1 -0
- package/dist/util/getStringLength.js.map +1 -1
- package/dist/util/getThisExpression.js +1 -1
- package/dist/util/getThisExpression.js.map +1 -1
- package/dist/util/getWrappedCode.js +8 -0
- package/dist/util/getWrappedCode.js.map +1 -0
- package/dist/util/getWrappingFixer.js +19 -5
- package/dist/util/getWrappingFixer.js.map +1 -1
- package/dist/util/index.js +1 -0
- package/dist/util/index.js.map +1 -1
- package/dist/util/isNodeEqual.js.map +1 -1
- package/dist/util/misc.js +5 -7
- package/dist/util/misc.js.map +1 -1
- package/dist/util/objectIterators.js.map +1 -1
- package/docs/rules/README.md +44 -7
- package/docs/rules/TEMPLATE.md +5 -1
- package/docs/rules/adjacent-overload-signatures.md +7 -1
- package/docs/rules/array-type.md +14 -6
- package/docs/rules/await-thenable.md +3 -1
- package/docs/rules/ban-ts-comment.md +12 -9
- package/docs/rules/ban-tslint-comment.md +3 -3
- package/docs/rules/ban-types.md +11 -62
- package/docs/rules/block-spacing.md +0 -2
- package/docs/rules/brace-style.md +0 -2
- package/docs/rules/camelcase.md +5 -2
- package/docs/rules/class-literal-property-style.md +5 -14
- package/docs/rules/class-methods-use-this.md +96 -0
- package/docs/rules/comma-dangle.md +0 -2
- package/docs/rules/comma-spacing.md +0 -2
- package/docs/rules/consistent-generic-constructors.md +7 -4
- package/docs/rules/consistent-indexed-object-style.md +12 -12
- package/docs/rules/consistent-type-assertions.md +27 -22
- package/docs/rules/consistent-type-definitions.md +12 -13
- package/docs/rules/consistent-type-exports.md +9 -4
- package/docs/rules/consistent-type-imports.md +9 -6
- package/docs/rules/default-param-last.md +16 -6
- package/docs/rules/dot-notation.md +10 -5
- package/docs/rules/explicit-function-return-type.md +31 -30
- package/docs/rules/explicit-member-accessibility.md +49 -36
- package/docs/rules/explicit-module-boundary-types.md +30 -31
- package/docs/rules/func-call-spacing.md +0 -2
- package/docs/rules/indent.md +0 -2
- package/docs/rules/init-declarations.md +0 -2
- package/docs/rules/key-spacing.md +1 -3
- package/docs/rules/keyword-spacing.md +1 -3
- package/docs/rules/lines-around-comment.md +0 -2
- package/docs/rules/lines-between-class-members.md +2 -10
- package/docs/rules/max-params.md +10 -0
- package/docs/rules/member-delimiter-style.md +4 -1
- package/docs/rules/member-ordering.md +278 -200
- package/docs/rules/method-signature-style.md +7 -4
- package/docs/rules/naming-convention.md +31 -16
- package/docs/rules/no-array-constructor.md +0 -6
- package/docs/rules/no-array-delete.md +40 -0
- package/docs/rules/no-base-to-string.md +2 -2
- package/docs/rules/no-confusing-void-expression.md +3 -3
- package/docs/rules/no-dupe-class-members.md +3 -1
- package/docs/rules/no-duplicate-enum-values.md +8 -0
- package/docs/rules/no-duplicate-imports.md +5 -2
- package/docs/rules/no-duplicate-type-constituents.md +7 -2
- package/docs/rules/no-dynamic-delete.md +1 -1
- package/docs/rules/no-empty-function.md +13 -9
- package/docs/rules/no-empty-interface.md +2 -13
- package/docs/rules/no-explicit-any.md +28 -34
- package/docs/rules/no-extra-non-null-assertion.md +2 -0
- package/docs/rules/no-extra-parens.md +0 -2
- package/docs/rules/no-extra-semi.md +2 -2
- package/docs/rules/no-extraneous-class.md +10 -9
- package/docs/rules/no-floating-promises.md +24 -6
- package/docs/rules/no-for-in-array.md +13 -8
- package/docs/rules/no-implied-eval.md +2 -1
- package/docs/rules/no-import-type-side-effects.md +1 -2
- package/docs/rules/no-inferrable-types.md +4 -4
- package/docs/rules/no-invalid-this.md +3 -1
- package/docs/rules/no-invalid-void-type.md +5 -6
- package/docs/rules/no-loop-func.md +0 -2
- package/docs/rules/no-loss-of-precision.md +0 -2
- package/docs/rules/no-magic-numbers.md +14 -26
- package/docs/rules/no-meaningless-void-operator.md +6 -0
- package/docs/rules/no-misused-new.md +2 -1
- package/docs/rules/no-misused-promises.md +14 -13
- package/docs/rules/no-namespace.md +9 -7
- package/docs/rules/no-non-null-asserted-nullish-coalescing.md +5 -0
- package/docs/rules/no-non-null-asserted-optional-chain.md +5 -0
- package/docs/rules/no-non-null-assertion.md +2 -2
- package/docs/rules/no-parameter-properties.md +12 -0
- package/docs/rules/no-redeclare.md +5 -3
- package/docs/rules/no-redundant-type-constituents.md +14 -0
- package/docs/rules/no-require-imports.md +24 -1
- package/docs/rules/no-restricted-imports.md +24 -16
- package/docs/rules/no-shadow.md +15 -11
- package/docs/rules/no-this-alias.md +73 -3
- package/docs/rules/no-throw-literal.md +9 -11
- package/docs/rules/no-type-alias.md +55 -48
- package/docs/rules/no-unnecessary-boolean-literal-compare.md +5 -5
- package/docs/rules/no-unnecessary-condition.md +18 -2
- package/docs/rules/no-unnecessary-qualifier.md +1 -1
- package/docs/rules/no-unnecessary-type-arguments.md +7 -1
- package/docs/rules/no-unnecessary-type-assertion.md +2 -2
- package/docs/rules/no-unnecessary-type-constraint.md +1 -1
- package/docs/rules/no-unsafe-argument.md +12 -2
- package/docs/rules/no-unsafe-assignment.md +11 -1
- package/docs/rules/no-unsafe-call.md +10 -0
- package/docs/rules/no-unsafe-declaration-merging.md +5 -0
- package/docs/rules/no-unsafe-enum-comparison.md +15 -10
- package/docs/rules/no-unsafe-member-access.md +11 -1
- package/docs/rules/no-unsafe-return.md +11 -1
- package/docs/rules/no-unsafe-unary-minus.md +52 -0
- package/docs/rules/no-unused-expressions.md +0 -2
- package/docs/rules/no-unused-vars.md +17 -2
- package/docs/rules/no-use-before-define.md +4 -14
- package/docs/rules/no-useless-constructor.md +0 -2
- package/docs/rules/no-useless-empty-export.md +4 -0
- package/docs/rules/no-useless-template-literals.md +57 -0
- package/docs/rules/no-var-requires.md +24 -1
- package/docs/rules/non-nullable-type-assertion-style.md +1 -1
- package/docs/rules/object-curly-spacing.md +0 -2
- package/docs/rules/padding-line-between-statements.md +3 -5
- package/docs/rules/parameter-properties.md +22 -19
- package/docs/rules/prefer-as-const.md +4 -1
- package/docs/rules/prefer-destructuring.md +91 -0
- package/docs/rules/prefer-enum-initializers.md +1 -1
- package/docs/rules/prefer-find.md +39 -0
- package/docs/rules/prefer-for-of.md +3 -5
- package/docs/rules/prefer-function-type.md +1 -1
- package/docs/rules/prefer-includes.md +1 -3
- package/docs/rules/prefer-literal-enum-member.md +6 -4
- package/docs/rules/prefer-namespace-keyword.md +1 -1
- package/docs/rules/prefer-nullish-coalescing.md +27 -15
- package/docs/rules/prefer-optional-chain.md +18 -17
- package/docs/rules/prefer-promise-reject-errors.md +50 -0
- package/docs/rules/prefer-readonly-parameter-types.md +58 -32
- package/docs/rules/prefer-readonly.md +19 -4
- package/docs/rules/prefer-reduce-type-parameter.md +3 -1
- package/docs/rules/prefer-string-starts-ends-with.md +2 -1
- package/docs/rules/prefer-ts-expect-error.md +1 -0
- package/docs/rules/promise-function-async.md +73 -0
- package/docs/rules/quotes.md +0 -2
- package/docs/rules/require-array-sort-compare.md +7 -7
- package/docs/rules/require-await.md +2 -2
- package/docs/rules/restrict-plus-operands.md +16 -16
- package/docs/rules/restrict-template-expressions.md +11 -7
- package/docs/rules/return-await.md +8 -8
- package/docs/rules/semi.md +0 -4
- package/docs/rules/sort-type-constituents.md +62 -0
- package/docs/rules/space-before-blocks.md +5 -4
- package/docs/rules/space-before-function-paren.md +0 -2
- package/docs/rules/strict-boolean-expressions.md +7 -0
- package/docs/rules/switch-exhaustiveness-check.md +127 -8
- package/docs/rules/triple-slash-reference.md +76 -25
- package/docs/rules/type-annotation-spacing.md +8 -8
- package/docs/rules/typedef.md +19 -19
- package/docs/rules/unbound-method.md +4 -2
- package/docs/rules/unified-signatures.md +11 -2
- package/index.d.ts +6 -2
- package/package.json +31 -23
- package/rules.d.ts +46 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Require using Error objects as Promise rejection reasons.'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
|
+
>
|
|
7
|
+
> See **https://typescript-eslint.io/rules/prefer-promise-reject-errors** for documentation.
|
|
8
|
+
|
|
9
|
+
This rule extends the base [`eslint/prefer-promise-reject-errors`](https://eslint.org/docs/rules/prefer-promise-reject-errors) rule.
|
|
10
|
+
It uses type information to enforce that `Promise`s are only rejected with `Error` objects.
|
|
11
|
+
|
|
12
|
+
## Examples
|
|
13
|
+
|
|
14
|
+
<!--tabs-->
|
|
15
|
+
|
|
16
|
+
### ❌ Incorrect
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
Promise.reject('error');
|
|
20
|
+
|
|
21
|
+
const err = new Error();
|
|
22
|
+
Promise.reject('an ' + err);
|
|
23
|
+
|
|
24
|
+
new Promise((resolve, reject) => reject('error'));
|
|
25
|
+
|
|
26
|
+
new Promise((resolve, reject) => {
|
|
27
|
+
const err = new Error();
|
|
28
|
+
reject('an ' + err);
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### ✅ Correct
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
Promise.reject(new Error());
|
|
36
|
+
|
|
37
|
+
class CustomError extends Error {
|
|
38
|
+
// ...
|
|
39
|
+
}
|
|
40
|
+
Promise.reject(new CustomError());
|
|
41
|
+
|
|
42
|
+
new Promise((resolve, reject) => reject(new Error()));
|
|
43
|
+
|
|
44
|
+
new Promise((resolve, reject) => {
|
|
45
|
+
class CustomError extends Error {
|
|
46
|
+
// ...
|
|
47
|
+
}
|
|
48
|
+
return reject(new CustomError());
|
|
49
|
+
});
|
|
50
|
+
```
|
|
@@ -57,7 +57,7 @@ interface Foo {
|
|
|
57
57
|
interface Foo {
|
|
58
58
|
new (arg: string[]): void;
|
|
59
59
|
}
|
|
60
|
-
const x = { foo(arg: string[]): void
|
|
60
|
+
const x = { foo(arg: string[]): void {} };
|
|
61
61
|
function foo(arg: string[]);
|
|
62
62
|
type Foo = (arg: string[]) => void;
|
|
63
63
|
interface Foo {
|
|
@@ -91,7 +91,7 @@ interface CustomFunction {
|
|
|
91
91
|
}
|
|
92
92
|
function custom2(arg: CustomFunction) {}
|
|
93
93
|
|
|
94
|
-
function union(arg: readonly string[] | ReadonlyArray<number
|
|
94
|
+
function union(arg: readonly string[] | ReadonlyArray<number>) {}
|
|
95
95
|
|
|
96
96
|
function primitive1(arg: string) {}
|
|
97
97
|
function primitive2(arg: number) {}
|
|
@@ -105,8 +105,11 @@ function primitive9(arg: string | number | undefined) {}
|
|
|
105
105
|
|
|
106
106
|
function fnSig(arg: () => void) {}
|
|
107
107
|
|
|
108
|
-
enum Foo {
|
|
109
|
-
|
|
108
|
+
enum Foo {
|
|
109
|
+
a,
|
|
110
|
+
b,
|
|
111
|
+
}
|
|
112
|
+
function enumArg(arg: Foo) {}
|
|
110
113
|
|
|
111
114
|
function symb1(arg: symbol) {}
|
|
112
115
|
const customSymbol = Symbol('a');
|
|
@@ -119,7 +122,7 @@ interface Foo {
|
|
|
119
122
|
interface Foo {
|
|
120
123
|
new (arg: readonly string[]): void;
|
|
121
124
|
}
|
|
122
|
-
const x = { foo(arg: readonly string[]): void
|
|
125
|
+
const x = { foo(arg: readonly string[]): void {} };
|
|
123
126
|
function foo(arg: readonly string[]);
|
|
124
127
|
type Foo = (arg: readonly string[]) => void;
|
|
125
128
|
interface Foo {
|
|
@@ -158,7 +161,7 @@ Examples of code for this rule with:
|
|
|
158
161
|
|
|
159
162
|
#### ❌ Incorrect
|
|
160
163
|
|
|
161
|
-
```ts
|
|
164
|
+
```ts option='{"allow":["$",{"source":"file","name":"Foo"},{"source":"lib","name":"HTMLElement"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
|
162
165
|
interface ThisIsMutable {
|
|
163
166
|
prop: string;
|
|
164
167
|
}
|
|
@@ -172,12 +175,17 @@ interface WrapperWithOther {
|
|
|
172
175
|
otherProp: string;
|
|
173
176
|
}
|
|
174
177
|
|
|
175
|
-
|
|
176
|
-
function
|
|
177
|
-
|
|
178
|
+
// Incorrect because ThisIsMutable is not readonly
|
|
179
|
+
function fn1(arg: ThisIsMutable) {}
|
|
180
|
+
|
|
181
|
+
// Incorrect because Wrapper.sub is not readonly
|
|
182
|
+
function fn2(arg: Wrapper) {}
|
|
183
|
+
|
|
184
|
+
// Incorrect because WrapperWithOther.otherProp is not readonly and not in the allowlist
|
|
185
|
+
function fn3(arg: WrapperWithOther) {}
|
|
178
186
|
```
|
|
179
187
|
|
|
180
|
-
```ts
|
|
188
|
+
```ts option='{"allow":["$",{"source":"file","name":"Foo"},{"source":"lib","name":"HTMLElement"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
|
181
189
|
import { Foo } from 'some-lib';
|
|
182
190
|
import { Bar } from 'incorrect-lib';
|
|
183
191
|
|
|
@@ -185,14 +193,19 @@ interface HTMLElement {
|
|
|
185
193
|
prop: string;
|
|
186
194
|
}
|
|
187
195
|
|
|
188
|
-
|
|
189
|
-
function
|
|
190
|
-
|
|
196
|
+
// Incorrect because Foo is not a local type
|
|
197
|
+
function fn1(arg: Foo) {}
|
|
198
|
+
|
|
199
|
+
// Incorrect because HTMLElement is not from the default library
|
|
200
|
+
function fn2(arg: HTMLElement) {}
|
|
201
|
+
|
|
202
|
+
// Incorrect because Bar is not from "bar-lib"
|
|
203
|
+
function fn3(arg: Bar) {}
|
|
191
204
|
```
|
|
192
205
|
|
|
193
206
|
#### ✅ Correct
|
|
194
207
|
|
|
195
|
-
```ts
|
|
208
|
+
```ts option='{"allow":["$",{"source":"file","name":"Foo"},{"source":"lib","name":"HTMLElement"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
|
196
209
|
interface Foo {
|
|
197
210
|
prop: string;
|
|
198
211
|
}
|
|
@@ -202,26 +215,35 @@ interface Wrapper {
|
|
|
202
215
|
readonly otherProp: string;
|
|
203
216
|
}
|
|
204
217
|
|
|
205
|
-
|
|
206
|
-
function
|
|
218
|
+
// Works because Foo is allowed
|
|
219
|
+
function fn1(arg: Foo) {}
|
|
220
|
+
|
|
221
|
+
// Works even when Foo is nested somewhere in the type, with other properties still being checked
|
|
222
|
+
function fn2(arg: Wrapper) {}
|
|
207
223
|
```
|
|
208
224
|
|
|
209
|
-
```ts
|
|
225
|
+
```ts option='{"allow":["$",{"source":"file","name":"Foo"},{"source":"lib","name":"HTMLElement"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
|
210
226
|
import { Bar } from 'bar-lib';
|
|
211
227
|
|
|
212
228
|
interface Foo {
|
|
213
229
|
prop: string;
|
|
214
230
|
}
|
|
215
231
|
|
|
216
|
-
|
|
217
|
-
function
|
|
218
|
-
|
|
232
|
+
// Works because Foo is a local type
|
|
233
|
+
function fn1(arg: Foo) {}
|
|
234
|
+
|
|
235
|
+
// Works because HTMLElement is from the default library
|
|
236
|
+
function fn2(arg: HTMLElement) {}
|
|
237
|
+
|
|
238
|
+
// Works because Bar is from "bar-lib"
|
|
239
|
+
function fn3(arg: Bar) {}
|
|
219
240
|
```
|
|
220
241
|
|
|
221
|
-
```ts
|
|
242
|
+
```ts option='{"allow":["$",{"source":"file","name":"Foo"},{"source":"lib","name":"HTMLElement"},{"from":"package","name":"Bar","package":"bar-lib"}]}'
|
|
222
243
|
import { Foo } from './foo';
|
|
223
244
|
|
|
224
|
-
|
|
245
|
+
// Works because Foo is still a local type - it has to be in the same package
|
|
246
|
+
function fn(arg: Foo) {}
|
|
225
247
|
```
|
|
226
248
|
|
|
227
249
|
### `checkParameterProperties`
|
|
@@ -235,7 +257,7 @@ Examples of code for this rule with `{checkParameterProperties: true}`:
|
|
|
235
257
|
|
|
236
258
|
#### ❌ Incorrect
|
|
237
259
|
|
|
238
|
-
```ts
|
|
260
|
+
```ts option='{ "checkParameterProperties": true }'
|
|
239
261
|
class Foo {
|
|
240
262
|
constructor(private paramProp: string[]) {}
|
|
241
263
|
}
|
|
@@ -243,7 +265,7 @@ class Foo {
|
|
|
243
265
|
|
|
244
266
|
#### ✅ Correct
|
|
245
267
|
|
|
246
|
-
```ts
|
|
268
|
+
```ts option='{ "checkParameterProperties": true }'
|
|
247
269
|
class Foo {
|
|
248
270
|
constructor(private paramProp: readonly string[]) {}
|
|
249
271
|
}
|
|
@@ -253,7 +275,7 @@ class Foo {
|
|
|
253
275
|
|
|
254
276
|
Examples of **correct** code for this rule with `{checkParameterProperties: false}`:
|
|
255
277
|
|
|
256
|
-
```ts
|
|
278
|
+
```ts option='{ "checkParameterProperties": false }' showPlaygroundButton
|
|
257
279
|
class Foo {
|
|
258
280
|
constructor(
|
|
259
281
|
private paramProp1: string[],
|
|
@@ -272,7 +294,7 @@ Examples of code for this rule with `{ignoreInferredTypes: true}`:
|
|
|
272
294
|
|
|
273
295
|
#### ❌ Incorrect
|
|
274
296
|
|
|
275
|
-
```ts
|
|
297
|
+
```ts option='{ "ignoreInferredTypes": true }'
|
|
276
298
|
import { acceptsCallback, CallbackOptions } from 'external-dependency';
|
|
277
299
|
|
|
278
300
|
acceptsCallback((options: CallbackOptions) => {});
|
|
@@ -281,7 +303,7 @@ acceptsCallback((options: CallbackOptions) => {});
|
|
|
281
303
|
<details>
|
|
282
304
|
<summary>external-dependency.d.ts</summary>
|
|
283
305
|
|
|
284
|
-
```ts
|
|
306
|
+
```ts option='{ "ignoreInferredTypes": true }'
|
|
285
307
|
export interface CallbackOptions {
|
|
286
308
|
prop: string;
|
|
287
309
|
}
|
|
@@ -295,7 +317,7 @@ export const acceptsCallback: AcceptsCallback;
|
|
|
295
317
|
|
|
296
318
|
#### ✅ Correct
|
|
297
319
|
|
|
298
|
-
```ts
|
|
320
|
+
```ts option='{ "ignoreInferredTypes": true }'
|
|
299
321
|
import { acceptsCallback } from 'external-dependency';
|
|
300
322
|
|
|
301
323
|
acceptsCallback(options => {});
|
|
@@ -304,7 +326,7 @@ acceptsCallback(options => {});
|
|
|
304
326
|
<details>
|
|
305
327
|
<summary>external-dependency.d.ts</summary>
|
|
306
328
|
|
|
307
|
-
```ts
|
|
329
|
+
```ts option='{ "ignoreInferredTypes": true }'
|
|
308
330
|
export interface CallbackOptions {
|
|
309
331
|
prop: string;
|
|
310
332
|
}
|
|
@@ -326,7 +348,7 @@ Examples of code for this rule with `{treatMethodsAsReadonly: false}`:
|
|
|
326
348
|
|
|
327
349
|
#### ❌ Incorrect
|
|
328
350
|
|
|
329
|
-
```ts
|
|
351
|
+
```ts option='{ "treatMethodsAsReadonly": false }'
|
|
330
352
|
type MyType = {
|
|
331
353
|
readonly prop: string;
|
|
332
354
|
method(): string; // note: this method is mutable
|
|
@@ -336,7 +358,7 @@ function foo(arg: MyType) {}
|
|
|
336
358
|
|
|
337
359
|
#### ✅ Correct
|
|
338
360
|
|
|
339
|
-
```ts
|
|
361
|
+
```ts option='{ "treatMethodsAsReadonly": false }'
|
|
340
362
|
type MyType = Readonly<{
|
|
341
363
|
prop: string;
|
|
342
364
|
method(): string;
|
|
@@ -354,10 +376,14 @@ function bar(arg: MyOtherType) {}
|
|
|
354
376
|
|
|
355
377
|
Examples of **correct** code for this rule with `{treatMethodsAsReadonly: true}`:
|
|
356
378
|
|
|
357
|
-
```ts
|
|
379
|
+
```ts option='{ "treatMethodsAsReadonly": true }' showPlaygroundButton
|
|
358
380
|
type MyType = {
|
|
359
381
|
readonly prop: string;
|
|
360
382
|
method(): string; // note: this method is mutable
|
|
361
383
|
};
|
|
362
384
|
function foo(arg: MyType) {}
|
|
363
385
|
```
|
|
386
|
+
|
|
387
|
+
## When Not To Use It
|
|
388
|
+
|
|
389
|
+
If your project does not attempt to enforce strong immutability guarantees of parameters, you can avoid this rule.
|
|
@@ -6,7 +6,7 @@ description: "Require private members to be marked as `readonly` if they're neve
|
|
|
6
6
|
>
|
|
7
7
|
> See **https://typescript-eslint.io/rules/prefer-readonly** for documentation.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Private member variables (whether using the `private` modifier or private `#` fields) are never permitted to be modified outside of their declaring class.
|
|
10
10
|
If that class never modifies their value, they may safely be marked as `readonly`.
|
|
11
11
|
|
|
12
12
|
This rule reports on private members are marked as `readonly` if they're never modified outside of the constructor.
|
|
@@ -22,6 +22,7 @@ class Container {
|
|
|
22
22
|
// These member variables could be marked as readonly
|
|
23
23
|
private neverModifiedMember = true;
|
|
24
24
|
private onlyModifiedInConstructor: number;
|
|
25
|
+
#neverModifiedPrivateField = 3;
|
|
25
26
|
|
|
26
27
|
public constructor(
|
|
27
28
|
onlyModifiedInConstructor: number,
|
|
@@ -49,6 +50,13 @@ class Container {
|
|
|
49
50
|
public mutate() {
|
|
50
51
|
this.modifiedLater = 'mutated';
|
|
51
52
|
}
|
|
53
|
+
|
|
54
|
+
// This is modified later on by the class
|
|
55
|
+
#modifiedLaterPrivateField = 'unchanged';
|
|
56
|
+
|
|
57
|
+
public mutatePrivateField() {
|
|
58
|
+
this.#modifiedLaterPrivateField = 'mutated';
|
|
59
|
+
}
|
|
52
60
|
}
|
|
53
61
|
```
|
|
54
62
|
|
|
@@ -60,7 +68,10 @@ You may pass `"onlyInlineLambdas": true` as a rule option within an object to re
|
|
|
60
68
|
|
|
61
69
|
```jsonc
|
|
62
70
|
{
|
|
63
|
-
"@typescript-eslint/prefer-readonly": [
|
|
71
|
+
"@typescript-eslint/prefer-readonly": [
|
|
72
|
+
"error",
|
|
73
|
+
{ "onlyInlineLambdas": true },
|
|
74
|
+
],
|
|
64
75
|
}
|
|
65
76
|
```
|
|
66
77
|
|
|
@@ -70,7 +81,7 @@ Example of code for the `{ "onlyInlineLambdas": true }` options:
|
|
|
70
81
|
|
|
71
82
|
#### ❌ Incorrect
|
|
72
83
|
|
|
73
|
-
```ts
|
|
84
|
+
```ts option='{ "onlyInlineLambdas": true }'
|
|
74
85
|
class Container {
|
|
75
86
|
private onClick = () => {
|
|
76
87
|
/* ... */
|
|
@@ -80,8 +91,12 @@ class Container {
|
|
|
80
91
|
|
|
81
92
|
#### ✅ Correct
|
|
82
93
|
|
|
83
|
-
```ts
|
|
94
|
+
```ts option='{ "onlyInlineLambdas": true }'
|
|
84
95
|
class Container {
|
|
85
96
|
private neverModifiedPrivate = 'unchanged';
|
|
86
97
|
}
|
|
87
98
|
```
|
|
99
|
+
|
|
100
|
+
## When Not To Use It
|
|
101
|
+
|
|
102
|
+
If you aren't trying to enforce strong immutability guarantees, this rule may be too restrictive for your project.
|
|
@@ -55,4 +55,6 @@ It will suggest instead pass the asserted type to `Array#reduce` as a generic ty
|
|
|
55
55
|
|
|
56
56
|
## When Not To Use It
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
This rule can sometimes be difficult to work around when creating objects using a `.reduce`.
|
|
59
|
+
See [[prefer-reduce-type-parameter] unfixable reporting #3440](https://github.com/typescript-eslint/typescript-eslint/issues/3440) for more details.
|
|
60
|
+
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
|
|
@@ -54,4 +54,5 @@ foo.endsWith('bar');
|
|
|
54
54
|
|
|
55
55
|
## When Not To Use It
|
|
56
56
|
|
|
57
|
-
If you don't mind
|
|
57
|
+
If you don't mind which style of string checking is used, you can turn this rule off safely.
|
|
58
|
+
However, keep in mind that inconsistent style can harm readability in a project.
|
|
@@ -63,6 +63,7 @@ const isOptionEnabled = (key: string): boolean => {
|
|
|
63
63
|
## When Not To Use It
|
|
64
64
|
|
|
65
65
|
If you are compiling against multiple versions of TypeScript and using `@ts-ignore` to ignore version-specific type errors, this rule might get in your way.
|
|
66
|
+
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
|
|
66
67
|
|
|
67
68
|
## Further Reading
|
|
68
69
|
|
|
@@ -57,3 +57,76 @@ async function functionReturnsUnionWithPromiseImplicitly(p: boolean) {
|
|
|
57
57
|
return p ? 'value' : Promise.resolve('value');
|
|
58
58
|
}
|
|
59
59
|
```
|
|
60
|
+
|
|
61
|
+
## Options
|
|
62
|
+
|
|
63
|
+
### `allowAny`
|
|
64
|
+
|
|
65
|
+
Whether to ignore functions that return `any` and `unknown`.
|
|
66
|
+
If you want additional safety, consider turning this option off, as it makes the rule less able to catch incorrect Promise behaviors.
|
|
67
|
+
|
|
68
|
+
Examples of code with `{ "allowAny": false }`:
|
|
69
|
+
|
|
70
|
+
<!--tabs-->
|
|
71
|
+
|
|
72
|
+
#### ❌ Incorrect
|
|
73
|
+
|
|
74
|
+
```ts option='{ "allowAny": false }'
|
|
75
|
+
const returnsAny = () => ({}) as any;
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### ✅ Correct
|
|
79
|
+
|
|
80
|
+
```ts option='{ "allowAny": false }'
|
|
81
|
+
const returnsAny = async () => ({}) as any;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### `allowedPromiseNames`
|
|
85
|
+
|
|
86
|
+
For projects that use constructs other than the global built-in `Promise` for asynchronous code.
|
|
87
|
+
This option allows specifying string names of classes or interfaces that cause a function to be checked as well.
|
|
88
|
+
|
|
89
|
+
Examples of code with `{ "allowedPromiseNames": ["Bluebird"] }`:
|
|
90
|
+
|
|
91
|
+
<!--tabs-->
|
|
92
|
+
|
|
93
|
+
#### ❌ Incorrect
|
|
94
|
+
|
|
95
|
+
```ts option='{ "allowedPromiseNames": ["Bluebird"] }'
|
|
96
|
+
import { Bluebird } from 'bluebird';
|
|
97
|
+
|
|
98
|
+
const returnsBluebird = () => new Bluebird(() => {});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### ✅ Correct
|
|
102
|
+
|
|
103
|
+
```ts option='{ "allowedPromiseNames": ["Bluebird"] }'
|
|
104
|
+
import { Bluebird } from 'bluebird';
|
|
105
|
+
|
|
106
|
+
const returnsBluebird = async () => new Bluebird(() => {});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `checkArrowFunctions`
|
|
110
|
+
|
|
111
|
+
Whether to check arrow functions.
|
|
112
|
+
`true` by default, but can be set to `false` to ignore them.
|
|
113
|
+
|
|
114
|
+
### `checkFunctionDeclarations`
|
|
115
|
+
|
|
116
|
+
Whether to check standalone function declarations.
|
|
117
|
+
`true` by default, but can be set to `false` to ignore them.
|
|
118
|
+
|
|
119
|
+
### `checkFunctionExpressions`
|
|
120
|
+
|
|
121
|
+
Whether to check inline function expressions.
|
|
122
|
+
`true` by default, but can be set to `false` to ignore them.
|
|
123
|
+
|
|
124
|
+
### `checkMethodDeclarations`
|
|
125
|
+
|
|
126
|
+
Whether to check methods on classes and object literals
|
|
127
|
+
`true` by default, but can be set to `false` to ignore them.
|
|
128
|
+
|
|
129
|
+
## When Not To Use It
|
|
130
|
+
|
|
131
|
+
This rule can be difficult to enable on projects that use APIs which require functions to always be `async`.
|
|
132
|
+
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) along with filing issues on your dependencies for those specific situations instead of completely disabling this rule.
|
package/docs/rules/quotes.md
CHANGED
|
@@ -6,7 +6,5 @@ description: 'Enforce the consistent use of either backticks, double, or single
|
|
|
6
6
|
>
|
|
7
7
|
> See **https://typescript-eslint.io/rules/quotes** for documentation.
|
|
8
8
|
|
|
9
|
-
## Examples
|
|
10
|
-
|
|
11
9
|
This rule extends the base [`eslint/quotes`](https://eslint.org/docs/rules/quotes) rule.
|
|
12
10
|
It adds support for TypeScript features which allow quoted names, but not backtick quoted names.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: 'Require `Array#sort` calls to always provide a `compareFunction`.'
|
|
2
|
+
description: 'Require `Array#sort` and `Array#toSorted` calls to always provide a `compareFunction`.'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
> 🛑 This file is source code, not the primary documentation location! 🛑
|
|
6
6
|
>
|
|
7
7
|
> See **https://typescript-eslint.io/rules/require-array-sort-compare** for documentation.
|
|
8
8
|
|
|
9
|
-
When called without a compare function, `Array#sort()` converts all non-undefined array elements into strings and then compares said strings based off their UTF-16 code units [[ECMA specification](https://www.ecma-international.org/ecma-262/9.0/#sec-sortcompare)].
|
|
9
|
+
When called without a compare function, `Array#sort()` and `Array#toSorted()` converts all non-undefined array elements into strings and then compares said strings based off their UTF-16 code units [[ECMA specification](https://www.ecma-international.org/ecma-262/9.0/#sec-sortcompare)].
|
|
10
10
|
|
|
11
11
|
The result is that elements are sorted alphabetically, regardless of their type.
|
|
12
12
|
For example, when sorting numbers, this results in a "10 before 2" order:
|
|
@@ -15,11 +15,11 @@ For example, when sorting numbers, this results in a "10 before 2" order:
|
|
|
15
15
|
[1, 2, 3, 10, 20, 30].sort(); //→ [1, 10, 2, 20, 3, 30]
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
This rule reports on any call to the
|
|
18
|
+
This rule reports on any call to the sort methods that do not provide a `compare` argument.
|
|
19
19
|
|
|
20
20
|
## Examples
|
|
21
21
|
|
|
22
|
-
This rule aims to ensure all calls of the native
|
|
22
|
+
This rule aims to ensure all calls of the native sort methods provide a `compareFunction`, while ignoring calls to user-defined methods.
|
|
23
23
|
|
|
24
24
|
<!--tabs-->
|
|
25
25
|
|
|
@@ -57,7 +57,7 @@ Examples of code for this rule with `{ ignoreStringArrays: true }`:
|
|
|
57
57
|
|
|
58
58
|
#### ❌ Incorrect
|
|
59
59
|
|
|
60
|
-
```ts
|
|
60
|
+
```ts option='{ "ignoreStringArrays": true }'
|
|
61
61
|
const one = 1;
|
|
62
62
|
const two = 2;
|
|
63
63
|
const three = 3;
|
|
@@ -66,7 +66,7 @@ const three = 3;
|
|
|
66
66
|
|
|
67
67
|
#### ✅ Correct
|
|
68
68
|
|
|
69
|
-
```ts
|
|
69
|
+
```ts option='{ "ignoreStringArrays": true }'
|
|
70
70
|
const one = '1';
|
|
71
71
|
const two = '2';
|
|
72
72
|
const three = '3';
|
|
@@ -75,4 +75,4 @@ const three = '3';
|
|
|
75
75
|
|
|
76
76
|
## When Not To Use It
|
|
77
77
|
|
|
78
|
-
If you
|
|
78
|
+
If you intentionally want your arrays to be always sorted in a string-like manner, you can turn this rule off safely.
|
|
@@ -6,11 +6,11 @@ description: 'Disallow async functions which have no `await` expression.'
|
|
|
6
6
|
>
|
|
7
7
|
> See **https://typescript-eslint.io/rules/require-await** for documentation.
|
|
8
8
|
|
|
9
|
-
## Examples
|
|
10
|
-
|
|
11
9
|
This rule extends the base [`eslint/require-await`](https://eslint.org/docs/rules/require-await) rule.
|
|
12
10
|
It uses type information to add support for `async` functions that return a `Promise`.
|
|
13
11
|
|
|
12
|
+
## Examples
|
|
13
|
+
|
|
14
14
|
Examples of **correct** code for this rule:
|
|
15
15
|
|
|
16
16
|
```ts
|
|
@@ -18,15 +18,15 @@ This rule reports when a `+` operation combines two values of different types, o
|
|
|
18
18
|
### ❌ Incorrect
|
|
19
19
|
|
|
20
20
|
```ts
|
|
21
|
-
let foo = '5.5' + 5;
|
|
22
21
|
let foo = 1n + 1;
|
|
22
|
+
let fn = (a: string, b: never) => a + b;
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### ✅ Correct
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
|
-
let foo = parseInt('5.5', 10) + 10;
|
|
29
28
|
let foo = 1n + 1n;
|
|
29
|
+
let fn = (a: string, b: string) => a + b;
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
## Options
|
|
@@ -74,14 +74,14 @@ Examples of code for this rule with `{ allowAny: true }`:
|
|
|
74
74
|
|
|
75
75
|
#### ❌ Incorrect
|
|
76
76
|
|
|
77
|
-
```ts
|
|
77
|
+
```ts option='{ "allowAny": true }'
|
|
78
78
|
let fn = (a: number, b: []) => a + b;
|
|
79
79
|
let fn = (a: string, b: []) => a + b;
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
#### ✅ Correct
|
|
83
83
|
|
|
84
|
-
```ts
|
|
84
|
+
```ts option='{ "allowAny": true }'
|
|
85
85
|
let fn = (a: number, b: any) => a + b;
|
|
86
86
|
let fn = (a: string, b: any) => a + b;
|
|
87
87
|
```
|
|
@@ -94,14 +94,14 @@ Examples of code for this rule with `{ allowBoolean: true }`:
|
|
|
94
94
|
|
|
95
95
|
#### ❌ Incorrect
|
|
96
96
|
|
|
97
|
-
```ts
|
|
97
|
+
```ts option='{ "allowBoolean": true }'
|
|
98
98
|
let fn = (a: number, b: unknown) => a + b;
|
|
99
99
|
let fn = (a: string, b: unknown) => a + b;
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
#### ✅ Correct
|
|
103
103
|
|
|
104
|
-
```ts
|
|
104
|
+
```ts option='{ "allowBoolean": true }'
|
|
105
105
|
let fn = (a: number, b: boolean) => a + b;
|
|
106
106
|
let fn = (a: string, b: boolean) => a + b;
|
|
107
107
|
```
|
|
@@ -114,7 +114,7 @@ Examples of code for this rule with `{ allowNullish: true }`:
|
|
|
114
114
|
|
|
115
115
|
#### ❌ Incorrect
|
|
116
116
|
|
|
117
|
-
```ts
|
|
117
|
+
```ts option='{ "allowNullish": true }'
|
|
118
118
|
let fn = (a: number, b: unknown) => a + b;
|
|
119
119
|
let fn = (a: number, b: never) => a + b;
|
|
120
120
|
let fn = (a: string, b: unknown) => a + b;
|
|
@@ -123,7 +123,7 @@ let fn = (a: string, b: never) => a + b;
|
|
|
123
123
|
|
|
124
124
|
#### ✅ Correct
|
|
125
125
|
|
|
126
|
-
```ts
|
|
126
|
+
```ts option='{ "allowNullish": true }'
|
|
127
127
|
let fn = (a: number, b: undefined) => a + b;
|
|
128
128
|
let fn = (a: number, b: null) => a + b;
|
|
129
129
|
let fn = (a: string, b: undefined) => a + b;
|
|
@@ -138,14 +138,14 @@ Examples of code for this rule with `{ allowNumberAndString: true }`:
|
|
|
138
138
|
|
|
139
139
|
#### ❌ Incorrect
|
|
140
140
|
|
|
141
|
-
```ts
|
|
141
|
+
```ts option='{ "allowNumberAndString": true }'
|
|
142
142
|
let fn = (a: number, b: unknown) => a + b;
|
|
143
143
|
let fn = (a: number, b: never) => a + b;
|
|
144
144
|
```
|
|
145
145
|
|
|
146
146
|
#### ✅ Correct
|
|
147
147
|
|
|
148
|
-
```ts
|
|
148
|
+
```ts option='{ "allowNumberAndString": true }'
|
|
149
149
|
let fn = (a: number, b: string) => a + b;
|
|
150
150
|
let fn = (a: number, b: number | string) => a + b;
|
|
151
151
|
```
|
|
@@ -158,25 +158,25 @@ Examples of code for this rule with `{ allowRegExp: true }`:
|
|
|
158
158
|
|
|
159
159
|
#### ❌ Incorrect
|
|
160
160
|
|
|
161
|
-
```ts
|
|
161
|
+
```ts option='{ "allowRegExp": true }'
|
|
162
162
|
let fn = (a: number, b: RegExp) => a + b;
|
|
163
163
|
```
|
|
164
164
|
|
|
165
165
|
#### ✅ Correct
|
|
166
166
|
|
|
167
|
-
```ts
|
|
167
|
+
```ts option='{ "allowRegExp": true }'
|
|
168
168
|
let fn = (a: string, b: RegExp) => a + b;
|
|
169
169
|
```
|
|
170
170
|
|
|
171
171
|
### `skipCompoundAssignments`
|
|
172
172
|
|
|
173
|
-
Examples of code for this rule with `{ skipCompoundAssignments:
|
|
173
|
+
Examples of code for this rule with `{ skipCompoundAssignments: false }`:
|
|
174
174
|
|
|
175
175
|
<!--tabs-->
|
|
176
176
|
|
|
177
177
|
#### ❌ Incorrect
|
|
178
178
|
|
|
179
|
-
```ts
|
|
179
|
+
```ts option='{ "skipCompoundAssignments": true }'
|
|
180
180
|
let foo: string | undefined;
|
|
181
181
|
foo += 'some data';
|
|
182
182
|
|
|
@@ -186,7 +186,7 @@ bar += 0;
|
|
|
186
186
|
|
|
187
187
|
#### ✅ Correct
|
|
188
188
|
|
|
189
|
-
```ts
|
|
189
|
+
```ts option='{ "skipCompoundAssignments": true }'
|
|
190
190
|
let foo: number = 0;
|
|
191
191
|
foo += 1;
|
|
192
192
|
|
|
@@ -196,7 +196,7 @@ bar += 'test';
|
|
|
196
196
|
|
|
197
197
|
## When Not To Use It
|
|
198
198
|
|
|
199
|
-
If you don't mind `"[object Object]"` in your
|
|
199
|
+
If you don't mind a risk of `"[object Object]"` or incorrect type coercions in your values, then you will not need this rule.
|
|
200
200
|
|
|
201
201
|
## Related To
|
|
202
202
|
|