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: prefer-destructuring says "Use destructuring" on "super" (#9625) #9626

Merged
merged 3 commits into from
Nov 19, 2017
Merged

Fix: prefer-destructuring says "Use destructuring" on "super" (#9625) #9626

merged 3 commits into from
Nov 19, 2017

Conversation

gjbkz
Copy link
Contributor

@gjbkz gjbkz commented Nov 15, 2017

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

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

This fixes #9625

What changes did you make? (Give an overview)

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

@gjbkz gjbkz changed the title 9625 fix prefer destructuring Fix: prefer-destructuring says "Use destructuring" on "super" (#9625) Nov 15, 2017
@aladdin-add aladdin-add added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules labels Nov 15, 2017
@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 15, 2017
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.

Looks good to me. Thanks for contributing!

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.

Could we add a test case for a nested super call?

class Foo extends Bar { static get foo() {var bar = super.foo.bar } }

Asking because I'm not 100% sure that line 148 of the rule will catch that, since you'd have to check rightNode.object.object in that case. In fact, you might need a recursive check, if I'm not mistaken about this. Even if does work, it'd be good to have a test so we can protect against a regression in that case.

@not-an-aardvark
Copy link
Member

I agree that it would be nice to have a test. Having said that, I think the implementation in this PR already handles that case correctly by reporting an error because const {bar} = super.foo is legal.

Conceptually, the rule should report an error only when node.object is a valid expression on its own. So I think checking the type of node.object is correct here, regardless of whether node.object is another MemberExpression or contains super.

@platinumazure
Copy link
Member

Thanks for the explanation. You are right that I had misunderstood conceptually how this rule is supposed to work and thought that const { bar } = super.foo; was invalid syntax, when in reality it is valid. Thanks!

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!

@gjbkz
Copy link
Contributor Author

gjbkz commented Nov 16, 2017

Thank you for the reviewing. I added another test to check what @platinumazure pointed out.
I found that I can omit get and the simplest test reproducing #9625 is

class Foo extends Bar {
  foo() {
    var foo = super.foo;
  }
}

@not-an-aardvark not-an-aardvark merged commit a015234 into eslint:master Nov 19, 2017
@not-an-aardvark
Copy link
Member

Thanks for contributing!

@gjbkz gjbkz deleted the 9625-fix-prefer-destructuring branch November 20, 2017 00:59
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators May 19, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label May 19, 2018
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.

prefer-destructuring says "Use destructuring" on "super"
5 participants