Overview
@typescript-eslint/eslint-plugin includes over 100 rules that detect best practice violations, bugs, and/or stylistic issues specifically for TypeScript code. All of our rules are listed below.
tip
Instead of enabling rules one by one, we recommend using one of our pre-defined configs to enable a large set of recommended rules.
Rulesβ
The rules are listed in alphabetical order. You can optionally filter them based on these categories:
Config Group (βοΈ)
Metadata
(These categories are explained in more detail below.)
| Rule | βοΈ | π§ | π | π§± | π |
|---|---|---|---|---|---|
Require that function overload signatures be consecutive | π¨ | ||||
Require consistently using either T[] or Array<T> for arrays | π¨ | π§ | |||
Disallow awaiting a value that is not a Thenable | β | π‘ | π | ||
Disallow @ts-<directive> comments or require descriptions after directives | β | π‘ | |||
Disallow // tslint:<rule-flag> comments | π¨ | π§ | |||
Enforce that literals on classes are exposed in a consistent style | π¨ | π‘ | |||
Enforce that class methods utilize this | π§± | ||||
Enforce specifying generic type arguments on type annotation or constructor name of a constructor call | π¨ | π§ | |||
Require or disallow the Record type | π¨ | π§ π‘ | |||
Require return statements to either always or never specify values | π | π§± | |||
Enforce consistent usage of type assertions | π¨ | π§ π‘ | |||
Enforce type definitions to consistently use either interface or type | π¨ | π§ | |||
Enforce consistent usage of type exports | π§ | π | |||
Enforce consistent usage of type imports | π§ | ||||
Enforce default parameters to be last | π§± | ||||
Enforce dot notation whenever possible | π¨ | π§ | π | π§± | |
Require explicit return types on functions and class methods | |||||
Require explicit accessibility modifiers on class properties and methods | π§ π‘ | ||||
Require explicit return and argument types on exported functions' and classes' public class methods | |||||
Require or disallow initialization in variable declarations | π§± | ||||
Enforce a maximum number of parameters in function definitions | π§± | ||||
Require a consistent member declaration order | |||||
Enforce using a particular method signature syntax | π§ | ||||
Enforce naming conventions for everything across a codebase | π | ||||
Disallow generic Array constructors | β | π§ | π§± | ||
Disallow using the delete operator on array values | β | π‘ | π | ||
Require .toString() and .toLocaleString() to only be called on objects which provide useful information when stringified | β | π | |||
Disallow non-null assertion in locations that may be confusing | π¨ | π‘ | |||
Require expressions of type void to appear in statement position | π | π§ π‘ | π | ||
Disallow using code marked as @deprecated | π | π | |||
Disallow duplicate class members | π§± | ||||
Disallow duplicate enum member values | β | ||||
Disallow duplicate constituents of union or intersection types | β | π§ | π | ||
Disallow using the delete operator on computed key expressions | π | ||||
Disallow empty functions | π¨ | π‘ | π§± | ||
Disallow the declaration of empty interfaces | π§ π‘ | π | |||
Disallow accidentally using the "empty object" type | β | π‘ | |||
Disallow the any type | β | π§ π‘ | |||
Disallow extra non-null assertions | β | π§ | |||
Disallow classes used as namespaces | π | ||||
Require Promise-like statements to be handled appropriately | β | π‘ | π | ||
Disallow iterating over an array with a for-in loop | β | π | |||
Disallow the use of eval()-like functions | β | π | π§± | ||
Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers | π§ | ||||
Disallow explicit type declarations for variables or parameters initialized to a number, string, or boolean | π¨ | π§ | |||
Disallow this keywords outside of classes or class-like objects | π§± | ||||
Disallow void type outside of generic or return types | π | ||||
Disallow function declarations that contain unsafe references inside loop statements | π§± | ||||
Disallow literal numbers that lose precision | π§± | π | |||
Disallow magic numbers | π§± | ||||
Disallow the void operator except when used to discard a value | π | π§ π‘ | π | ||
Enforce valid definition of new and constructor | β | ||||
Disallow Promises in places not designed to handle them | β | π | |||
Disallow using the spread operator when it might cause unexpected behavior | π | π‘ | π | ||
Disallow enums from having both number and string members | π | π | |||
Disallow TypeScript namespaces | β | ||||
Disallow non-null assertions in the left operand of a nullish coalescing operator | π | π‘ | |||
Disallow non-null assertions after an optional chain expression | β | π‘ | |||
Disallow non-null assertions using the ! postfix operator | π | π‘ | |||
Disallow variable redeclaration | π§± | ||||
Disallow members of unions and intersections that do nothing or override type information | β | π | |||
Disallow invocation of require() | β | ||||
Disallow specified modules when loaded by import | π§± | ||||
Disallow certain types | π§ π‘ | ||||
Disallow variable declarations from shadowing variables declared in the outer scope | π§± | ||||
Disallow aliasing this | β | ||||
Disallow type aliases | π | ||||
Disallow unnecessary equality comparisons against boolean literals | π | π§ | π | ||
Disallow conditionals where the type is always truthy or always falsy | π | π‘ | π | ||
Disallow unnecessary assignment of constructor property parameter | |||||
Disallow unnecessary namespace qualifiers | π§ | π | |||
Disallow unnecessary template expressions | π | π§ | π | ||
Disallow type arguments that are equal to the default | π | π§ | π | ||
Disallow type assertions that do not change the type of an expression | β | π§ | π | ||
Disallow unnecessary constraints on generic types | β | π‘ | |||
Disallow conversion idioms when they do not change the type or value of the expression | π | π‘ | π | ||
Disallow type parameters that aren't used multiple times | π | π‘ | π | ||
Disallow calling a function with a value with type any | β | π | |||
Disallow assigning a value with type any to variables and properties | β | π | |||
Disallow calling a value with type any | β | π | |||
Disallow unsafe declaration merging | β | ||||
Disallow comparing an enum value with a non-enum value | β | π‘ | π | ||
Disallow using the unsafe built-in Function type | β | ||||
Disallow member access on a value with type any | β | π | |||
Disallow returning a value with type any from a function | β | π | |||
Disallow type assertions that narrow a type | π | ||||
Require unary negation to take a number | β | π | |||
Disallow unused expressions | β | π§± | |||
Disallow unused private class members | π§± | ||||
Disallow unused variables | β | π§± | |||
Disallow the use of variables before they are defined | π§± | ||||
Disallow unnecessary constructors | π | π‘ | π§± | ||
Disallow default values that will never be used | π | π§ | π | ||
Disallow empty exports that don't change anything in a module file | π§ | ||||
Disallow require statements except in import statements | π | ||||
Disallow using confusing built-in primitive class wrappers | β | π§ | |||
Enforce non-null assertions over explicit type assertions | π¨ | π§ | π | ||
Disallow throwing non- Error values as exceptions | β | π | π§± | ||
Require or disallow parameter properties in class constructors | |||||
Enforce the use of as const over literal type | β |