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: dot-notation autofix produces errors on parenthesized computed keys #8330
Conversation
@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vitorbal, @gyandeeps and @goatslacker to be potential reviewers. |
LGTM |
This commit updates the dot-notation autofixer logic to ensure that parenthesized computed keys are handled correctly. Previously, the rule didn't account for the possibility that a computed key might be parenthesized, so it ended up using the parens instead of the square brackets for the fix range.
314e035
to
db8735c
Compare
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.
Just one question but LGTM.
|
||
if (textBeforeProperty.trim() || textAfterProperty.trim()) { | ||
if (sourceCode.getFirstTokenBetween(leftBracket, rightBracket, { includeComments: true, filter: astUtils.isCommentToken })) { |
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.
Is includeComments: true
necessary here?
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.
Yes, the idea is to find comments. (If includeComments: true
wasn't used, then the iterator would only run on the non-comment tokens, and the filter would return false for all of them.)
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.
Oh hell, I misread the filter parameter there. Yes, obviously we need that parameter. Thanks for clarifying.
What is the purpose of this pull request? (put an "X" next to item)
[x] Bug fix
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
Please show your full configuration:
What did you do? Please include the actual source code causing the issue.
What did you expect to happen?
I expected eslint to autofix the code to
What actually happened? Please include the actual, raw output from ESLint.
eslint autofixed the code to invalid syntax:
What changes did you make? (Give an overview)
This commit updates the dot-notation autofixer logic to ensure that parenthesized computed keys are handled correctly. Previously, the rule didn't account for the possibility that a computed key might be parenthesized, so it ended up using the parens instead of the square brackets for the fix range.
Is there anything you'd like reviewers to focus on?
Nothing in particular