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

Conversation

@mdjermanovic
Copy link
Member

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 eslint bot added the triage label Jul 3, 2019

@platinumazure platinumazure self-requested a review Jul 3, 2019

@platinumazure platinumazure added accepted bug rule and removed triage labels Jul 3, 2019

@not-an-aardvark
Copy link
Member

left a comment

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
@platinumazure
Copy link
Member

left a comment

LGTM, thanks!

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

@mdjermanovic

This comment has been minimized.

Copy link
Member Author

commented Jul 11, 2019

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

This comment has been minimized.

Copy link
Member

commented Jul 11, 2019

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

This comment has been minimized.

Copy link
Member Author

commented Jul 12, 2019

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.

@platinumazure
Copy link
Member

left a comment

LGTM, thanks!

@platinumazure platinumazure requested a review from mysticatea Jul 21, 2019

@mysticatea
Copy link
Member

left a comment

LGTM, thank you!

@mysticatea mysticatea merged commit bfcf8b2 into eslint:master Jul 21, 2019

9 checks passed

commit-message PR title follows commit message guidelines
Details
continuous-integration Build #20190711.4 succeeded
Details
continuous-integration (Test on Node.js 10 (Linux)) Test on Node.js 10 (Linux) succeeded
Details
continuous-integration (Test on Node.js 12 (Linux)) Test on Node.js 12 (Linux) succeeded
Details
continuous-integration (Test on Node.js 12 (Windows)) Test on Node.js 12 (Windows) succeeded
Details
continuous-integration (Test on Node.js 12 (macOS)) Test on Node.js 12 (macOS) succeeded
Details
continuous-integration (Test on Node.js 8 (Linux)) Test on Node.js 8 (Linux) succeeded
Details
licence/cla Contributor License Agreement is signed.
Details
release-monitor No patch release is pending
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.