Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
OliverSieweke opened this issue Oct 3, 2019 · 2 comments
Labels
documentation Documentation ("docs") that needs adding/updating package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@OliverSieweke
Copy link
Contributor

OliverSieweke commented Oct 3, 2019

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
@OliverSieweke OliverSieweke added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Oct 3, 2019
@OliverSieweke OliverSieweke changed the title [no-unreachable] Rule disabled by default Questionably [no-unreachable] Recommended rule disabled with default TS compiler options Oct 3, 2019
@bradzacher bradzacher added documentation Documentation ("docs") that needs adding/updating and removed triage Waiting for maintainers to take a look labels Oct 4, 2019
@bradzacher
Copy link
Member

Happy to accept a PR to improve the documentation around the usage of eslint-recommended.

@OliverSieweke
Copy link
Contributor Author

Great! I've noticed a couple more issues similar to #999 and #983 - l'll report those when I get to it in the next days and will think about a good way to include a note in the docs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation ("docs") that needs adding/updating package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants