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

curly: multi-or-nest should allow lexical declarations to have braces for single-statement blocks #11663

Closed
cherryblossom000 opened this issue Apr 29, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@cherryblossom000
Copy link

commented Apr 29, 2019

What rule do you want to change?
curly

Does this change cause the rule to produce more or fewer warnings?
fewer

How will the change be implemented? (New option, new default behavior, etc.)?
The multi-or-nest option should allow single-statement blocks with lexical declarations (let, const, function, and class) to have braces.

Please provide some example code that this change will affect:

if (foo) {
  const bar = 'baz';
}

What does the rule currently do for this code?
ESLint outputs the error "Unnecessary { after 'if' condition." if the multi-or-nest option is set. After this is fixed:

if (foo)
  const bar = 'baz';

it outputs the error "Parsing error: Unexpected token const" as lexical declarations need to be in a block.

What will the rule do after it's changed?
The multi-or-nest option would allow the code and not output any errors.

Are you willing to submit a pull request to implement this change?
I would if I could, but I'm not great at coding.

@platinumazure

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

Hi @cherryblossom000, thanks for the issue.

This seems like a bug-- we shouldn't report in that case if "fixing" the issue will result in a parse error.

To be clear, does ESLint's autofix feature actually apply a fix in this case?

@cherryblossom000

This comment has been minimized.

Copy link
Author

commented Apr 30, 2019

Yes, sorry for not clarifying earlier. ESLint autofixed it to become

if (foo)
  const bar = 'baz';

which produces a parsing error.

Even if the autofix problem is solved, wouldn't the multi-or-nest option produce an error for

if (foo) {
  const bar = 'baz';
}

because single-statement blocks can't have braces?

@platinumazure

This comment has been minimized.

Copy link
Member

commented Apr 30, 2019

Even if the autofix problem is solved, wouldn't the multi-or-nest option produce an error[...]

I think it would and that's why I think we shouldn't report an error there at all. As a bonus, if no error is reported, then no fixing will take place.

@platinumazure platinumazure changed the title curly: multi-or-nest should allow lexical decelerations to have braces for single-statement blocks curly: multi-or-nest should allow lexical declarations to have braces for single-statement blocks May 3, 2019

@platinumazure

This comment has been minimized.

Copy link
Member

commented May 3, 2019

Marking as "accepted" as I can recreate the issue in our online demo.

@platinumazure platinumazure added accepted and removed evaluating labels May 3, 2019

@BRKurek

This comment has been minimized.

Copy link
Contributor

commented May 4, 2019

Working on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.