Config for strict TypeScript projects.
-
If you haven't already, make sure to install
@code-pushup/eslint-config
and its required peer dependencies. -
Since this plugin requires additional peer dependencies, you have to install them as well:
npm install -D eslint-plugin-deprecation
-
Because this config includes rules which require type information, make sure to configure
parserOptions.project
in your .eslintrc points to your project's tsconfig. For more information, refer to Linting with Type Information (typescript-eslint), or Configuring ESLint with Typescript (Nx) if using Nx monorepo.-
Example for library in Nx monorepo:
{ "extends": ["../../.eslintrc.json"], "ignorePatterns": ["!**/*"], "overrides": [ { "files": "*.ts", "parserOptions": { "project": ["libs/shared-utils/tsconfig.*?.json"] } } ] }
Similarly, you may need to configure a tsconfig file for
eslint-plugin-import
rules (e.g. if using path aliases in.ts
files):-
Install additional import resolver:
npm i -D eslint-import-resolver-typescript
-
Example
.eslintrc.json
for Nx monorepo:{ // ... "settings": { "import/resolver": { "typescript": { "alwaysTryTypes": true, "project": "tsconfig.base.json" // or if using RxJS: // "project": ["tsconfig.base.json", "node_modules/rxjs/tsconfig.json"] } } } }
-
-
Add to
extends
in your .eslintrc file:{ "extends": ["@code-pushup/eslint-config/typescript"] }
248 rules are included from the default config. For brevity, only the 47 additional rules are listed in this document.
🔧 Automatically fixable by the
--fix
CLI option.
💡 Manually fixable by editor suggestions.
🧪🚫 Disabled for test files.
🧪⚠️ Severity lessened to warning for test files.
Plugin | Rule | Options | Autofix | Overrides |
---|---|---|---|---|
![]() |
await-thenable Disallow awaiting a value that is not a Thenable |
💡 | ||
![]() |
consistent-type-assertions Enforce consistent usage of type assertions |
assertionStyle: as, objectL...{
"assertionStyle": "as",
"objectLiteralTypeAssertions": "never"
} |
🔧, 💡 | 🧪 |
![]() |
no-array-delete Disallow using the delete operator on array values |
💡 | ||
![]() |
no-base-to-string Require .toString() to only be called on objects which provide useful information when stringified |
|||
![]() |
no-duplicate-type-constituents Disallow duplicate constituents of union or intersection types |
🔧 | ||
![]() |
no-dynamic-delete Disallow using the delete operator on computed key expressions |
🔧 | ||
![]() |
no-extraneous-class Disallow classes used as namespaces |
|||
![]() |
no-floating-promises Require Promise-like statements to be handled appropriately |
💡 | ||
![]() |
no-for-in-array Disallow iterating over an array with a for-in loop |
|||
![]() |
no-implied-eval Disallow the use of eval() -like methods |
|||
![]() |
no-invalid-void-type Disallow void type outside of generic or return types |
|||
![]() |
no-misused-promises Disallow Promises in places not designed to handle them |
|||
![]() |
no-mixed-enums Disallow enums from having both number and string members |
|||
![]() |
no-non-null-asserted-nullish-coalescing Disallow non-null assertions in the left operand of a nullish coalescing operator |
💡 | ||
![]() |
no-non-null-assertion Disallow non-null assertions using the ! postfix operator |
💡 | ||
![]() |
no-redundant-type-constituents Disallow members of unions and intersections that do nothing or override type information |
|||
![]() |
no-unnecessary-type-assertion Disallow type assertions that do not change the type of an expression |
🔧 | ||
![]() |
no-unsafe-argument Disallow calling a function with a value with type any |
🧪🚫 | ||
![]() |
no-unsafe-assignment Disallow assigning a value with type any to variables and properties |
🧪🚫 | ||
![]() |
no-unsafe-call Disallow calling a value with type any |
|||
![]() |
no-unsafe-member-access Disallow member access on a value with type any |
🧪🚫 | ||
![]() |
no-unsafe-return Disallow returning a value with type any from a function |
🧪🚫 | ||
![]() |
no-unsafe-unary-minus Require unary negation to take a number |
|||
![]() |
no-useless-constructor Disallow unnecessary constructors |
|||
![]() |
only-throw-error Disallow throwing non- Error values as exceptions |
|||
![]() |
prefer-literal-enum-member Require all enum members to be literal values |
|||
![]() |
require-await Disallow async functions which do not return promises and have no await expression |
🧪 |
||
![]() |
restrict-plus-operands Require both operands of addition to be the same type and be bigint , number , or string |
allowAny: false, allowBoole...{
"allowAny": false,
"allowBoolean": false,
"allowNullish": false,
"allowNumberAndString": false,
"allowRegExp": false
} |
||
![]() |
restrict-template-expressions Enforce template literal expressions to be of string type |
allowBoolean: true, allowNu...{
"allowBoolean": true,
"allowNumber": true
} |
🧪🚫 | |
![]() |
unified-signatures Disallow two overloads that could be unified into one with a union or an optional/rest parameter |
|||
![]() |
use-unknown-in-catch-callback-variable Enforce typing arguments in .catch() callbacks as unknown |
🔧, 💡 | ||
![]() |
deprecation Do not use deprecated APIs. |
|||
![]() |
immutable-data Enforce treating data as immutable. |
ignoreImmediateMutation: tr...{
"ignoreImmediateMutation": true,
"ignoreClasses": true
} |
🧪 |
Plugin | Rule | Options | Autofix | Overrides |
---|---|---|---|---|
![]() |
naming-convention Enforce naming conventions for everything across a codebase |
selector: variableLike, met...[
{
"selector": [
"variableLike",
"method",
"typeProperty",
"parameterProperty",
"classProperty"
],
"format": [
"camelCase"
]
},
{
"selector": "variable",
"format": [
"camelCase",
"UPPER_CASE"
]
},
{
"selector": "typeLike",
"format": [
"PascalCase"
]
},
{
"selector": "enumMember",
"format": [
"PascalCase"
]
},
{
"selector": "parameter",
"modifiers": [
"unused"
],
"format": null,
"custom": {
"regex": "^(_+|[a-z][a-zA-Z0-9]*)$",
"match": true
}
},
{
"selector": "objectLiteralProperty",
"modifiers": [
"requiresQuotes"
],
"format": null
},
{
"selector": [
"variable",
"parameter"
],
"modifiers": [
"destructured"
],
"format": null
}
] |
||
![]() |
no-confusing-void-expression Require expressions of type void to appear in statement position |
🔧, 💡 | ||
![]() |
no-meaningless-void-operator Disallow the void operator except when used to discard a value |
🔧, 💡 | ||
![]() |
no-unnecessary-boolean-literal-compare Disallow unnecessary equality comparisons against boolean literals |
🔧 | ||
![]() |
no-unnecessary-condition Disallow conditionals where the type is always truthy or always falsy |
🔧 | ||
![]() |
no-unnecessary-template-expression Disallow unnecessary template expressions |
🔧 | ||
![]() |
no-unnecessary-type-arguments Disallow type arguments that are equal to the default |
🔧 | ||
![]() |
prefer-includes Enforce includes method over indexOf method |
🔧 | ||
![]() |
prefer-nullish-coalescing Enforce using the nullish coalescing operator instead of logical assignments or chaining |
ignorePrimitives: {"string"...{
"ignorePrimitives": {
"string": true
}
} |
💡 | |
![]() |
prefer-promise-reject-errors Require using Error objects as Promise rejection reasons |
|||
![]() |
prefer-reduce-type-parameter Enforce using type parameter when calling Array#reduce instead of casting |
🔧 | 🧪🚫 | |
![]() |
prefer-return-this-type Enforce that this is used when only this type is returned |
🔧 | ||
![]() |
prefer-property-signatures Prefer property signatures over method signatures. |
|||
![]() |
prefer-tacit Replaces x => f(x) with just f . |
💡 |