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: dot-location errors with parenthesized objects (fixes #11868) #11933

Merged
merged 3 commits into from Jul 21, 2019
Merged

Fix: dot-location errors with parenthesized objects (fixes #11868) #11933

merged 3 commits into from Jul 21, 2019

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Jul 3, 2019

What is the purpose of this pull request? (put an "X" next to item)

[X] Bug fix #11868

What changes did you make? (Give an overview)

Fixed dot-location rule ("object" option) because it produces syntax errors with parenthesized objects.

Parentheses around MemberExpression.object node are now treated as a part of the 'object'.

For example, the following was a false positive:

( 
  object
).
property

and the auto-fix produced syntax error:

( 
  object.
)
property

With this PR, the example above does not have a warning.

Also, with this PR auto-fix works correctly for similar cases that do have warnings. For example, this:

( 
  object
)
.property

will be fixed to:

( 
  object
).
property

I've also added several test cases unrelated to this issue.

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

  • If the first token before the MemberExpression.property is not a dot token, the rule will ignore that node. I believe there is no need to support this case (post).
  • The rule doesn't check if the dot is right after the object (or parens now) / right before the property. This is valid syntax: a . b and produces no dot-location warnings. Perhaps there could be an additional option to 'attach' the dot, I could open an issue if this wasn't already discussed.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jul 3, 2019
@platinumazure platinumazure self-requested a review July 3, 2019 00:33
@platinumazure platinumazure 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 and removed triage An ESLint team member will look at this issue soon labels Jul 3, 2019
Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! This looks good to me, I just have a minor question.

lib/rules/dot-location.js Outdated Show resolved Hide resolved
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!

I'm okay with leaving the if check in for now.

@mdjermanovic
Copy link
Member Author

I'll be away for two weeks from next Tuesday. If the isNotDotToken is a blocking issue I could remove that conditional now, to not wait that long. In any case, please don't close the PR if I'm not responding in next couple of weeks :)

@kaicataldo
Copy link
Member

My vote would be to remove it, but I also don’t want to hold up landing this. If you can remove it, that sounds good to me! Otherwise, I’d be fine with merging this and revisiting that. Thanks for working on this!

@mdjermanovic
Copy link
Member Author

It's removed now.

It looks like this conditional (in the form: if (dot.type === "Punctuator" && dot.value === ".") was indeed added to check computed properties in 45cda23 (PR #2506 which also fixed an unrelated or semi-related #2504).

I didn't remove isDotToken() and isNotDotToken() functions from ast_utils. They were added in the first commit, both are unused now but they have their own test cases and might be useful for something else in the future.

I've also added more test cases with computed properties.

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!

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!

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.

eslint --fix with dot-location breaks code
5 participants