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-debugger autofixer produced invalid syntax #8806

Merged
merged 1 commit into from Jun 27, 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: master
  • Node Version: 8.1.2
  • npm Version: 5.0.3

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

default

Please show your full configuration:

rules:
  no-debugger: error

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

if (foo) debugger

What did you expect to happen?

I expected the code to be valid after running eslint --fix.

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

The code was fixed to if (foo), which is invalid syntax.

What changes did you make? (Give an overview)

This updates the no-debugger autofixer to not remove debugger statements that are in a position where a statement is required (e.g. the direct descendent of an if statement).

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

Nothing in particular

This updates the `no-debugger` autofixer to not remove `debugger` statements that are in a position where a statement is required (e.g. the direct descendent of an `if` statement).
@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 Jun 26, 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 @nzakas, @vitorbal and @btmills to be potential reviewers.

@eslintbot
Copy link

LGTM

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@aladdin-add
Copy link
Member

it may be somewhat inconsistent.
can we fix if (foo) debugger to if (foo) ;?

@not-an-aardvark
Copy link
Member Author

In general, we try to make it so that rules don't autofix problems unless they're sure about what the user was trying to do. In this case, I don't think we can be sure.

For example, I think the most likely case where this issue would occur would be if I was trying to isolate a special case in the debugger:

doSomething(foo);
// doAnotherThing isn't working when foo.bar is true, so I'm debugging it there
if (foo.bar) debugger;
doAnotherThing(foo);

But in that case, when I'm done debugging I would actually to remove the if statement entirely:

doSomething(foo);
doAnotherThing(foo);

I don't think it's safe to assume that the user would want an empty if (foo.bar); statement to remain in their code, so it seems best to not fix this case.

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 this pull request may close these issues.

None yet

6 participants