Skip to content

[no-unreachable] Recommended rule disabled with default TS compiler options #1041

@OliverSieweke

Description

@OliverSieweke

Recommended ESLint rules that are already handled by TypeScript are turned off in plugin:@typescript-eslint/recommended.

The no-unreachable rule is one of the disabled rules because it is covered by the TypeScript compiler error TS7027. However this TS error is suppressed by default since 2.9.1.

This means that when using the recommended rules without explicitly turning off the allowUnreachableCode flag, no ESLint or TS errors will alert the developer of the presence of unreachable code.

I am not sure what the best approach to this is, but it may be worth considering not disabling no-unreachable in the recommended rules or adding a note in the docs...

Repro

{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended"
  ]
}

From the ESLint docs:

function fn() {
    x = 1;
    return x;
    x = 3; // this will never execute
}

Expected Result
To be alerted of the unreachable code.

Actual Result
No error reported with the default TypeScript compiler options.

Versions

package version
@typescript-eslint/eslint-plugin 2.3.0
@typescript-eslint/parser 2.3.0
TypeScript 3.6.3
ESLint 6.4.0
node 10.16.3
npm 6.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationDocumentation ("docs") that needs adding/updatingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions