question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`no-unreachable` reports EmptyStatements

See original GitHub issue

Thank you for a wonderful tool. Most times I think I find a bug, instead I learn a JS horror detail.

Can’t figure this one out yet. Don’t think it’s env related.

  • ESLint - 4.3.0
  • Node - 8.1.3
  • NPM - 5.3.0
  • Parser - babel-eslint
  • Exhibits on Mac, Win10, Travis CI’s debian

Please show your full configuration:

Configuration
John-Haugeland:jssm johnhaugeland$ cat .eslintrc 
{

  "parser"  : "babel-eslint",
  "plugins" : [ ],
  "env"     : { "es6": true, "commonjs": true },

  "extends" : "eslint-config-stonecypher"

}

eslint-config-stonecypher in turn configures every current eslint rule, plus eslint-plugin-flowtype, fp, jsdoc, ava, unicorn, new-with-error, and promise

What did you do? Please include the actual source code causing the issue.

The following code triggers “no-unreachable” at the end of the switch, even though it’s the last action in a default, ostensibly because of the throw.

const arrow_direction = arrow => {

  switch (arrow) {

    case '->': case '=>': case '~>':
      return 'right';

    case '<-': case '<=': case '<~':
      return 'left';

    case '<->': case '<-=>': case '<-~>':
    case '<=>': case '<=->': case '<=~>':
    case '<~>': case '<~->': case '<~=>':
      return 'both';

    default:
      throw new Error(`arrow_direction: unknown arrow type ${arrow}`);

  };

}

What did you expect to happen? Nothing. No code follows the throw.

This similar code does not trigger the warning, I expect because the throw is now outside the switch.

const arrow_direction = arrow => {

  switch (arrow) {

    case '->': case '=>': case '~>':
      return 'right';

    case '<-': case '<=': case '<~':
      return 'left';

    case '<->': case '<-=>': case '<-~>':
    case '<=>': case '<=->': case '<=~>':
    case '<~>': case '<~->': case '<~=>':
      return 'both';

  };

  throw new Error(`arrow_direction: unknown arrow type ${arrow}`);

}

What actually happened? Please include the actual, raw output from ESLint.

/Users/johnhaugeland/projects/jssm/src/js/jssm.js
   22:7    warning  'arrow_direction' is assigned a value but never used  no-unused-vars
   22:7    warning  Missing "arrow_direction" variable type annotation    flowtype/require-variable-type
   22:25   warning  Missing return type annotation                        flowtype/require-return-type
   22:25   warning  Missing "arrow" parameter type annotation             flowtype/require-parameter-type
   44:4    warning  Unnecessary semicolon                                 no-extra-semi
   44:4    error    Unreachable code                                      no-unreachable
...

It’s not like it’s a big deal, or anything. I moved the throws outside of the switch afterwards anyway, because in retrospect it’s sorta gross.

It’s just surprising, and I wonder whether it’s legitimately a subtle bug.

Please have a nice day.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:20 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Aug 10, 2017

@ljharb @StoneCypher 👍, I’ll request reviews on my pull request with the current behavior.

2reactions
platinumazurecommented, Aug 6, 2017

I’ll work on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do unreachable statements method not result in a ...
Unreachable statements don't result in compilation errors in Kotlin, because it's a language design decision.
Read more >
Warning: unreachable code after return statement - JavaScript
When an expression exists after a valid return statement, a warning is given to indicate that the code after the return statement is...
Read more >
11217 – is double "; " on a return statement an error? - Bugs - Eclipse
The difference is that this is not an empty statement. So we have a generic message to report unreachable code and as long...
Read more >
no-unreachable - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
46476 – Missing Warning about unreachable code after return
Reported : 2010-11-14 16:55 UTC by Paolo Carlini ... error: statement is not reachable [-Werror] 354 | __builtin_unreachable ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found