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: object-shorthand's consistent-as-needed option (issue #7214) #7215

Merged
merged 4 commits into from Sep 30, 2016

Conversation

naomiajacobs
Copy link
Contributor

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 PR fixes issue #7214.

Please check each item to ensure your pull request is ready:

  • I've read the pull request guide
  • I've included tests for my change
  • I've updated documentation for my change (if appropriate)

What changes did you make? (Give an overview)

object-shorthand's consistent-as-needed rule was failing when keys were either numbers or quoted strings. We (@ahuth and I) fixed this by changing the conditions under which an object is determined to have redundant properties.

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

@mention-bot
Copy link

@naomiajacobs, thanks for your PR! By analyzing the annotation information on this pull request, we identified @martijndeh, @vitorbal and @NickHeiner to be potential reviewers

@eslintbot
Copy link

LGTM

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.

Thank you for contributions!
The fix seems to introduce new bug. Could you fix it?

@@ -156,7 +156,7 @@ module.exports = {
property.value && property.value.id && property.value.id.name === property.key.name ||

// A property
property.value && property.value.name === property.key.name
property.value && (property.value.name || property.value.value) === (property.key.name || property.key.value)
Copy link
Member

Choose a reason for hiding this comment

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

This comparison seems still wrong about computed properties and string literals.
Could you add tests such below?

  • ({foo: "foo"})
  • ({"❤": "❤"})
  • ({[foo]: foo})
  • ({[foo]: "foo"})

I guess isRedudant function should be:

const astUtils = require("../ast-utils");

function isRedudant(property) {
    const value = property.value;

    if (value.type === "FunctionExpression") {
        return !value.id; // Only anonymous should be shorthand method.
    }
    if (value.type === "Identifier") {
        return astUtils.getStaticPropertyName(property) === value.name;
    }

    return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mysticatea I will look into this - thanks for the feedback!

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@naomiajacobs
Copy link
Contributor Author

@mysticatea the requested changes have been added! However, I still have the CLA:error tag. I went and signed the CLA and pushed an empty commit to re-trigger the check, but it doesn't seem to have worked. Do you know how I can fix this? Thanks!

@mysticatea
Copy link
Member

mysticatea commented Sep 26, 2016

@naomiajacobs Thank you! The 1st commit and the 2nd commit seem to have different author info. Could you sign CLA for both author info?

http://contribute.jquery.org/CLA/status/?owner=eslint&repo=eslint&sha=606074168b5e913195747d220613972aa668b2e1

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 but would like someone else to verify.

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 in general, but there's a typo in here from before this change which we might as well fix.

@@ -150,14 +155,16 @@ module.exports = {
* @private
**/
function isRedudant(property) {
Copy link
Member

Choose a reason for hiding this comment

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

Should be isRedundant (might as well fix this while we're in here).

@vitorbal vitorbal added the bug ESLint is working incorrectly label Sep 26, 2016
@eslintbot
Copy link

LGTM

@naomiajacobs
Copy link
Contributor Author

@vitorbal @platinumazure the typo was fixed - is that the bug the label is referring to? If it's fixed now, what's the process for getting it merged in? Let me know if I can help. Thanks!

@platinumazure
Copy link
Member

@naomiajacobs Nah, we use "bug" to indicate that this is a bug issue/PR, rather than an enhancement. @vitorbal Please confirm or clarify, thanks

@vitorbal
Copy link
Member

That's correct, I was just marking this accordingly with the corresponding issue! Sorry for any confusion.

@naomiajacobs
Copy link
Contributor Author

@vitorbal gotcha, makes sense. Do you know when this might get merged in? I ask because we'd love to be able to use this rule in our code base! Thanks!

@platinumazure
Copy link
Member

platinumazure commented Sep 26, 2016

@naomiajacobs The latest this will be released is next Friday, 7 October. Our release schedule is every 2 weeks on Friday (or occasionally Saturday). So hopefully not later than that, assuming we don't let this sit for too long.

I don't know if there's any chance this could make it into a patch release sooner than that. We usually only do patch releases for really urgent things, such as regressions from the last release. So normally we would want this fixed in a normal release. But we'll see what happens.

@ahuth
Copy link

ahuth commented Sep 27, 2016

Nice job, @naomiajacobs, and thanks for working on this!

@naomiajacobs
Copy link
Contributor Author

@platinumazure thanks for the clarification!

@ahuth no problem :)

@nzakas nzakas merged commit 2fee8ad into eslint:master Sep 30, 2016
@naomiajacobs naomiajacobs deleted the fix-issue7214 branch September 30, 2016 18:16
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 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 Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants