eslint/rules/dead-code
Dead code: Unused, unreachable, useless, empty or duplicated code. Rules of ESLint, typescript-eslint and SonarJS (the Sonar way profile of SonarQube) on this subject, every rule listed; the TypeScript rules apply to TypeScript files only.
16 rules, 13 on. Source: lint/eslint/rules/dead-code.mjs.
| Rule | Setting | Files | What it checks | Why |
|---|---|---|---|---|
no-debugger | error | JS + TS | Disallow the use of debugger | — |
no-empty-pattern | error | JS + TS | Disallow empty destructuring patterns | — |
no-self-assign | error | JS + TS | Disallow assignments where both sides are exactly the same | — |
no-unreachable | error | JS + TS | Disallow unreachable code after return, throw, continue, and break statements | Kept: TypeScript only greys out dead code, allowUnreachableCode: false would also block the dev loop. |
no-useless-assignment | error | JS + TS | Disallow variable assignments when the value is not used | — |
no-empty | warn | JS + TS | Disallow empty block statements | — |
no-lone-blocks | info | JS + TS | Disallow unnecessary nested blocks | — |
no-unused-expressions | error | JS + TS | Disallow unused expressions | Replaced by the TS version. |
sonarjs/no-dead-store | off | JS + TS | Unused assignments should be removed | Off: duplicate of no-useless-assignment. |
sonarjs/no-duplicate-in-composite | off | JS + TS | Union and intersection types should not include duplicated constituents | Off: duplicate of @typescript-eslint/no-duplicate-type-constituents. |
sonarjs/no-redundant-jump | warn | JS + TS | Jump statements should not be redundant | Sonar way; replaces the core no-useless-return, like SonarQube. |
sonarjs/no-redundant-optional | warn | JS + TS | Optional property declarations should not use both '?' and 'undefined' syntax | — |
no-unreachable | error | TS | Disallow unreachable code after return, throw, continue, and break statements | Kept: TypeScript only greys out dead code, allowUnreachableCode: false would also block the dev loop. |
@typescript-eslint/no-unnecessary-qualifier | error | TS | Disallow unnecessary namespace qualifiers | — |
no-unused-expressions | off | TS | Disallow unused expressions | Replaced by the TS version. |
@typescript-eslint/no-unused-expressions | error | TS | Disallow unused expressions | — |