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 · Fixed by #11688
Closed

no-useless-return removes return statements in unreachable code #11647

benjie opened this issue Apr 23, 2019 · 0 comments · Fixed by #11688
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@benjie
Copy link

benjie 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 ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Apr 23, 2019
@aladdin-add aladdin-add added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Apr 23, 2019
@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels May 4, 2019
@mysticatea mysticatea self-assigned this May 4, 2019
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Nov 8, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Nov 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants