From 9b1332384628d1603acec3c44b74487a4934c168 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 30 Dec 2021 12:42:03 -0500 Subject: [PATCH 1/5] docs: standardized rule docs heading and option-less Options --- .../rules/adjacent-overload-signatures.md | 17 +++- .../eslint-plugin/docs/rules/array-type.md | 4 +- .../docs/rules/await-thenable.md | 17 +++- .../docs/rules/ban-ts-comment.md | 4 +- .../docs/rules/ban-tslint-comment.md | 4 +- .../eslint-plugin/docs/rules/ban-types.md | 4 +- .../eslint-plugin/docs/rules/brace-style.md | 4 +- .../rules/class-literal-property-style.md | 4 +- .../eslint-plugin/docs/rules/comma-dangle.md | 4 +- .../eslint-plugin/docs/rules/comma-spacing.md | 4 +- .../rules/consistent-indexed-object-style.md | 4 +- .../docs/rules/consistent-type-assertions.md | 4 +- .../docs/rules/consistent-type-definitions.md | 4 +- .../docs/rules/consistent-type-exports.md | 4 +- .../docs/rules/consistent-type-imports.md | 4 +- .../docs/rules/default-param-last.md | 4 +- .../eslint-plugin/docs/rules/dot-notation.md | 4 +- .../rules/explicit-function-return-type.md | 4 +- .../rules/explicit-member-accessibility.md | 4 +- .../rules/explicit-module-boundary-types.md | 4 +- .../docs/rules/func-call-spacing.md | 4 +- packages/eslint-plugin/docs/rules/indent.md | 4 +- .../docs/rules/init-declarations.md | 4 +- .../docs/rules/keyword-spacing.md | 4 +- .../docs/rules/lines-between-class-members.md | 4 +- .../docs/rules/member-delimiter-style.md | 4 +- .../docs/rules/member-ordering.md | 4 +- .../docs/rules/method-signature-style.md | 4 +- .../docs/rules/naming-convention.md | 4 +- .../docs/rules/no-array-constructor.md | 4 +- .../docs/rules/no-base-to-string.md | 4 +- .../rules/no-confusing-non-null-assertion.md | 4 +- .../rules/no-confusing-void-expression.md | 4 +- .../docs/rules/no-dupe-class-members.md | 4 +- .../docs/rules/no-duplicate-imports.md | 4 +- .../docs/rules/no-dynamic-delete.md | 4 +- .../docs/rules/no-empty-function.md | 4 +- .../docs/rules/no-empty-interface.md | 4 +- .../docs/rules/no-explicit-any.md | 4 +- .../docs/rules/no-extra-non-null-assertion.md | 15 ++- .../docs/rules/no-extra-parens.md | 4 +- .../eslint-plugin/docs/rules/no-extra-semi.md | 4 +- .../docs/rules/no-extraneous-class.md | 4 +- .../docs/rules/no-floating-promises.md | 4 +- .../docs/rules/no-for-in-array.md | 17 +++- .../docs/rules/no-implicit-any-catch.md | 4 +- .../docs/rules/no-implied-eval.md | 4 +- .../docs/rules/no-inferrable-types.md | 4 +- .../docs/rules/no-invalid-this.md | 4 +- .../docs/rules/no-invalid-void-type.md | 4 +- .../eslint-plugin/docs/rules/no-loop-func.md | 4 +- .../docs/rules/no-loss-of-precision.md | 4 +- .../docs/rules/no-magic-numbers.md | 4 +- .../rules/no-meaningless-void-operator.md | 4 +- .../docs/rules/no-misused-new.md | 13 ++- .../docs/rules/no-misused-promises.md | 4 +- .../eslint-plugin/docs/rules/no-namespace.md | 4 +- ...no-non-null-asserted-nullish-coalescing.md | 4 +- .../no-non-null-asserted-optional-chain.md | 17 +++- .../docs/rules/no-non-null-assertion.md | 17 +++- .../docs/rules/no-parameter-properties.md | 4 +- .../eslint-plugin/docs/rules/no-redeclare.md | 4 +- .../docs/rules/no-require-imports.md | 4 +- .../docs/rules/no-restricted-imports.md | 4 +- .../eslint-plugin/docs/rules/no-shadow.md | 4 +- .../eslint-plugin/docs/rules/no-this-alias.md | 4 +- .../docs/rules/no-throw-literal.md | 4 +- .../eslint-plugin/docs/rules/no-type-alias.md | 4 +- .../no-unnecessary-boolean-literal-compare.md | 4 +- .../docs/rules/no-unnecessary-condition.md | 4 +- .../docs/rules/no-unnecessary-qualifier.md | 4 +- .../rules/no-unnecessary-type-arguments.md | 4 +- .../rules/no-unnecessary-type-assertion.md | 4 +- .../rules/no-unnecessary-type-constraint.md | 17 +++- .../docs/rules/no-unsafe-argument.md | 17 +++- .../docs/rules/no-unsafe-assignment.md | 17 +++- .../docs/rules/no-unsafe-call.md | 17 +++- .../docs/rules/no-unsafe-member-access.md | 17 +++- .../docs/rules/no-unsafe-return.md | 17 +++- .../docs/rules/no-unused-expressions.md | 4 +- .../docs/rules/no-unused-vars.md | 4 +- .../docs/rules/no-use-before-define.md | 4 +- .../docs/rules/no-useless-constructor.md | 4 +- .../docs/rules/no-var-requires.md | 17 +++- .../non-nullable-type-assertion-style.md | 4 +- .../docs/rules/object-curly-spacing.md | 4 +- .../rules/padding-line-between-statements.md | 4 +- .../docs/rules/prefer-as-const.md | 17 +++- .../docs/rules/prefer-enum-initializers.md | 4 +- .../eslint-plugin/docs/rules/prefer-for-of.md | 4 +- .../docs/rules/prefer-function-type.md | 4 +- .../docs/rules/prefer-includes.md | 4 +- .../docs/rules/prefer-literal-enum-member.md | 4 +- .../docs/rules/prefer-namespace-keyword.md | 17 +++- .../docs/rules/prefer-nullish-coalescing.md | 4 +- .../docs/rules/prefer-optional-chain.md | 4 +- .../rules/prefer-readonly-parameter-types.md | 4 +- .../docs/rules/prefer-readonly.md | 4 +- .../rules/prefer-reduce-type-parameter.md | 4 +- .../docs/rules/prefer-regexp-exec.md | 4 +- .../docs/rules/prefer-return-this-type.md | 4 +- .../rules/prefer-string-starts-ends-with.md | 4 +- .../docs/rules/prefer-ts-expect-error.md | 4 +- .../docs/rules/promise-function-async.md | 4 +- packages/eslint-plugin/docs/rules/quotes.md | 4 +- .../docs/rules/require-array-sort-compare.md | 4 +- .../eslint-plugin/docs/rules/require-await.md | 4 +- .../docs/rules/restrict-plus-operands.md | 4 +- .../rules/restrict-template-expressions.md | 4 +- .../eslint-plugin/docs/rules/return-await.md | 4 +- packages/eslint-plugin/docs/rules/semi.md | 4 +- .../sort-type-union-intersection-members.md | 4 +- .../docs/rules/space-before-function-paren.md | 4 +- .../docs/rules/space-infix-ops.md | 4 +- .../docs/rules/strict-boolean-expressions.md | 4 +- .../docs/rules/switch-exhaustiveness-check.md | 4 +- .../docs/rules/triple-slash-reference.md | 4 +- .../docs/rules/type-annotation-spacing.md | 4 +- packages/eslint-plugin/docs/rules/typedef.md | 4 +- .../docs/rules/unbound-method.md | 4 +- .../docs/rules/unified-signatures.md | 2 +- packages/eslint-plugin/tests/docs.test.ts | 96 ++++++++++++++++--- 122 files changed, 643 insertions(+), 137 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md b/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md index 120bcc4326e4..58f9d77e393b 100644 --- a/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md +++ b/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md @@ -1,4 +1,6 @@ -# Require that member overloads be consecutive (`adjacent-overload-signatures`) +# `adjacent-overload-signatures` + +Require that member overloads be consecutive. Grouping overloaded members together can improve readability of the code. @@ -82,6 +84,19 @@ export function foo(n: number): void; export function foo(sn: string | number): void; ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/adjacent-overload-signatures": "error" + } +} +``` + +This rule is not configurable. + ## When Not To Use It If you don't care about the general structure of the code, then you will not need this rule. diff --git a/packages/eslint-plugin/docs/rules/array-type.md b/packages/eslint-plugin/docs/rules/array-type.md index e911ac190acc..9e5780fda390 100644 --- a/packages/eslint-plugin/docs/rules/array-type.md +++ b/packages/eslint-plugin/docs/rules/array-type.md @@ -1,4 +1,6 @@ -# Requires using either `T[]` or `Array` for arrays (`array-type`) +# `array-type` + +Requires using either `T[]` or `Array` for arrays. Using the same style for array definitions across your codebase makes it easier for your developers to read and understand the types. diff --git a/packages/eslint-plugin/docs/rules/await-thenable.md b/packages/eslint-plugin/docs/rules/await-thenable.md index 55c0f87d0ebf..0cb5c2a1b74e 100644 --- a/packages/eslint-plugin/docs/rules/await-thenable.md +++ b/packages/eslint-plugin/docs/rules/await-thenable.md @@ -1,4 +1,6 @@ -# Disallows awaiting a value that is not a Thenable (`await-thenable`) +# `await-thenable` + +Disallows awaiting a value that is not a Thenable. This rule disallows awaiting a value that is not a "Thenable" (an object which has `then` method, such as a Promise). While it is valid JavaScript to await a non-`Promise`-like value (it will resolve immediately), this pattern is often a programmer error, such as forgetting to add parenthesis to call a function that returns a Promise. @@ -27,6 +29,19 @@ const createValue = async () => 'value'; await createValue(); ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/await-thenable": "error" + } +} +``` + +This rule is not configurable. + ## When Not To Use It If you want to allow code to `await` non-Promise values. diff --git a/packages/eslint-plugin/docs/rules/ban-ts-comment.md b/packages/eslint-plugin/docs/rules/ban-ts-comment.md index 9b9e08c78949..ee5e86113f0b 100644 --- a/packages/eslint-plugin/docs/rules/ban-ts-comment.md +++ b/packages/eslint-plugin/docs/rules/ban-ts-comment.md @@ -1,4 +1,6 @@ -# Bans `@ts-` comments from being used or requires descriptions after directive (`ban-ts-comment`) +# `ban-ts-comment` + +Bans `@ts-` comments from being used or requires descriptions after directive. TypeScript provides several directive comments that can be used to alter how it processes files. Using these to suppress TypeScript Compiler Errors reduces the effectiveness of TypeScript overall. diff --git a/packages/eslint-plugin/docs/rules/ban-tslint-comment.md b/packages/eslint-plugin/docs/rules/ban-tslint-comment.md index 121fcaf5ea9a..95f9ab875436 100644 --- a/packages/eslint-plugin/docs/rules/ban-tslint-comment.md +++ b/packages/eslint-plugin/docs/rules/ban-tslint-comment.md @@ -1,4 +1,6 @@ -# Bans `// tslint:` comments from being used (`ban-tslint-comment`) +# `ban-tslint-comment` + +Bans `// tslint:` comments from being used. Useful when migrating from TSLint to ESLint. Once TSLint has been removed, this rule helps locate TSLint annotations (e.g. `// tslint:disable`). diff --git a/packages/eslint-plugin/docs/rules/ban-types.md b/packages/eslint-plugin/docs/rules/ban-types.md index cfa9635e1c01..0a16559e96f5 100644 --- a/packages/eslint-plugin/docs/rules/ban-types.md +++ b/packages/eslint-plugin/docs/rules/ban-types.md @@ -1,4 +1,6 @@ -# Bans specific types from being used (`ban-types`) +# `ban-types` + +Bans specific types from being used. Some builtin types have aliases, some types are considered dangerous or harmful. It's often a good idea to ban certain types to help with consistency and safety. diff --git a/packages/eslint-plugin/docs/rules/brace-style.md b/packages/eslint-plugin/docs/rules/brace-style.md index 1e006ad0ef2d..83316fa631fc 100644 --- a/packages/eslint-plugin/docs/rules/brace-style.md +++ b/packages/eslint-plugin/docs/rules/brace-style.md @@ -1,4 +1,6 @@ -# Enforce consistent brace style for blocks (`brace-style`) +# `brace-style` + +Enforce consistent brace style for blocks. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/class-literal-property-style.md b/packages/eslint-plugin/docs/rules/class-literal-property-style.md index 1f29e6dbbea3..649a640cc739 100644 --- a/packages/eslint-plugin/docs/rules/class-literal-property-style.md +++ b/packages/eslint-plugin/docs/rules/class-literal-property-style.md @@ -1,4 +1,6 @@ -# Ensures that literals on classes are exposed in a consistent style (`class-literal-property-style`) +# `class-literal-property-style` + +Ensures that literals on classes are exposed in a consistent style. When writing TypeScript applications, it's typically safe to store literal values on classes using fields with the `readonly` modifier to prevent them from being reassigned. When writing TypeScript libraries that could be used by JavaScript users however, it's typically safer to expose these literals using `getter`s, since the `readonly` modifier is enforced at compile type. diff --git a/packages/eslint-plugin/docs/rules/comma-dangle.md b/packages/eslint-plugin/docs/rules/comma-dangle.md index 29d01bc5a965..0605e485438b 100644 --- a/packages/eslint-plugin/docs/rules/comma-dangle.md +++ b/packages/eslint-plugin/docs/rules/comma-dangle.md @@ -1,4 +1,6 @@ -# Require or disallow trailing comma (`comma-dangle`) +# `comma-dangle` + +Require or disallow trailing comma. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/comma-spacing.md b/packages/eslint-plugin/docs/rules/comma-spacing.md index 4fa965a7ff51..2cc5a68694ba 100644 --- a/packages/eslint-plugin/docs/rules/comma-spacing.md +++ b/packages/eslint-plugin/docs/rules/comma-spacing.md @@ -1,4 +1,6 @@ -# Enforces consistent spacing before and after commas (`comma-spacing`) +# `comma-spacing` + +Enforces consistent spacing before and after commas. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md b/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md index cf66c5b7654c..ae44a0248895 100644 --- a/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md +++ b/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md @@ -1,4 +1,6 @@ -# Enforce or disallow the use of the record type (`consistent-indexed-object-style`) +# `consistent-indexed-object-style` + +Enforce or disallow the use of the record type. TypeScript supports defining object show keys can be flexible using an index signature. TypeScript also has a builtin type named `Record` to create an empty object defining only an index signature. For example, the following types are equal: diff --git a/packages/eslint-plugin/docs/rules/consistent-type-assertions.md b/packages/eslint-plugin/docs/rules/consistent-type-assertions.md index 5b8d84b67669..cb56c5d8a249 100644 --- a/packages/eslint-plugin/docs/rules/consistent-type-assertions.md +++ b/packages/eslint-plugin/docs/rules/consistent-type-assertions.md @@ -1,4 +1,6 @@ -# Enforces consistent usage of type assertions (`consistent-type-assertions`) +# `consistent-type-assertions` + +Enforces consistent usage of type assertions. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/consistent-type-definitions.md b/packages/eslint-plugin/docs/rules/consistent-type-definitions.md index 85c2033b7730..19f8d0df3d3e 100644 --- a/packages/eslint-plugin/docs/rules/consistent-type-definitions.md +++ b/packages/eslint-plugin/docs/rules/consistent-type-definitions.md @@ -1,4 +1,6 @@ -# Consistent with type definition either `interface` or `type` (`consistent-type-definitions`) +# `consistent-type-definitions` + +Consistent with type definition either `interface` or `type`. There are two ways to define a type. diff --git a/packages/eslint-plugin/docs/rules/consistent-type-exports.md b/packages/eslint-plugin/docs/rules/consistent-type-exports.md index 3c02e38d29c9..9145d83d29f6 100644 --- a/packages/eslint-plugin/docs/rules/consistent-type-exports.md +++ b/packages/eslint-plugin/docs/rules/consistent-type-exports.md @@ -1,4 +1,6 @@ -# Enforces consistent usage of type exports (`consistent-type-exports`) +# `consistent-type-exports` + +Enforces consistent usage of type exports. TypeScript 3.8 added support for type-only exports. diff --git a/packages/eslint-plugin/docs/rules/consistent-type-imports.md b/packages/eslint-plugin/docs/rules/consistent-type-imports.md index 515675e6e6fe..154fe0a62525 100644 --- a/packages/eslint-plugin/docs/rules/consistent-type-imports.md +++ b/packages/eslint-plugin/docs/rules/consistent-type-imports.md @@ -1,4 +1,6 @@ -# Enforces consistent usage of type imports (`consistent-type-imports`) +# `consistent-type-imports` + +Enforces consistent usage of type imports. TypeScript 3.8 added support for type-only imports. Type-only imports allow you to specify that an import can only be used in a type location, allowing certain optimizations within compilers. diff --git a/packages/eslint-plugin/docs/rules/default-param-last.md b/packages/eslint-plugin/docs/rules/default-param-last.md index 859bfd6ebb5b..ec8377ecb88a 100644 --- a/packages/eslint-plugin/docs/rules/default-param-last.md +++ b/packages/eslint-plugin/docs/rules/default-param-last.md @@ -1,4 +1,6 @@ -# Enforce default parameters to be last (`default-param-last`) +# `default-param-last` + +Enforce default parameters to be last. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/dot-notation.md b/packages/eslint-plugin/docs/rules/dot-notation.md index be4f23fd7763..85a8fff08df5 100644 --- a/packages/eslint-plugin/docs/rules/dot-notation.md +++ b/packages/eslint-plugin/docs/rules/dot-notation.md @@ -1,4 +1,6 @@ -# enforce dot notation whenever possible (`dot-notation`) +# `dot-notation` + +enforce dot notation whenever possible. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md index 4c199878bb1f..20aaeadb9861 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md @@ -1,4 +1,6 @@ -# Require explicit return types on functions and class methods (`explicit-function-return-type`) +# `explicit-function-return-type` + +Require explicit return types on functions and class methods. Explicit types for function return values makes it clear to any calling code what type is returned. This ensures that the return value is assigned to a variable of the correct type; or in the case diff --git a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md index 6f6d97ccefe2..e60af94265a2 100644 --- a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md +++ b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md @@ -1,4 +1,6 @@ -# Require explicit accessibility modifiers on class properties and methods (`explicit-member-accessibility`) +# `explicit-member-accessibility` + +Require explicit accessibility modifiers on class properties and methods. Leaving off accessibility modifier and making everything public can make your interface hard to use by others. diff --git a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md index f857b813ba90..038fb8b33ea9 100644 --- a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md +++ b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md @@ -1,4 +1,6 @@ -# Require explicit return and argument types on exported functions' and classes' public class methods (`explicit-module-boundary-types`) +# `explicit-module-boundary-types` + +Require explicit return and argument types on exported functions' and classes' public class methods. Explicit types for function return values and arguments makes it clear to any calling code what is the module boundary's input and output. diff --git a/packages/eslint-plugin/docs/rules/func-call-spacing.md b/packages/eslint-plugin/docs/rules/func-call-spacing.md index 4560bea5e4be..cb96cd5d7c03 100644 --- a/packages/eslint-plugin/docs/rules/func-call-spacing.md +++ b/packages/eslint-plugin/docs/rules/func-call-spacing.md @@ -1,4 +1,6 @@ -# Require or disallow spacing between function identifiers and their invocations (`func-call-spacing`) +# `func-call-spacing` + +Require or disallow spacing between function identifiers and their invocations. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/indent.md b/packages/eslint-plugin/docs/rules/indent.md index b787231aade5..2a8920398d3f 100644 --- a/packages/eslint-plugin/docs/rules/indent.md +++ b/packages/eslint-plugin/docs/rules/indent.md @@ -1,4 +1,6 @@ -# Enforce consistent indentation (`indent`) +# `indent` + +Enforce consistent indentation. ## Warning diff --git a/packages/eslint-plugin/docs/rules/init-declarations.md b/packages/eslint-plugin/docs/rules/init-declarations.md index 566e01c1d637..5df410a8dc5b 100644 --- a/packages/eslint-plugin/docs/rules/init-declarations.md +++ b/packages/eslint-plugin/docs/rules/init-declarations.md @@ -1,4 +1,6 @@ -# require or disallow initialization in variable declarations (`init-declarations`) +# `init-declarations` + +require or disallow initialization in variable declarations. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/keyword-spacing.md b/packages/eslint-plugin/docs/rules/keyword-spacing.md index 0e812a3b74ae..d2682f17abd7 100644 --- a/packages/eslint-plugin/docs/rules/keyword-spacing.md +++ b/packages/eslint-plugin/docs/rules/keyword-spacing.md @@ -1,4 +1,6 @@ -# Enforce consistent spacing before and after keywords (`keyword-spacing`) +# `keyword-spacing` + +Enforce consistent spacing before and after keywords. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/lines-between-class-members.md b/packages/eslint-plugin/docs/rules/lines-between-class-members.md index 0e8fe0d2fa1d..8d4a8ce767d3 100644 --- a/packages/eslint-plugin/docs/rules/lines-between-class-members.md +++ b/packages/eslint-plugin/docs/rules/lines-between-class-members.md @@ -1,4 +1,6 @@ -# Require or disallow an empty line between class members (`lines-between-class-members`) +# `lines-between-class-members` + +Require or disallow an empty line between class members. This rule improves readability by enforcing lines between class members. It will not check empty lines before the first member and after the last member. This rule require or disallow an empty line between class members. diff --git a/packages/eslint-plugin/docs/rules/member-delimiter-style.md b/packages/eslint-plugin/docs/rules/member-delimiter-style.md index 4a979cd9fbe5..1ad60abbdee0 100644 --- a/packages/eslint-plugin/docs/rules/member-delimiter-style.md +++ b/packages/eslint-plugin/docs/rules/member-delimiter-style.md @@ -1,4 +1,6 @@ -# Require a specific member delimiter style for interfaces and type literals (`member-delimiter-style`) +# `member-delimiter-style` + +Require a specific member delimiter style for interfaces and type literals. Enforces a consistent member delimiter style in interfaces and type literals. There are three member delimiter styles primarily used in TypeScript: diff --git a/packages/eslint-plugin/docs/rules/member-ordering.md b/packages/eslint-plugin/docs/rules/member-ordering.md index 40112c777c03..2606fd35f9c7 100644 --- a/packages/eslint-plugin/docs/rules/member-ordering.md +++ b/packages/eslint-plugin/docs/rules/member-ordering.md @@ -1,4 +1,6 @@ -# Require a consistent member declaration order (`member-ordering`) +# `member-ordering` + +Require a consistent member declaration order. A consistent ordering of fields, methods and constructors can make interfaces, type literals, classes and class expressions easier to read, navigate and edit. diff --git a/packages/eslint-plugin/docs/rules/method-signature-style.md b/packages/eslint-plugin/docs/rules/method-signature-style.md index 412150683553..9c55c4709024 100644 --- a/packages/eslint-plugin/docs/rules/method-signature-style.md +++ b/packages/eslint-plugin/docs/rules/method-signature-style.md @@ -1,4 +1,6 @@ -# Enforces using a particular method signature syntax. (`method-signature-style`) +# `method-signature-style` + +Enforces using a particular method signature syntax.. There are two ways to define an object/interface function property. diff --git a/packages/eslint-plugin/docs/rules/naming-convention.md b/packages/eslint-plugin/docs/rules/naming-convention.md index ef917b1a239c..9268e8a9d028 100644 --- a/packages/eslint-plugin/docs/rules/naming-convention.md +++ b/packages/eslint-plugin/docs/rules/naming-convention.md @@ -1,4 +1,6 @@ -# Enforces naming conventions for everything across a codebase (`naming-convention`) +# `naming-convention` + +Enforces naming conventions for everything across a codebase. Enforcing naming conventions helps keep the codebase consistent, and reduces overhead when thinking about how to name a variable. Additionally, a well-designed style guide can help communicate intent, such as by enforcing all private properties begin with an `_`, and all global-level constants are written in `UPPER_CASE`. diff --git a/packages/eslint-plugin/docs/rules/no-array-constructor.md b/packages/eslint-plugin/docs/rules/no-array-constructor.md index 5eae0cf8645a..e3fbaadbf189 100644 --- a/packages/eslint-plugin/docs/rules/no-array-constructor.md +++ b/packages/eslint-plugin/docs/rules/no-array-constructor.md @@ -1,4 +1,6 @@ -# Disallow generic `Array` constructors (`no-array-constructor`) +# `no-array-constructor` + +Disallow generic `Array` constructors. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-base-to-string.md b/packages/eslint-plugin/docs/rules/no-base-to-string.md index 5dd59bb2bb58..5db6218bb52b 100644 --- a/packages/eslint-plugin/docs/rules/no-base-to-string.md +++ b/packages/eslint-plugin/docs/rules/no-base-to-string.md @@ -1,4 +1,6 @@ -# Requires that `.toString()` is only called on objects which provide useful information when stringified (`no-base-to-string`) +# `no-base-to-string` + +Requires that `.toString()` is only called on objects which provide useful information when stringified. JavaScript will call `toString()` on an object when it is converted to a string, such as when `+` adding to a string or in `${}` template literals. diff --git a/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md b/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md index 78655b69db82..ed894aa8eb32 100644 --- a/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md @@ -1,4 +1,6 @@ -# Disallow non-null assertion in locations that may be confusing (`no-confusing-non-null-assertion`) +# `no-confusing-non-null-assertion` + +Disallow non-null assertion in locations that may be confusing. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-confusing-void-expression.md b/packages/eslint-plugin/docs/rules/no-confusing-void-expression.md index 0ca36a150cd1..c2af300e0b63 100644 --- a/packages/eslint-plugin/docs/rules/no-confusing-void-expression.md +++ b/packages/eslint-plugin/docs/rules/no-confusing-void-expression.md @@ -1,4 +1,6 @@ -# Requires expressions of type void to appear in statement position (`no-confusing-void-expression`) +# `no-confusing-void-expression` + +Requires expressions of type void to appear in statement position. Returning the results of an expression whose type is void can be misleading. Attempting to do so is likely a symptom of expecting a different return type from a function. diff --git a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md index ed7a38923d3f..7d59aec06831 100644 --- a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md +++ b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md @@ -1,4 +1,6 @@ -# Disallow duplicate class members (`no-dupe-class-members`) +# `no-dupe-class-members` + +Disallow duplicate class members. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-duplicate-imports.md b/packages/eslint-plugin/docs/rules/no-duplicate-imports.md index 193d69e873db..f6d1fc5eb42a 100644 --- a/packages/eslint-plugin/docs/rules/no-duplicate-imports.md +++ b/packages/eslint-plugin/docs/rules/no-duplicate-imports.md @@ -1,4 +1,6 @@ -# Disallow duplicate imports (`no-duplicate-imports`) +# `no-duplicate-imports` + +Disallow duplicate imports. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-dynamic-delete.md b/packages/eslint-plugin/docs/rules/no-dynamic-delete.md index 63e41781d5e3..c5349d519835 100644 --- a/packages/eslint-plugin/docs/rules/no-dynamic-delete.md +++ b/packages/eslint-plugin/docs/rules/no-dynamic-delete.md @@ -1,4 +1,6 @@ -# Disallow the delete operator with computed key expressions (`no-dynamic-delete`) +# `no-dynamic-delete` + +Disallow the delete operator with computed key expressions. Deleting dynamically computed keys can be dangerous and in some cases not well optimized. diff --git a/packages/eslint-plugin/docs/rules/no-empty-function.md b/packages/eslint-plugin/docs/rules/no-empty-function.md index e380be0a29b1..db450a46121b 100644 --- a/packages/eslint-plugin/docs/rules/no-empty-function.md +++ b/packages/eslint-plugin/docs/rules/no-empty-function.md @@ -1,4 +1,6 @@ -# Disallow empty functions (`no-empty-function`) +# `no-empty-function` + +Disallow empty functions. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-empty-interface.md b/packages/eslint-plugin/docs/rules/no-empty-interface.md index ddeab6579189..b2db028106fd 100644 --- a/packages/eslint-plugin/docs/rules/no-empty-interface.md +++ b/packages/eslint-plugin/docs/rules/no-empty-interface.md @@ -1,4 +1,6 @@ -# Disallow the declaration of empty interfaces (`no-empty-interface`) +# `no-empty-interface` + +Disallow the declaration of empty interfaces. An empty interface is equivalent to its supertype. If the interface does not implement a supertype, then the interface is equivalent to an empty object (`{}`). In both cases it can be omitted. diff --git a/packages/eslint-plugin/docs/rules/no-explicit-any.md b/packages/eslint-plugin/docs/rules/no-explicit-any.md index 7e3435b3b58d..222c08c5123e 100644 --- a/packages/eslint-plugin/docs/rules/no-explicit-any.md +++ b/packages/eslint-plugin/docs/rules/no-explicit-any.md @@ -1,4 +1,6 @@ -# Disallow usage of the `any` type (`no-explicit-any`) +# `no-explicit-any` + +Disallow usage of the `any` type. Using the `any` type defeats the purpose of using TypeScript. When `any` is used, all compiler type checks around that value are ignored. diff --git a/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md b/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md index d55167ff2b58..6e19e8b0dd7e 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md @@ -1,4 +1,6 @@ -# Disallow extra non-null assertion (`no-extra-non-null-assertion`) +# `no-extra-non-null-assertion` + +Disallow extra non-null assertion. ## Rule Details @@ -44,14 +46,19 @@ function foo(bar?: { n: number }) { } ``` -## How to Use +## Options -```json +```jsonc +// .eslintrc.json { - "@typescript-eslint/no-extra-non-null-assertion": ["error"] + "rules": { + "@typescript-eslint/no-extra-non-null-assertion": "error" + } } ``` +This rule is not configurable. + ## Attributes - [x] ✅ Recommended diff --git a/packages/eslint-plugin/docs/rules/no-extra-parens.md b/packages/eslint-plugin/docs/rules/no-extra-parens.md index 1ae12a47be38..287918a2b445 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-parens.md +++ b/packages/eslint-plugin/docs/rules/no-extra-parens.md @@ -1,4 +1,6 @@ -# Disallow unnecessary parentheses (`no-extra-parens`) +# `no-extra-parens` + +Disallow unnecessary parentheses. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-extra-semi.md b/packages/eslint-plugin/docs/rules/no-extra-semi.md index 504ff588de45..2ca8c2f14bcc 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-semi.md +++ b/packages/eslint-plugin/docs/rules/no-extra-semi.md @@ -1,4 +1,6 @@ -# Disallow unnecessary semicolons (`no-extra-semi`) +# `no-extra-semi` + +Disallow unnecessary semicolons. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-extraneous-class.md b/packages/eslint-plugin/docs/rules/no-extraneous-class.md index 72303e3c25b1..470da5c607d8 100644 --- a/packages/eslint-plugin/docs/rules/no-extraneous-class.md +++ b/packages/eslint-plugin/docs/rules/no-extraneous-class.md @@ -1,4 +1,6 @@ -# Forbids the use of classes as namespaces (`no-extraneous-class`) +# `no-extraneous-class` + +Forbids the use of classes as namespaces. This rule warns when a class is accidentally used as a namespace. diff --git a/packages/eslint-plugin/docs/rules/no-floating-promises.md b/packages/eslint-plugin/docs/rules/no-floating-promises.md index 1322f468d47f..020a5b5b72a0 100644 --- a/packages/eslint-plugin/docs/rules/no-floating-promises.md +++ b/packages/eslint-plugin/docs/rules/no-floating-promises.md @@ -1,4 +1,6 @@ -# Requires Promise-like values to be handled appropriately (`no-floating-promises`) +# `no-floating-promises` + +Requires Promise-like values to be handled appropriately. This rule forbids usage of Promise-like values in statements without handling their errors appropriately. Unhandled promises can cause several issues, such diff --git a/packages/eslint-plugin/docs/rules/no-for-in-array.md b/packages/eslint-plugin/docs/rules/no-for-in-array.md index 9fbed4ca02fb..d21ab4e60816 100644 --- a/packages/eslint-plugin/docs/rules/no-for-in-array.md +++ b/packages/eslint-plugin/docs/rules/no-for-in-array.md @@ -1,4 +1,6 @@ -# Disallow iterating over an array with a for-in loop (`no-for-in-array`) +# `no-for-in-array` + +Disallow iterating over an array with a for-in loop. This rule prohibits iterating over an array with a for-in loop. @@ -39,6 +41,19 @@ for (const x in { a: 3, b: 4, c: 5 }) { } ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/no-for-in-array": "error" + } +} +``` + +This rule is not configurable. + ## When Not To Use It If you want to iterate through a loop using the indices in an array as strings, you can turn off this rule. diff --git a/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md b/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md index a03adc818197..d17e53209c87 100644 --- a/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md +++ b/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md @@ -1,4 +1,6 @@ -# Disallow usage of the implicit `any` type in catch clauses (`no-implicit-any-catch`) +# `no-implicit-any-catch` + +Disallow usage of the implicit `any` type in catch clauses. TypeScript 4.0 added support for adding an explicit `any` or `unknown` type annotation on a catch clause variable. diff --git a/packages/eslint-plugin/docs/rules/no-implied-eval.md b/packages/eslint-plugin/docs/rules/no-implied-eval.md index 1a1fe3d87a75..fe0bc5a79dfd 100644 --- a/packages/eslint-plugin/docs/rules/no-implied-eval.md +++ b/packages/eslint-plugin/docs/rules/no-implied-eval.md @@ -1,4 +1,6 @@ -# Disallow the use of `eval()`-like methods (`no-implied-eval`) +# `no-implied-eval` + +Disallow the use of `eval()`-like methods. It's considered a good practice to avoid using `eval()`. There are security and performance implications involved with doing so, which is why many linters recommend disallowing `eval()`. However, there are some other ways to pass a string and have it interpreted as JavaScript code that have similar concerns. diff --git a/packages/eslint-plugin/docs/rules/no-inferrable-types.md b/packages/eslint-plugin/docs/rules/no-inferrable-types.md index de82c8719f7c..473676bac0e3 100644 --- a/packages/eslint-plugin/docs/rules/no-inferrable-types.md +++ b/packages/eslint-plugin/docs/rules/no-inferrable-types.md @@ -1,4 +1,6 @@ -# Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean (`no-inferrable-types`) +# `no-inferrable-types` + +Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean. Explicit types where they can be easily inferred may add unnecessary verbosity. diff --git a/packages/eslint-plugin/docs/rules/no-invalid-this.md b/packages/eslint-plugin/docs/rules/no-invalid-this.md index becbc9d6186a..a8a3256b8e36 100644 --- a/packages/eslint-plugin/docs/rules/no-invalid-this.md +++ b/packages/eslint-plugin/docs/rules/no-invalid-this.md @@ -1,4 +1,6 @@ -# Disallow `this` keywords outside of classes or class-like objects (`no-invalid-this`) +# `no-invalid-this` + +Disallow `this` keywords outside of classes or class-like objects. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-invalid-void-type.md b/packages/eslint-plugin/docs/rules/no-invalid-void-type.md index e36fe8f97e1f..3771f572b109 100644 --- a/packages/eslint-plugin/docs/rules/no-invalid-void-type.md +++ b/packages/eslint-plugin/docs/rules/no-invalid-void-type.md @@ -1,4 +1,6 @@ -# Disallows usage of `void` type outside of generic or return types (`no-invalid-void-type`) +# `no-invalid-void-type` + +Disallows usage of `void` type outside of generic or return types. Disallows usage of `void` type outside of return types or generic type arguments. If `void` is used as return type, it shouldn’t be a part of intersection/union type with most other types. diff --git a/packages/eslint-plugin/docs/rules/no-loop-func.md b/packages/eslint-plugin/docs/rules/no-loop-func.md index a0cde8aee765..e69a0d7b0a14 100644 --- a/packages/eslint-plugin/docs/rules/no-loop-func.md +++ b/packages/eslint-plugin/docs/rules/no-loop-func.md @@ -1,4 +1,6 @@ -# Disallow function declarations that contain unsafe references inside loop statements (`no-loop-func`) +# `no-loop-func` + +Disallow function declarations that contain unsafe references inside loop statements. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-loss-of-precision.md b/packages/eslint-plugin/docs/rules/no-loss-of-precision.md index 24b3753f8b32..7165f945b077 100644 --- a/packages/eslint-plugin/docs/rules/no-loss-of-precision.md +++ b/packages/eslint-plugin/docs/rules/no-loss-of-precision.md @@ -1,4 +1,6 @@ -# Disallow literal numbers that lose precision (`no-loss-of-precision`) +# `no-loss-of-precision` + +Disallow literal numbers that lose precision. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-magic-numbers.md b/packages/eslint-plugin/docs/rules/no-magic-numbers.md index 61ea6627f18b..b67aeae67886 100644 --- a/packages/eslint-plugin/docs/rules/no-magic-numbers.md +++ b/packages/eslint-plugin/docs/rules/no-magic-numbers.md @@ -1,4 +1,6 @@ -# Disallow magic numbers (`no-magic-numbers`) +# `no-magic-numbers` + +Disallow magic numbers. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-meaningless-void-operator.md b/packages/eslint-plugin/docs/rules/no-meaningless-void-operator.md index f1ddff9e219d..79e43d04ce5a 100644 --- a/packages/eslint-plugin/docs/rules/no-meaningless-void-operator.md +++ b/packages/eslint-plugin/docs/rules/no-meaningless-void-operator.md @@ -1,4 +1,6 @@ -# Disallow the `void` operator except when used to discard a value (`no-meaningless-void-operator`) +# `no-meaningless-void-operator` + +Disallow the `void` operator except when used to discard a value. Disallow the `void` operator when its argument is already of type `void` or `undefined`. diff --git a/packages/eslint-plugin/docs/rules/no-misused-new.md b/packages/eslint-plugin/docs/rules/no-misused-new.md index 72cc5eabf711..e56ff23012af 100644 --- a/packages/eslint-plugin/docs/rules/no-misused-new.md +++ b/packages/eslint-plugin/docs/rules/no-misused-new.md @@ -1,4 +1,6 @@ -# Enforce valid definition of `new` and `constructor` (`no-misused-new`) +# `no-misused-new` + +Enforce valid definition of `new` and `constructor`. Warns on apparent attempts to define constructors for interfaces or `new` for classes. @@ -34,12 +36,17 @@ interface I { ## Options -```json +```jsonc +// .eslintrc.json { - "@typescript-eslint/no-misused-new": "error" + "rules": { + "@typescript-eslint/no-misused-new": "error" + } } ``` +This rule is not configurable. + ## Related To - TSLint: [no-misused-new](https://palantir.github.io/tslint/rules/no-misused-new/) diff --git a/packages/eslint-plugin/docs/rules/no-misused-promises.md b/packages/eslint-plugin/docs/rules/no-misused-promises.md index 7be1938e7435..a50cf28108c4 100644 --- a/packages/eslint-plugin/docs/rules/no-misused-promises.md +++ b/packages/eslint-plugin/docs/rules/no-misused-promises.md @@ -1,4 +1,6 @@ -# Avoid using promises in places not designed to handle them (`no-misused-promises`) +# `no-misused-promises` + +Avoid using promises in places not designed to handle them. This rule forbids using promises in places where the TypeScript compiler allows them but they are not handled properly. These situations can often arise diff --git a/packages/eslint-plugin/docs/rules/no-namespace.md b/packages/eslint-plugin/docs/rules/no-namespace.md index 88328741bb5f..bee784373ac1 100644 --- a/packages/eslint-plugin/docs/rules/no-namespace.md +++ b/packages/eslint-plugin/docs/rules/no-namespace.md @@ -1,4 +1,6 @@ -# Disallow the use of custom TypeScript modules and namespaces (`no-namespace`) +# `no-namespace` + +Disallow the use of custom TypeScript modules and namespaces. Custom TypeScript modules (`module foo {}`) and namespaces (`namespace foo {}`) are considered outdated ways to organize TypeScript code. ES2015 module syntax is now preferred (`import`/`export`). diff --git a/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md b/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md index 498ac053d6f9..fd4b524b8cb1 100644 --- a/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md +++ b/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md @@ -1,4 +1,6 @@ -# Disallows using a non-null assertion in the left operand of the nullish coalescing operator (`no-non-null-asserted-nullish-coalescing`) +# `no-non-null-asserted-nullish-coalescing` + +Disallows using a non-null assertion in the left operand of the nullish coalescing operator. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md b/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md index 0a59902883d3..196f709bab83 100644 --- a/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md +++ b/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md @@ -1,4 +1,6 @@ -# Disallows using a non-null assertion after an optional chain expression (`no-non-null-asserted-optional-chain`) +# `no-non-null-asserted-optional-chain` + +Disallows using a non-null assertion after an optional chain expression. ## Rule Details @@ -42,6 +44,19 @@ foo?.bar!(); foo?.bar!().baz; ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/no-non-null-asserted-optional-chain": "error" + } +} +``` + +This rule is not configurable. + ## When Not To Use It If you are not using TypeScript 3.7 (or greater), then you will not need to use this rule, as the operator is not supported. diff --git a/packages/eslint-plugin/docs/rules/no-non-null-assertion.md b/packages/eslint-plugin/docs/rules/no-non-null-assertion.md index cbd76d1bb1f4..cc3f5a138148 100644 --- a/packages/eslint-plugin/docs/rules/no-non-null-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-non-null-assertion.md @@ -1,4 +1,6 @@ -# Disallows non-null assertions using the `!` postfix operator (`no-non-null-assertion`) +# `no-non-null-assertion` + +Disallows non-null assertions using the `!` postfix operator. ## Rule Details @@ -30,6 +32,19 @@ const foo: Foo = getFoo(); const includesBaz: boolean = foo.bar?.includes('baz') ?? false; ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/no-non-null-assertion": "warn" + } +} +``` + +This rule is not configurable. + ## When Not To Use It If you don't care about strict null-checking, then you will not need this rule. diff --git a/packages/eslint-plugin/docs/rules/no-parameter-properties.md b/packages/eslint-plugin/docs/rules/no-parameter-properties.md index eb4944364b66..e915acb1403a 100644 --- a/packages/eslint-plugin/docs/rules/no-parameter-properties.md +++ b/packages/eslint-plugin/docs/rules/no-parameter-properties.md @@ -1,4 +1,6 @@ -# Disallow the use of parameter properties in class constructors (`no-parameter-properties`) +# `no-parameter-properties` + +Disallow the use of parameter properties in class constructors. Parameter properties can be confusing to those new to TypeScript as they are less explicit than other ways of declaring and initializing class members. diff --git a/packages/eslint-plugin/docs/rules/no-redeclare.md b/packages/eslint-plugin/docs/rules/no-redeclare.md index 2e6efa958236..c8c55025577f 100644 --- a/packages/eslint-plugin/docs/rules/no-redeclare.md +++ b/packages/eslint-plugin/docs/rules/no-redeclare.md @@ -1,4 +1,6 @@ -# Disallow variable redeclaration (`no-redeclare`) +# `no-redeclare` + +Disallow variable redeclaration. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-require-imports.md b/packages/eslint-plugin/docs/rules/no-require-imports.md index 9a4680796d02..0be131f64843 100644 --- a/packages/eslint-plugin/docs/rules/no-require-imports.md +++ b/packages/eslint-plugin/docs/rules/no-require-imports.md @@ -1,4 +1,6 @@ -# Disallows invocation of `require()` (`no-require-imports`) +# `no-require-imports` + +Disallows invocation of `require()`. Prefer the newer ES6-style imports over `require()`. diff --git a/packages/eslint-plugin/docs/rules/no-restricted-imports.md b/packages/eslint-plugin/docs/rules/no-restricted-imports.md index 52a8daa2fd6e..b7b04c8e3fcb 100644 --- a/packages/eslint-plugin/docs/rules/no-restricted-imports.md +++ b/packages/eslint-plugin/docs/rules/no-restricted-imports.md @@ -1,4 +1,6 @@ -# Disallow specified modules when loaded by `import` (`no-restricted-imports`) +# `no-restricted-imports` + +Disallow specified modules when loaded by `import`. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-shadow.md b/packages/eslint-plugin/docs/rules/no-shadow.md index e3da57987b44..11b9f62c0bd0 100644 --- a/packages/eslint-plugin/docs/rules/no-shadow.md +++ b/packages/eslint-plugin/docs/rules/no-shadow.md @@ -1,4 +1,6 @@ -# Disallow variable declarations from shadowing variables declared in the outer scope (`no-shadow`) +# `no-shadow` + +Disallow variable declarations from shadowing variables declared in the outer scope. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-this-alias.md b/packages/eslint-plugin/docs/rules/no-this-alias.md index 8265fe7efdd3..9ce436eb6e50 100644 --- a/packages/eslint-plugin/docs/rules/no-this-alias.md +++ b/packages/eslint-plugin/docs/rules/no-this-alias.md @@ -1,4 +1,6 @@ -# Disallow aliasing `this` (`no-this-alias`) +# `no-this-alias` + +Disallow aliasing `this`. This rule prohibits assigning variables to `this`. diff --git a/packages/eslint-plugin/docs/rules/no-throw-literal.md b/packages/eslint-plugin/docs/rules/no-throw-literal.md index ea99d592fe7a..2216a05f74c3 100644 --- a/packages/eslint-plugin/docs/rules/no-throw-literal.md +++ b/packages/eslint-plugin/docs/rules/no-throw-literal.md @@ -1,4 +1,6 @@ -# Disallow throwing literals as exceptions (`no-throw-literal`) +# `no-throw-literal` + +Disallow throwing literals as exceptions. It is considered good practice to only `throw` the `Error` object itself or an object using the `Error` object as base objects for user-defined exceptions. The fundamental benefit of `Error` objects is that they automatically keep track of where they were built and originated. diff --git a/packages/eslint-plugin/docs/rules/no-type-alias.md b/packages/eslint-plugin/docs/rules/no-type-alias.md index e2cca34b0a78..20302bdd7400 100644 --- a/packages/eslint-plugin/docs/rules/no-type-alias.md +++ b/packages/eslint-plugin/docs/rules/no-type-alias.md @@ -1,4 +1,6 @@ -# Disallow the use of type aliases (`no-type-alias`) +# `no-type-alias` + +Disallow the use of type aliases. In TypeScript, type aliases serve three purposes: diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md b/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md index 4f81aec9a846..5ba48cc64881 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md @@ -1,4 +1,6 @@ -# Flags unnecessary equality comparisons against boolean literals (`no-unnecessary-boolean-literal-compare`) +# `no-unnecessary-boolean-literal-compare` + +Flags unnecessary equality comparisons against boolean literals. Comparing boolean values to boolean literals is unnecessary, those comparisons result in the same booleans. Using the boolean values directly, or via a unary negation (`!value`), is more concise and clearer. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md b/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md index a6d029ab09fe..53532b2371b7 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md @@ -1,4 +1,6 @@ -# Prevents conditionals where the type is always truthy or always falsy (`no-unnecessary-condition`) +# `no-unnecessary-condition` + +Prevents conditionals where the type is always truthy or always falsy. Any expression being used as a condition must be able to evaluate as truthy or falsy in order to be considered "necessary". Conversely, any expression that always evaluates to truthy or always evaluates to falsy, as determined by the type of the expression, is considered unnecessary and will be flagged by this rule. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md b/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md index 3df839c1756f..55feda0a1881 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md @@ -1,4 +1,6 @@ -# Warns when a namespace qualifier is unnecessary (`no-unnecessary-qualifier`) +# `no-unnecessary-qualifier` + +Warns when a namespace qualifier is unnecessary. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md b/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md index 82668377296f..b7829c9405cb 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md @@ -1,4 +1,6 @@ -# Enforces that type arguments will not be used if not required (`no-unnecessary-type-arguments`) +# `no-unnecessary-type-arguments` + +Enforces that type arguments will not be used if not required. Warns if an explicitly specified type argument is the default for that type parameter. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md b/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md index f97d0fab1b9b..8cf43cbe50e7 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md @@ -1,4 +1,6 @@ -# Warns if a type assertion does not change the type of an expression (`no-unnecessary-type-assertion`) +# `no-unnecessary-type-assertion` + +Warns if a type assertion does not change the type of an expression. This rule prohibits using a type assertion that does not change the type of an expression. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md b/packages/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md index b69dab2c157d..5bbb2c6cb65a 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md @@ -1,4 +1,6 @@ -# Disallows unnecessary constraints on generic types (`no-unnecessary-type-constraint`) +# `no-unnecessary-type-constraint` + +Disallows unnecessary constraints on generic types. ## Rule Details @@ -54,6 +56,19 @@ const Quux = () => {}; function Quuz() {} ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/no-unnecessary-type-constraint": "error" + } +} +``` + +This rule is not configurable. + ## When Not To Use It If you don't care about the specific styles of your type constraints, or never use them in the first place, then you will not need this rule. diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-argument.md b/packages/eslint-plugin/docs/rules/no-unsafe-argument.md index 9b56a982efa2..cd0a1e830968 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-argument.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-argument.md @@ -1,4 +1,6 @@ -# Disallows calling a function with an any type value (`no-unsafe-argument`) +# `no-unsafe-argument` + +Disallows calling a function with an any type value. Despite your best intentions, the `any` type can sometimes leak into your codebase. Call a function with `any` typed argument are not checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase. @@ -69,6 +71,19 @@ declare function foo(arg1: unknown, arg2: Set, arg3: unknown[]): void; foo(1 as any, new Set(), [] as any[]); ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/no-unsafe-argument": "error" + } +} +``` + +This rule is not configurable. + ## Related To - [`no-explicit-any`](./no-explicit-any.md) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md b/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md index 41ecc2ce1649..cf2ed503207c 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md @@ -1,4 +1,6 @@ -# Disallows assigning any to variables and properties (`no-unsafe-assignment`) +# `no-unsafe-assignment` + +Disallows assigning any to variables and properties. Despite your best intentions, the `any` type can sometimes leak into your codebase. Assigning an `any` typed value to a variable can be hard to pick up on, particularly if it leaks in from an external library. Operations on the variable will not be checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase. @@ -72,6 +74,19 @@ const x: unknown[] = y as any[]; const x: Set = y as Set; ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/no-unsafe-assignment": "error" + } +} +``` + +This rule is not configurable. + ## Related To - [`no-explicit-any`](./no-explicit-any.md) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-call.md b/packages/eslint-plugin/docs/rules/no-unsafe-call.md index 6a2e3933c51d..e6eb6fe3aaa3 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-call.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-call.md @@ -1,4 +1,6 @@ -# Disallows calling an any type value (`no-unsafe-call`) +# `no-unsafe-call` + +Disallows calling an any type value. Despite your best intentions, the `any` type can sometimes leak into your codebase. The arguments to, and return value of calling an `any` typed variable are not checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase. @@ -46,6 +48,19 @@ new Map(); String.raw`foo`; ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/no-unsafe-call": "error" + } +} +``` + +This rule is not configurable. + ## Related To - [`no-explicit-any`](./no-explicit-any.md) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md b/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md index df9ca7fc26ab..92eacedf6c79 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md @@ -1,4 +1,6 @@ -# Disallows member access on any typed variables (`no-unsafe-member-access`) +# `no-unsafe-member-access` + +Disallows member access on any typed variables. Despite your best intentions, the `any` type can sometimes leak into your codebase. Member access on `any` typed variables is not checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase. @@ -52,6 +54,19 @@ arr[idx]; arr[idx++]; ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/no-unsafe-member-access": "error" + } +} +``` + +This rule is not configurable. + ## Related To - [`no-explicit-any`](./no-explicit-any.md) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-return.md b/packages/eslint-plugin/docs/rules/no-unsafe-return.md index 4cecc7c39c15..792eb91c4189 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-return.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-return.md @@ -1,4 +1,6 @@ -# Disallows returning any from a function (`no-unsafe-return`) +# `no-unsafe-return` + +Disallows returning any from a function. Despite your best intentions, the `any` type can sometimes leak into your codebase. Returned `any` typed values are not checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase. @@ -89,6 +91,19 @@ function foo2(): unknown[] { } ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/no-unsafe-return": "error" + } +} +``` + +This rule is not configurable. + ## Related To - [`no-explicit-any`](./no-explicit-any.md) diff --git a/packages/eslint-plugin/docs/rules/no-unused-expressions.md b/packages/eslint-plugin/docs/rules/no-unused-expressions.md index 8c7beea07b42..4a0abf2fc432 100644 --- a/packages/eslint-plugin/docs/rules/no-unused-expressions.md +++ b/packages/eslint-plugin/docs/rules/no-unused-expressions.md @@ -1,4 +1,6 @@ -# Disallow unused expressions (`no-unused-expressions`) +# `no-unused-expressions` + +Disallow unused expressions. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-unused-vars.md b/packages/eslint-plugin/docs/rules/no-unused-vars.md index 6387b5940446..0de95a4ac1e4 100644 --- a/packages/eslint-plugin/docs/rules/no-unused-vars.md +++ b/packages/eslint-plugin/docs/rules/no-unused-vars.md @@ -1,4 +1,6 @@ -# Disallow unused variables (`no-unused-vars`) +# `no-unused-vars` + +Disallow unused variables. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-use-before-define.md b/packages/eslint-plugin/docs/rules/no-use-before-define.md index 038b8fbb9b42..d96b3099ee8b 100644 --- a/packages/eslint-plugin/docs/rules/no-use-before-define.md +++ b/packages/eslint-plugin/docs/rules/no-use-before-define.md @@ -1,4 +1,6 @@ -# Disallow the use of variables before they are defined (`no-use-before-define`) +# `no-use-before-define` + +Disallow the use of variables before they are defined. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-useless-constructor.md b/packages/eslint-plugin/docs/rules/no-useless-constructor.md index a5ef7f0b664a..ef0210d17de2 100644 --- a/packages/eslint-plugin/docs/rules/no-useless-constructor.md +++ b/packages/eslint-plugin/docs/rules/no-useless-constructor.md @@ -1,4 +1,6 @@ -# Disallow unnecessary constructors (`no-useless-constructor`) +# `no-useless-constructor` + +Disallow unnecessary constructors. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-var-requires.md b/packages/eslint-plugin/docs/rules/no-var-requires.md index 7c5a46fa4bc3..1d1a4a84eeaf 100644 --- a/packages/eslint-plugin/docs/rules/no-var-requires.md +++ b/packages/eslint-plugin/docs/rules/no-var-requires.md @@ -1,4 +1,6 @@ -# Disallows the use of require statements except in import statements (`no-var-requires`) +# `no-var-requires` + +Disallows the use of require statements except in import statements. In other words, the use of forms such as `var foo = require("foo")` are banned. Instead use ES6 style imports or `import foo = require("foo")` imports. @@ -24,6 +26,19 @@ require('foo'); import foo from 'foo'; ``` +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/no-var-requires": "error" + } +} +``` + +This rule is not configurable. + ## When Not To Use It If you don't care about TypeScript module syntax, then you will not need this rule. diff --git a/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md b/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md index f4fe4320f9d3..07d8839091f1 100644 --- a/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md +++ b/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md @@ -1,4 +1,6 @@ -# Prefers a non-null assertion over explicit type cast when possible (`non-nullable-type-assertion-style`) +# `non-nullable-type-assertion-style` + +Prefers a non-null assertion over explicit type cast when possible. This rule detects when an `as` cast is doing the same job as a `!` would, and suggests fixing the code to be an `!`. diff --git a/packages/eslint-plugin/docs/rules/object-curly-spacing.md b/packages/eslint-plugin/docs/rules/object-curly-spacing.md index 31c1277868f4..f8f2811d7b77 100644 --- a/packages/eslint-plugin/docs/rules/object-curly-spacing.md +++ b/packages/eslint-plugin/docs/rules/object-curly-spacing.md @@ -1,4 +1,6 @@ -# Enforce consistent spacing inside braces (`object-curly-spacing`) +# `object-curly-spacing` + +Enforce consistent spacing inside braces. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/padding-line-between-statements.md b/packages/eslint-plugin/docs/rules/padding-line-between-statements.md index fd008c0fff5e..4e25f2073a6b 100644 --- a/packages/eslint-plugin/docs/rules/padding-line-between-statements.md +++ b/packages/eslint-plugin/docs/rules/padding-line-between-statements.md @@ -1,4 +1,6 @@ -# require or disallow padding lines between statements (`padding-line-between-statements`) +# `padding-line-between-statements` + +require or disallow padding lines between statements. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/prefer-as-const.md b/packages/eslint-plugin/docs/rules/prefer-as-const.md index e873bb5a1f77..47ab9787ec91 100644 --- a/packages/eslint-plugin/docs/rules/prefer-as-const.md +++ b/packages/eslint-plugin/docs/rules/prefer-as-const.md @@ -1,4 +1,6 @@ -# Prefer usage of `as const` over literal type (`prefer-as-const`) +# `prefer-as-const` + +Prefer usage of `as const` over literal type. This rule recommends usage of `const` assertion when type primitive value is equal to type. @@ -29,6 +31,19 @@ let foo = { bar: 'baz' }; +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/prefer-as-const": "error" + } +} +``` + +This rule is not configurable. + ## When Not To Use It If you are using TypeScript < 3.4 diff --git a/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md b/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md index 7baefc1b65ed..357350b76420 100644 --- a/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md +++ b/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md @@ -1,4 +1,6 @@ -# Prefer initializing each enums member value (`prefer-enum-initializers`) +# `prefer-enum-initializers` + +Prefer initializing each enums member value. This rule recommends having each `enum`s member value explicitly initialized. diff --git a/packages/eslint-plugin/docs/rules/prefer-for-of.md b/packages/eslint-plugin/docs/rules/prefer-for-of.md index bb58a598ed5f..f7447d82f177 100644 --- a/packages/eslint-plugin/docs/rules/prefer-for-of.md +++ b/packages/eslint-plugin/docs/rules/prefer-for-of.md @@ -1,4 +1,6 @@ -# Prefer a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated (`prefer-for-of`) +# `prefer-for-of` + +Prefer a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated. This rule recommends a for-of loop when the loop index is only used to read from an array that is being iterated. diff --git a/packages/eslint-plugin/docs/rules/prefer-function-type.md b/packages/eslint-plugin/docs/rules/prefer-function-type.md index c67a61bfa5e1..ffa187df83cd 100644 --- a/packages/eslint-plugin/docs/rules/prefer-function-type.md +++ b/packages/eslint-plugin/docs/rules/prefer-function-type.md @@ -1,4 +1,6 @@ -# Use function types instead of interfaces with call signatures (`prefer-function-type`) +# `prefer-function-type` + +Use function types instead of interfaces with call signatures. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/prefer-includes.md b/packages/eslint-plugin/docs/rules/prefer-includes.md index 57eb97b271f7..f23889a49006 100644 --- a/packages/eslint-plugin/docs/rules/prefer-includes.md +++ b/packages/eslint-plugin/docs/rules/prefer-includes.md @@ -1,4 +1,6 @@ -# Enforce `includes` method over `indexOf` method (`prefer-includes`) +# `prefer-includes` + +Enforce `includes` method over `indexOf` method. Until ES5, we were using `String#indexOf` method to check whether a string contains an arbitrary substring or not. Until ES2015, we were using `Array#indexOf` method to check whether an array contains an arbitrary value or not. diff --git a/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md b/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md index eb952dfd407b..ff7a1ce821d9 100644 --- a/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md +++ b/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md @@ -1,4 +1,6 @@ -# Require that all enum members be literal values to prevent unintended enum member name shadow issues (`prefer-literal-enum-member`) +# `prefer-literal-enum-member` + +Require that all enum members be literal values to prevent unintended enum member name shadow issues. TypeScript allows the value of an enum member to be many different kinds of valid JavaScript expressions. However, because enums create their own scope whereby each enum member becomes a variable in that scope, unexpected values could be used at runtime. Example: diff --git a/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md b/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md index a0ddd28500fc..887c8171b367 100644 --- a/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md +++ b/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md @@ -1,4 +1,6 @@ -# Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules (`prefer-namespace-keyword`) +# `prefer-namespace-keyword` + +Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. In an effort to prevent further confusion between custom TypeScript modules and the new ES2015 modules, starting with TypeScript `v1.5` the keyword `namespace` is now the preferred way to declare custom TypeScript modules. @@ -11,6 +13,19 @@ This rule aims to standardize the way modules are declared. If you are using the ES2015 module syntax, then you will not need this rule. +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/prefer-namespace-keyword": "error" + } +} +``` + +This rule is not configurable. + ## Further Reading - [Modules](https://www.typescriptlang.org/docs/handbook/modules.html) diff --git a/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md b/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md index feb7735ddc83..dd9c02009f9c 100644 --- a/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md +++ b/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md @@ -1,4 +1,6 @@ -# Enforce the usage of the nullish coalescing operator instead of logical chaining (`prefer-nullish-coalescing`) +# `prefer-nullish-coalescing` + +Enforce the usage of the nullish coalescing operator instead of logical chaining. TypeScript 3.7 added support for the nullish coalescing operator. This operator allows you to safely cascade a value when dealing with `null` or `undefined`. diff --git a/packages/eslint-plugin/docs/rules/prefer-optional-chain.md b/packages/eslint-plugin/docs/rules/prefer-optional-chain.md index 179ba9887332..1f42754e0f75 100644 --- a/packages/eslint-plugin/docs/rules/prefer-optional-chain.md +++ b/packages/eslint-plugin/docs/rules/prefer-optional-chain.md @@ -1,4 +1,6 @@ -# Prefer using concise optional chain expressions instead of chained logical ands (`prefer-optional-chain`) +# `prefer-optional-chain` + +Prefer using concise optional chain expressions instead of chained logical ands. TypeScript 3.7 added support for the optional chain operator. This operator allows you to safely access properties and methods on objects when they are potentially `null` or `undefined`. diff --git a/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md b/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md index 6790b55113e8..0446c34de46c 100644 --- a/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md +++ b/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md @@ -1,4 +1,6 @@ -# Requires that function parameters are typed as readonly to prevent accidental mutation of inputs (`prefer-readonly-parameter-types`) +# `prefer-readonly-parameter-types` + +Requires that function parameters are typed as readonly to prevent accidental mutation of inputs. Mutating function arguments can lead to confusing, hard to debug behavior. Whilst it's easy to implicitly remember to not modify function arguments, explicitly typing arguments as readonly provides clear contract to consumers. diff --git a/packages/eslint-plugin/docs/rules/prefer-readonly.md b/packages/eslint-plugin/docs/rules/prefer-readonly.md index 52703de7d839..9698c8e92515 100644 --- a/packages/eslint-plugin/docs/rules/prefer-readonly.md +++ b/packages/eslint-plugin/docs/rules/prefer-readonly.md @@ -1,4 +1,6 @@ -# Requires that private members are marked as `readonly` if they're never modified outside of the constructor (`prefer-readonly`) +# `prefer-readonly` + +Requires that private members are marked as `readonly` if they're never modified outside of the constructor. This rule enforces that private members are marked as `readonly` if they're never modified outside of the constructor. diff --git a/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md b/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md index 8ad9d675b53c..b53593438998 100644 --- a/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md +++ b/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md @@ -1,4 +1,6 @@ -# Prefer using type parameter when calling `Array#reduce` instead of casting (`prefer-reduce-type-parameter`) +# `prefer-reduce-type-parameter` + +Prefer using type parameter when calling `Array#reduce` instead of casting. It's common to call `Array#reduce` with a generic type, such as an array or object, as the initial value. Since these values are empty, their types are not usable: diff --git a/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md b/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md index 138ab1c1ded3..1c8202457411 100644 --- a/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md +++ b/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md @@ -1,4 +1,6 @@ -# Enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided (`prefer-regexp-exec`) +# `prefer-regexp-exec` + +Enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided. As `String#match` is defined to be the same as `RegExp#exec` when the regular expression does not include the `g` flag, prefer a consistent usage. diff --git a/packages/eslint-plugin/docs/rules/prefer-return-this-type.md b/packages/eslint-plugin/docs/rules/prefer-return-this-type.md index acc8520a97d9..c60bee7ec0dc 100644 --- a/packages/eslint-plugin/docs/rules/prefer-return-this-type.md +++ b/packages/eslint-plugin/docs/rules/prefer-return-this-type.md @@ -1,4 +1,6 @@ -# Enforce that `this` is used when only `this` type is returned (`prefer-return-this-type`) +# `prefer-return-this-type` + +Enforce that `this` is used when only `this` type is returned. [Method chaining](https://en.wikipedia.org/wiki/Method_chaining) is a common pattern in OOP languages and TypeScript provides a special [polymorphic this type](https://www.typescriptlang.org/docs/handbook/2/classes.html#this-types). If any type other than `this` is specified as the return type of these chaining methods, TypeScript will fail to cast it when invoking in subclass. diff --git a/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md b/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md index d67c7bd7d7ec..9b7cc2902ec0 100644 --- a/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md +++ b/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md @@ -1,4 +1,6 @@ -# Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings (`prefer-string-starts-ends-with`) +# `prefer-string-starts-ends-with` + +Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings. There are multiple ways to verify if a string starts or ends with a specific string, such as `foo.indexOf('bar') === 0`. diff --git a/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md b/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md index faf22348aaa2..ad9ee9745309 100644 --- a/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md +++ b/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md @@ -1,4 +1,6 @@ -# Recommends using `@ts-expect-error` over `@ts-ignore` (`prefer-ts-expect-error`) +# `prefer-ts-expect-error` + +Recommends using `@ts-expect-error` over `@ts-ignore`. TypeScript allows you to suppress all errors on a line by placing a single-line comment or a comment block line starting with `@ts-ignore` immediately before the erroring line. While powerful, there is no way to know if a `@ts-ignore` is actually suppressing an error without manually investigating what happens when the `@ts-ignore` is removed. diff --git a/packages/eslint-plugin/docs/rules/promise-function-async.md b/packages/eslint-plugin/docs/rules/promise-function-async.md index f587f6e54891..9791f586d571 100644 --- a/packages/eslint-plugin/docs/rules/promise-function-async.md +++ b/packages/eslint-plugin/docs/rules/promise-function-async.md @@ -1,4 +1,6 @@ -# Requires any function or method that returns a Promise to be marked async (`promise-function-async`) +# `promise-function-async` + +Requires any function or method that returns a Promise to be marked async. Requires any function or method that returns a Promise to be marked async. Ensures that each function is only capable of: diff --git a/packages/eslint-plugin/docs/rules/quotes.md b/packages/eslint-plugin/docs/rules/quotes.md index 825aeaf4ffaf..391c81682477 100644 --- a/packages/eslint-plugin/docs/rules/quotes.md +++ b/packages/eslint-plugin/docs/rules/quotes.md @@ -1,4 +1,6 @@ -# Enforce the consistent use of either backticks, double, or single quotes (`quotes`) +# `quotes` + +Enforce the consistent use of either backticks, double, or single quotes. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/require-array-sort-compare.md b/packages/eslint-plugin/docs/rules/require-array-sort-compare.md index 87e7ed552857..18248cca444b 100644 --- a/packages/eslint-plugin/docs/rules/require-array-sort-compare.md +++ b/packages/eslint-plugin/docs/rules/require-array-sort-compare.md @@ -1,4 +1,6 @@ -# Requires `Array#sort` calls to always provide a `compareFunction` (`require-array-sort-compare`) +# `require-array-sort-compare` + +Requires `Array#sort` calls to always provide a `compareFunction`. This rule prevents invoking the `Array#sort()` method without providing a `compare` argument. diff --git a/packages/eslint-plugin/docs/rules/require-await.md b/packages/eslint-plugin/docs/rules/require-await.md index baa155b435bc..86a5d580d874 100644 --- a/packages/eslint-plugin/docs/rules/require-await.md +++ b/packages/eslint-plugin/docs/rules/require-await.md @@ -1,4 +1,6 @@ -# Disallow async functions which have no `await` expression (`require-await`) +# `require-await` + +Disallow async functions which have no `await` expression. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/restrict-plus-operands.md b/packages/eslint-plugin/docs/rules/restrict-plus-operands.md index 35d7a984f900..c87d3a290644 100644 --- a/packages/eslint-plugin/docs/rules/restrict-plus-operands.md +++ b/packages/eslint-plugin/docs/rules/restrict-plus-operands.md @@ -1,4 +1,6 @@ -# When adding two variables, operands must both be of type number or of type string (`restrict-plus-operands`) +# `restrict-plus-operands` + +When adding two variables, operands must both be of type number or of type string. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/restrict-template-expressions.md b/packages/eslint-plugin/docs/rules/restrict-template-expressions.md index 771af5469e35..e248863cfda5 100644 --- a/packages/eslint-plugin/docs/rules/restrict-template-expressions.md +++ b/packages/eslint-plugin/docs/rules/restrict-template-expressions.md @@ -1,4 +1,6 @@ -# Enforce template literal expressions to be of string type (`restrict-template-expressions`) +# `restrict-template-expressions` + +Enforce template literal expressions to be of string type. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/return-await.md b/packages/eslint-plugin/docs/rules/return-await.md index cefe5d157536..09e4f2e2b284 100644 --- a/packages/eslint-plugin/docs/rules/return-await.md +++ b/packages/eslint-plugin/docs/rules/return-await.md @@ -1,4 +1,6 @@ -# Enforces consistent returning of awaited values (`return-await`) +# `return-await` + +Enforces consistent returning of awaited values. Returning an awaited promise can make sense for better stack trace information as well as for consistent error handling (returned promises will not be caught in an async function try/catch). diff --git a/packages/eslint-plugin/docs/rules/semi.md b/packages/eslint-plugin/docs/rules/semi.md index 2953c7670e17..46d21bfccd3b 100644 --- a/packages/eslint-plugin/docs/rules/semi.md +++ b/packages/eslint-plugin/docs/rules/semi.md @@ -1,4 +1,6 @@ -# Require or disallow semicolons instead of ASI (`semi`) +# `semi` + +Require or disallow semicolons instead of ASI. This rule enforces consistent use of semicolons after statements. diff --git a/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md b/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md index 749b88075bf9..19aa2ad18bbe 100644 --- a/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md +++ b/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md @@ -1,4 +1,6 @@ -# Enforces that members of a type union/intersection are sorted alphabetically (`sort-type-union-intersection-members`) +# `sort-type-union-intersection-members` + +Enforces that members of a type union/intersection are sorted alphabetically. Sorting union (`|`) and intersection (`&`) types can help: diff --git a/packages/eslint-plugin/docs/rules/space-before-function-paren.md b/packages/eslint-plugin/docs/rules/space-before-function-paren.md index d9dd3dd234ec..46e352e54d81 100644 --- a/packages/eslint-plugin/docs/rules/space-before-function-paren.md +++ b/packages/eslint-plugin/docs/rules/space-before-function-paren.md @@ -1,4 +1,6 @@ -# Enforces consistent spacing before function parenthesis (`space-before-function-paren`) +# `space-before-function-paren` + +Enforces consistent spacing before function parenthesis. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/space-infix-ops.md b/packages/eslint-plugin/docs/rules/space-infix-ops.md index 1f2d90445270..c95b91a4f8cb 100644 --- a/packages/eslint-plugin/docs/rules/space-infix-ops.md +++ b/packages/eslint-plugin/docs/rules/space-infix-ops.md @@ -1,4 +1,6 @@ -# This rule is aimed at ensuring there are spaces around infix operators. (`space-infix-ops`) +# `space-infix-ops` + +This rule is aimed at ensuring there are spaces around infix operators.. This rule extends the base [`eslint/space-infix-ops`](https://eslint.org/docs/rules/space-infix-ops) rule. diff --git a/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md b/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md index 61cc9efcc753..5b06af74c3f0 100644 --- a/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md +++ b/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md @@ -1,4 +1,6 @@ -# Restricts the types allowed in boolean expressions (`strict-boolean-expressions`) +# `strict-boolean-expressions` + +Restricts the types allowed in boolean expressions. Forbids usage of non-boolean types in expressions where a boolean is expected. `boolean` and `never` types are always allowed. diff --git a/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md b/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md index 4f11c66eb428..13f4123a9d03 100644 --- a/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md +++ b/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md @@ -1,4 +1,6 @@ -# Exhaustiveness checking in switch with union type (`switch-exhaustiveness-check`) +# `switch-exhaustiveness-check` + +Exhaustiveness checking in switch with union type. Union type may have a lot of parts. It's easy to forget to consider all cases in switch. This rule reminds which parts are missing. If domain of the problem requires to have only a partial switch, developer may _explicitly_ add a default clause. diff --git a/packages/eslint-plugin/docs/rules/triple-slash-reference.md b/packages/eslint-plugin/docs/rules/triple-slash-reference.md index bb32ea5b7596..23d8e12c2971 100644 --- a/packages/eslint-plugin/docs/rules/triple-slash-reference.md +++ b/packages/eslint-plugin/docs/rules/triple-slash-reference.md @@ -1,4 +1,6 @@ -# Sets preference level for triple slash directives versus ES6-style import declarations (`triple-slash-reference`) +# `triple-slash-reference` + +Sets preference level for triple slash directives versus ES6-style import declarations. Use of triple-slash reference type directives is discouraged in favor of the newer `import` style. This rule allows you to ban use of `/// `, `/// `, or `/// ` directives. diff --git a/packages/eslint-plugin/docs/rules/type-annotation-spacing.md b/packages/eslint-plugin/docs/rules/type-annotation-spacing.md index b1ca3e149504..46beee117e0e 100644 --- a/packages/eslint-plugin/docs/rules/type-annotation-spacing.md +++ b/packages/eslint-plugin/docs/rules/type-annotation-spacing.md @@ -1,4 +1,6 @@ -# Require consistent spacing around type annotations (`type-annotation-spacing`) +# `type-annotation-spacing` + +Require consistent spacing around type annotations. Spacing around type annotations improves readability of the code. Although the most commonly used style guideline for type annotations in TypeScript prescribes adding a space after the colon, but not before it, it is subjective to the preferences of a project. For example: diff --git a/packages/eslint-plugin/docs/rules/typedef.md b/packages/eslint-plugin/docs/rules/typedef.md index e4ae60a80523..75e4b1ccb57f 100644 --- a/packages/eslint-plugin/docs/rules/typedef.md +++ b/packages/eslint-plugin/docs/rules/typedef.md @@ -1,4 +1,6 @@ -# Requires type annotations to exist (`typedef`) +# `typedef` + +Requires type annotations to exist. TypeScript cannot always infer types for all places in code. Some locations require type annotations for their types to be inferred. diff --git a/packages/eslint-plugin/docs/rules/unbound-method.md b/packages/eslint-plugin/docs/rules/unbound-method.md index 60caa4018f36..69f049b6c428 100644 --- a/packages/eslint-plugin/docs/rules/unbound-method.md +++ b/packages/eslint-plugin/docs/rules/unbound-method.md @@ -1,4 +1,6 @@ -# Enforces unbound methods are called with their expected scope (`unbound-method`) +# `unbound-method` + +Enforces unbound methods are called with their expected scope. Warns when a method is used outside of a method call. diff --git a/packages/eslint-plugin/docs/rules/unified-signatures.md b/packages/eslint-plugin/docs/rules/unified-signatures.md index f71435dc3e01..0b5b527568b0 100644 --- a/packages/eslint-plugin/docs/rules/unified-signatures.md +++ b/packages/eslint-plugin/docs/rules/unified-signatures.md @@ -1,4 +1,4 @@ -# Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter (`unified-signatures`) +# `unified-signatures` Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter. diff --git a/packages/eslint-plugin/tests/docs.test.ts b/packages/eslint-plugin/tests/docs.test.ts index 61487b5169f0..51d6692e2248 100644 --- a/packages/eslint-plugin/tests/docs.test.ts +++ b/packages/eslint-plugin/tests/docs.test.ts @@ -4,6 +4,7 @@ import path from 'path'; import marked from 'marked'; import rules from '../src/rules'; import { titleCase } from 'title-case'; +import { JSONSchema4 } from 'json-schema'; const docsRoot = path.resolve(__dirname, '../docs/rules'); const rulesData = Object.entries(rules); @@ -42,6 +43,37 @@ function parseReadme(): { }; } +function isEmptySchema(schema: JSONSchema4 | JSONSchema4[]): boolean { + return Array.isArray(schema) + ? schema.length === 0 + : Object.keys(schema).length === 0; +} + +type TokenType = marked.Token['type']; + +function tokenAs( + token: marked.Token, + type: Type, +): marked.Token & { type: Type } { + expect(token.type).toBe(type); + return token as marked.Token & { type: Type }; +} + +function tokenIs( + token: marked.Token, + type: Type, +): token is marked.Token & { type: Type } { + return token.type === type; +} + +function tokenIsH1(token: marked.Token): token is marked.Tokens.Heading { + return tokenIs(token, 'heading') && token.depth === 1; +} + +function tokenIsH2(token: marked.Token): token is marked.Tokens.Heading { + return tokenIs(token, 'heading') && token.depth === 2; +} + describe('Validating rule docs', () => { it('All rules must have a corresponding rule doc', () => { const files = fs @@ -57,16 +89,24 @@ describe('Validating rule docs', () => { for (const [ruleName, rule] of rulesData) { const filePath = path.join(docsRoot, `${ruleName}.md`); + + it(`First header in ${ruleName}.md must be the name of the rule`, () => { + const tokens = parseMarkdownFile(filePath); + + const header = tokens.find(tokenIsH1)!; + + expect(header.text).toBe(`\`${ruleName}\``); + }); + it(`Description of ${ruleName}.md must match`, () => { // validate if description of rule is same as in docs const tokens = parseMarkdownFile(filePath); // Rule title not found. // Rule title does not match the rule metadata. - expect(tokens[0]).toMatchObject({ - type: 'heading', - depth: 1, - text: `${rule.meta.docs?.description} (\`${ruleName}\`)`, + expect(tokens[1]).toMatchObject({ + type: 'paragraph', + text: `${rule.meta.docs?.description}.`, }); }); @@ -74,28 +114,62 @@ describe('Validating rule docs', () => { const tokens = parseMarkdownFile(filePath); // Get all H2 headers objects as the other levels are variable by design. - const headers = tokens.filter( - token => token.type === 'heading' && token.depth === 2, - ) as marked.Tokens.Heading[]; + const headers = tokens.filter(tokenIsH2); headers.forEach(header => expect(header.text).toBe(titleCase(header.text)), ); }); + it(`Options in ${ruleName}.md must match the rule meta`, () => { + // TODO(#4365): We don't yet enforce formatting for all rules. + if ( + !isEmptySchema(rule.meta.schema) || + rule.meta.docs?.extendsBaseRule || + !rule.meta.docs?.recommended + ) { + return; + } + + const tokens = parseMarkdownFile(filePath); + + const optionsIndex = tokens.findIndex( + token => tokenIsH2(token) && token.text === 'Options', + ); + expect(optionsIndex).toBeGreaterThan(0); + + const codeBlock = tokenAs(tokens[optionsIndex + 1], 'code'); + tokenAs(tokens[optionsIndex + 2], 'space'); + const descriptionBlock = tokenAs(tokens[optionsIndex + 3], 'paragraph'); + + expect(codeBlock).toMatchObject({ + lang: 'jsonc', + text: ` +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/${ruleName}": "${rule.meta.docs?.recommended}" + } +} + `.trim(), + type: 'code', + }); + expect(descriptionBlock).toMatchObject({ + text: 'This rule is not configurable.', + }); + }); + it(`Attributes in ${ruleName}.md must match the metadata`, () => { const tokens = parseMarkdownFile(filePath); // Verify attributes header exists const attributesHeaderIndex = tokens.findIndex( - token => token.type === 'heading' && token.text === 'Attributes', + token => tokenIs(token, 'heading') && token.text === 'Attributes', ); expect(attributesHeaderIndex).toBeGreaterThan(-1); // Verify attributes content - const attributesList = tokens[ - attributesHeaderIndex + 1 - ] as marked.Tokens.List; + const attributesList = tokenAs(tokens[attributesHeaderIndex + 1], 'list'); const recommended = attributesList.items[0]; expect(rule.meta.docs?.recommended !== false).toBe(recommended.checked); const fixable = attributesList.items[1]; From be0b011af8b0a0814ab5fb4426c62d4ecb978c1f Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 30 Dec 2021 12:57:33 -0500 Subject: [PATCH 2/5] chore: fix package devDependencies listings --- packages/eslint-plugin/package.json | 2 ++ packages/eslint-plugin/tests/docs.test.ts | 2 +- yarn.lock | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index ad6bbd7f1099..8386cafc5b54 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -56,9 +56,11 @@ }, "devDependencies": { "@types/debug": "*", + "@types/json-schema": "*", "@types/marked": "*", "@types/prettier": "*", "chalk": "^4.1.2", + "json-schema": "*", "marked": "^3.0.7", "prettier": "*", "title-case": "^3.0.3", diff --git a/packages/eslint-plugin/tests/docs.test.ts b/packages/eslint-plugin/tests/docs.test.ts index 51d6692e2248..64e210875902 100644 --- a/packages/eslint-plugin/tests/docs.test.ts +++ b/packages/eslint-plugin/tests/docs.test.ts @@ -1,10 +1,10 @@ import fs from 'fs'; +import { JSONSchema4 } from 'json-schema'; import path from 'path'; import marked from 'marked'; import rules from '../src/rules'; import { titleCase } from 'title-case'; -import { JSONSchema4 } from 'json-schema'; const docsRoot = path.resolve(__dirname, '../docs/rules'); const rulesData = Object.entries(rules); diff --git a/yarn.lock b/yarn.lock index 3c305e231a21..c0b82cf40f4e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9386,7 +9386,7 @@ json-schema-traverse@^1.0.0: resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2" integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug== -json-schema@0.2.3: +json-schema@*, json-schema@0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" integrity sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM= From 12d91a6ad2654018608db03378360aec6cd17552 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 23 Jan 2022 17:24:47 -0500 Subject: [PATCH 3/5] docs: add template rule docs file --- packages/eslint-plugin/docs/rules/TEMPLATE.md | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 packages/eslint-plugin/docs/rules/TEMPLATE.md diff --git a/packages/eslint-plugin/docs/rules/TEMPLATE.md b/packages/eslint-plugin/docs/rules/TEMPLATE.md new file mode 100644 index 000000000000..5234033e4070 --- /dev/null +++ b/packages/eslint-plugin/docs/rules/TEMPLATE.md @@ -0,0 +1,56 @@ +# `your-rule-name` + +Your rule description here. + +## Rule Details + +To fill out: tell us more about this rule. + + + +### ❌ Incorrect + +```ts +// To fill out: incorrect code +``` + +### ✅ Correct + +```ts +// To fill out: correct code +``` + +## Options + +```jsonc +// .eslintrc.json +{ + "rules": { + "@typescript-eslint/your-rule-name": "error" + } +} +``` + +If not configurable: This rule is not configurable. + +If configurable... + +```ts +type Options = { + someOption?: boolean; +}; + +const defaultOptions: Options = { + someOption: false, +}; +``` + +## When Not To Use It + +To fill out: why wouldn't you want to use this rule? + +## Attributes + +- [ ] ✅ Recommended +- [ ] 🔧 Fixable +- [ ] 💭 Requires type information From 11b5c05ea75617f6ce1158833d0a7f1be2e7fd83 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 23 Jan 2022 18:03:50 -0500 Subject: [PATCH 4/5] chore: fix docs.test.ts --- packages/eslint-plugin/tests/docs.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/tests/docs.test.ts b/packages/eslint-plugin/tests/docs.test.ts index 9cac9d66e43f..149c065bc233 100644 --- a/packages/eslint-plugin/tests/docs.test.ts +++ b/packages/eslint-plugin/tests/docs.test.ts @@ -75,11 +75,16 @@ function tokenIsH2(token: marked.Token): token is marked.Tokens.Heading { } describe('Validating rule docs', () => { + const ignoredFiles = new Set([ + // this rule doc was left behind on purpose for legacy reasons + 'camelcase.md', + 'README.md', + 'TEMPLATE.md', + ]); it('All rules must have a corresponding rule doc', () => { const files = fs .readdirSync(docsRoot) - // this rule doc was left behind on purpose for legacy reasons - .filter(rule => rule !== 'camelcase.md' && rule !== 'README.md'); + .filter(rule => !ignoredFiles.has(rule)); const ruleFiles = Object.keys(rules) .map(rule => `${rule}.md`) .sort(); From fed1694854c3423b7e92aa8c9226cf9ba08d901f Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 29 Jan 2022 10:51:31 -0500 Subject: [PATCH 5/5] docs: added example suggested --- packages/eslint-plugin/docs/rules/TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-plugin/docs/rules/TEMPLATE.md b/packages/eslint-plugin/docs/rules/TEMPLATE.md index 5234033e4070..174fb71c6b35 100644 --- a/packages/eslint-plugin/docs/rules/TEMPLATE.md +++ b/packages/eslint-plugin/docs/rules/TEMPLATE.md @@ -48,6 +48,7 @@ const defaultOptions: Options = { ## When Not To Use It To fill out: why wouldn't you want to use this rule? +For example if this rule requires a feature released in a certain TS version. ## Attributes