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.
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:
(These categories are explained in more detail below.)
Rule | ⚙️ | 🔧 | 💭 | 🧱 | 💀 |
---|---|---|---|---|---|
@typescript-eslint/class-methods-use-this Enforce that class methods utilize this | 🧱 | ||||
@typescript-eslint/consistent-return Require return statements to either always or never specify values | 💭 | 🧱 | |||
@typescript-eslint/default-param-last Enforce default parameters to be last | 🧱 | ||||
@typescript-eslint/dot-notation Enforce dot notation whenever possible | 🎨 | 🔧 | 💭 | 🧱 | |
@typescript-eslint/init-declarations Require or disallow initialization in variable declarations | 🧱 | ||||
@typescript-eslint/max-params Enforce a maximum number of parameters in function definitions | 🧱 | ||||
@typescript-eslint/no-array-constructor Disallow generic Array constructors | ✅ | 🔧 | 🧱 | ||
@typescript-eslint/no-dupe-class-members Disallow duplicate class members | 🧱 | ||||
@typescript-eslint/no-empty-function Disallow empty functions | 🎨 | 🧱 | |||
@typescript-eslint/no-implied-eval Disallow the use of eval() -like functions | ✅ | 💭 | 🧱 | ||
@typescript-eslint/no-invalid-this Disallow this keywords outside of classes or class-like objects | 🧱 | ||||
@typescript-eslint/no-loop-func Disallow function declarations that contain unsafe references inside loop statements | 🧱 | ||||
@typescript-eslint/no-loss-of-precision Disallow literal numbers that lose precision | 🧱 | 💀 | |||
@typescript-eslint/no-magic-numbers Disallow magic numbers | 🧱 | ||||
@typescript-eslint/no-redeclare Disallow variable redeclaration | 🧱 | ||||
@typescript-eslint/no-restricted-imports Disallow specified modules when loaded by import | 🧱 | ||||
@typescript-eslint/no-shadow Disallow variable declarations from shadowing variables declared in the outer scope | 🧱 | ||||
@typescript-eslint/no-unused-expressions Disallow unused expressions | ✅ | 🧱 | |||
@typescript-eslint/no-unused-vars Disallow unused variables | ✅ | 🧱 | |||
@typescript-eslint/no-use-before-define Disallow the use of variables before they are defined | 🧱 | ||||
@typescript-eslint/no-useless-constructor Disallow unnecessary constructors | 🔒 | 💡 | 🧱 | ||
@typescript-eslint/only-throw-error Disallow throwing non- Error values as exceptions | ✅ | 💭 | 🧱 | ||
@typescript-eslint/prefer-destructuring Require destructuring from arrays and/or objects | 🔧 | 💭 | 🧱 | ||
@typescript-eslint/prefer-promise-reject-errors Require using Error objects as Promise rejection reasons | ✅ | 💭 | 🧱 | ||
@typescript-eslint/require-await Disallow async functions which do not return promises and have no await expression | ✅ | 💡 | 💭 | 🧱 |
Filtering
Config Group (⚙️)
"Config Group" refers to the pre-defined config that includes the rule. Extending from a configuration preset allow for enabling a large set of recommended rules all at once.
Metadata
🔧 fixable
refers to whether the rule contains an ESLint--fix
auto-fixer.💡 has suggestions
refers to whether the rule contains an ESLint suggestion fixer.- Sometimes, it is not safe to automatically fix the code with an auto-fixer. But in these cases, we often have a good guess of what the correct fix should be, and we can provide it as a suggestion to the developer.
💭 requires type information
refers to whether the rule requires typed linting.🧱 extension rule
means that the rule is an extension of an core ESLint rule (see Extension Rules).💀 deprecated rule
means that the rule should no longer be used and will be removed from the plugin in a future version.
Extension Rules
Some core ESLint rules do not support TypeScript syntax: either they crash, ignore the syntax, or falsely report against it. In these cases, we create what we call an "extension rule": a rule within our plugin that has the same functionality, but also supports TypeScript.
Extension rules generally completely replace the base rule from ESLint core. If the base rule is enabled in a config you extend from, you'll need to disable the base rule:
module.exports = {
extends: ['eslint:recommended'],
rules: {
// Note: you must disable the base rule as it can report incorrect errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
},
};
Search for 🧱 extension rule
s in this page to see all extension rules.