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

Fix: no-extra-label autofix should not remove labels used elsewhere #7885

Merged
merged 1 commit into from Jan 9, 2017

Conversation

not-an-aardvark
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[x] Bug fix

Tell us about your environment

  • ESLint Version: 3.13.0
  • Node Version: 7.3.0
  • npm Version: 3.10.10

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

default

Please show your full configuration:

(none)

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

/* eslint no-extra-label: error */

A: while (true) {
  break A;
  while (true) {
    break A;
  }
}

What did you expect to happen?

I expected an error to be reported on line 2, and the code to be fixed to

/* eslint no-extra-label: error */

A: while (true) {
  break;
  while (true) {
    break A;
  }
}

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

An error was reported on line 2 as expected, but the code was fixed to

/* eslint no-extra-label: error */

while (true) {
  break;
  while (true) {
    break A;
  }
}

...which is a syntax error, because the A label no longer exists even though it's used elsewhere.

What changes did you make? (Give an overview)

This changes the behavior of the no-extra-label autofixer. Previously, the autofixer would behave like this:

A: while (true) {
  break A;
}

// gets fixed to

while (true) {
  break;
}

However, it now behaves like this:

A: while (true) {
  break A;
}

// gets fixed to

A: while (true) {
  break;
}

In other words, it now only fixes the break/continue statement that got reported, but doesn't touch the loop. In my opinion, this is a better fix, because the no-extra-label rule is only concerned about extra break/continue labels, not unused labels on loops. (The no-unused-labels rule can be used to enforce no missing loop labels, and it will be able to do this automatically when/if #7841 is merged.)

Is there anything you'd like reviewers to focus on?

It would be good to verify that this change is a good idea. My only concern is that there was some opposition to adding a fixer for no-unused-labels in #7841, so if that PR stalls or is rejected, people might have more unused labels in their code after autofixing.

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules labels Jan 7, 2017
@eslintbot
Copy link

LGTM

@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vitorbal, @mysticatea and @gyandeeps to be potential reviewers.

@vitorbal vitorbal added regression Something broke patch candidate This issue may necessitate a patch release in the next few days and removed regression Something broke labels Jan 9, 2017
@ilyavolodin ilyavolodin merged commit f90462e into master Jan 9, 2017
@not-an-aardvark not-an-aardvark deleted the no-extra-label-multi-use branch January 9, 2017 23:58
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
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 patch candidate This issue may necessitate a patch release in the next few days rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants