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
Update: add fixer for no-unused-labels #7841
Conversation
@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vitorbal, @mysticatea and @BYK to be potential reviewers. |
LGTM |
Hmm. I'm slightly uncomfortable about adding a fixer here in case the label is only "unused" due to a typo in a named break/continue statement. @not-an-aardvark Any thoughts? |
I'm not too concerned about this, because using an undeclared label in break/continue will result in a syntax error. For example, the following is invalid syntax: foobar: while (true) {
break fooabr; // oops, this was a typo
} |
I have a concern, some editors have the feature it executes |
Hmm, that can indeed be quite annoying... |
I'm worried about the editor integrations as well. |
Personally, I don't think we should worry about editor integrations too much -- we already have a lot of fixers that could get in the way if they are applied while the user is writing the code. For example: /* eslint curly: ["error", "multi"] */
if (foo) {
bar();
// ... planning to put more statements here
} If I'm in the middle of filling in the Another example: /* eslint no-useless-return: error */
function foo() {
if (bar) {
return;
}
// ...planning to put more statements here
} If the code is autofixed on save before the statements after the In general, rules will often "incorrectly" report things when the code that they're acting on is partially unwritten. By enabling autofix-on-save, I think users are opting into this behavior. |
TSC Summary: This PR proposes adding a fixer for TSC Question: Should we add a fixer for this rule? |
Related: #7955 We already have several rules which might modify unfinished codes unintentionally; curly, no-extra-parens, no-extra-bind, no-useless-return, no-lonely-if, no-trailing-spaces, prefer-arrow-callback, prefer-const, ... I agreed that people should opt-out those rules when they use autofix on save. |
As per the TSC discussion, this is now accepted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As always, I think we should consider comments.
A: // some comments...
while (a) {
// do something.
}
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
What is the purpose of this pull request? (put an "X" next to item)
[x] Add autofixing to a rule
What changes did you make? (Give an overview)
This adds a fixer for
no-unused-labels
.Is there anything you'd like reviewers to focus on?
Nothing in particular.