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

Update: add fixer for no-unused-labels #7841

Merged
merged 2 commits into from Feb 7, 2017

Conversation

not-an-aardvark
Copy link
Member

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.

foo: while (true) {}

// gets fixed to:

while (true) {}

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

Nothing in particular.

@not-an-aardvark not-an-aardvark added enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules labels Jan 2, 2017
@not-an-aardvark not-an-aardvark self-assigned this Jan 2, 2017
@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 @BYK to be potential reviewers.

@eslintbot
Copy link

LGTM

@platinumazure
Copy link
Member

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?

@not-an-aardvark
Copy link
Member Author

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
}

@mysticatea
Copy link
Member

I have a concern, some editors have the feature it executes --fix on save files. If someone which has the habit of saving files frequently, they might lose labels from unfinished code on save.

@vitorbal
Copy link
Member

vitorbal commented Jan 5, 2017

I have a concern, some editors have the feature it executes --fix on save files. If someone which has the habit of saving files frequently, they might lose labels from unfinished code on save.

Hmm, that can indeed be quite annoying...

@platinumazure
Copy link
Member

I'm worried about the editor integrations as well.

@not-an-aardvark
Copy link
Member Author

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 if statement, I want to keep the curly braces, because I plan to put more lines in the block. However, if I autofix on save, ESLint will remove the block.

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 if statement are added, the return statement will be removed.


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.

@not-an-aardvark not-an-aardvark added the tsc agenda This issue will be discussed by ESLint's TSC at the next meeting label Jan 19, 2017
@not-an-aardvark
Copy link
Member Author

TSC Summary: This PR proposes adding a fixer for no-unused-labels. The fix is safe and works well with other rules such as no-extra-label, but a few people have expressed concern that the fixer will get in the way if it's run on unfinished code, e.g. in an editor integration.

TSC Question: Should we add a fixer for this rule?

@mysticatea
Copy link
Member

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.

@kaicataldo kaicataldo 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 tsc agenda This issue will be discussed by ESLint's TSC at the next meeting labels Feb 2, 2017
@kaicataldo
Copy link
Member

As per the TSC discussion, this is now accepted.

Copy link
Member

@mysticatea mysticatea left a 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.
}

@eslintbot
Copy link

LGTM

Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants