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-useless-return` removes return statements in unreachable code #11647

Closed
benjie opened this issue Apr 23, 2019 · 0 comments

Comments

Projects
None yet
3 participants
@benjie
Copy link

commented Apr 23, 2019

Tell us about your environment

  • ESLint Version: v5.16.0 (via the ESLint.org/demo website)
  • Node Version: ESLint.org/demo website
  • npm Version: ESLint.org/demo website

What parser (default, Babel-ESLint, etc.) are you using?

ESLint.org/demo default

Please show your full configuration:

This eslint.org/demo configuration (configured with just the no-useless-return rule)

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

function foo(arg) {
  throw new Error("Debugging...");

  if (!arg) {
    return; // < This return incorrectly gets removed by auto-fix
  }

  console.log(arg);
}

Using eslint.org/demo link above

I added a throw statement to the top of my function to aid debugging, and the critical return statement from later in the code was dropped which I only discovered after removing the throw statement and strange errors occurring.

What did you expect to happen?

return; statement should be flagged in unreachable code if and only if it would be flagged in equivalent reachable code. (At least that's how I read the comment in the source code.)

If we were to remove the throw line, the return; statement would not be flagged; therefore it should not be flagged with the throw statement present.

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

5:5 Unnecessary return statement. and fixed code removes the return statement. (See eslint.org/demo link)

Are you willing to submit a pull request to fix this bug?

This is currently beyond my ESLint skillset.

@benjie benjie added bug triage labels Apr 23, 2019

@aladdin-add aladdin-add added evaluating rule and removed triage labels Apr 23, 2019

@mysticatea mysticatea added accepted and removed evaluating labels May 4, 2019

@mysticatea mysticatea self-assigned this May 4, 2019

mysticatea added a commit that referenced this issue May 8, 2019

mysticatea added a commit that referenced this issue May 8, 2019

not-an-aardvark added a commit that referenced this issue May 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.