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

Update: update handling of destructuring in camelcase (fixes #8511) #9468

Merged
merged 2 commits into from Dec 8, 2017

Conversation

erindepew
Copy link
Contributor

@erindepew erindepew commented Oct 17, 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:

What changes did you make? (Give an overview)
Fixes the bug reported in #8511 . I forked from #8529 and added a check for the right-side of the value assignment

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

@eslintbot
Copy link

LGTM

@jsf-clabot
Copy link

jsf-clabot commented Oct 17, 2017

CLA assistant check
All committers have signed the CLA.

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@kaicataldo kaicataldo 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 Oct 17, 2017
@kaicataldo
Copy link
Member

kaicataldo commented Oct 17, 2017

I'm 👍 for this change - definitely seems like something the rule should catch.

I understand why this is branched off of the other PR, since it touches the same code, but I think the squashed commits will cause some issues with merging. Do we want to just combine the two PRs like was originally suggested, since they touch the same part of the code?
Thanks for updating this!

@vitorbal @platinumazure @not-an-aardvark Are you okay with closing #8529 in favor of this PR?

@eslintbot
Copy link

LGTM

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! Do we want to include any of the new test cases in the documentation?

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

Do you mind updating the PR title following the guidelines outlined here? This is important for us because we generate our changelogs and calculate the semver version of the release based on the commit messages in the commit history. Thanks!

@kaicataldo kaicataldo 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 Oct 19, 2017
@kaicataldo
Copy link
Member

Marking as accepted since #8529 had already been accepted.

@gyandeeps gyandeeps changed the title 8511 default destructuring Fix: handle destructuring with defaults in camelcase rule (fixes #8511) Oct 19, 2017
Copy link
Member

@kaicataldo kaicataldo 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 changing the PR title!

Have one comment, but I'd also love to see a test around destructuring with renaming and default values. Example (taken from #8529 (comment)):

var { foo: bar_baz = 1 } = quz;

It might also be nice to include a test for when multiple values are being destructured, just to ensure that works correctly.

} else if (node.parent.type === "Property" || node.parent.type === "AssignmentPattern") {

if (node.parent.parent.type === "ObjectPattern") {
node.parent.parent.properties.forEach(property => {
Copy link
Member

Choose a reason for hiding this comment

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

This method should worry about a single Property node at a time. I don't think we need to loop through all the properties here, as this method will already be called on each Identifier. The current implementation will loop through all the destructured properties for each destructured assignment that exists, which seems like more work than the rule needs to do.

@kaicataldo
Copy link
Member

Requesting a review from @not-an-aardvark since you had concerns with the initial PR.

@not-an-aardvark
Copy link
Member

I've been pretty busy lately, so I'll try to review this if I get the chance, but don't let me be a blocker if others are satisfied with the PR.

@eslintbot
Copy link

LGTM

1 similar comment
@eslintbot
Copy link

LGTM

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

This LGTM, but I would like to briefly discuss if this actually belongs behind the properties configuration option. I wonder if this should actually be on by default (as a semver-minor bug fix, which it technically already currently is) or if we should put it behind a destructuring configuration option. @erindepew @eslint/eslint-team Thoughts?

Apologies for thinking of this so late in the process. Also don't want to hold this PR up over a long discussion, but since this is a change that creates more errors I'd like to not have to do it twice :)

@kaicataldo kaicataldo removed the request for review from not-an-aardvark October 23, 2017 21:52
@kaicataldo kaicataldo added the tsc agenda This issue will be discussed by ESLint's TSC at the next meeting label Oct 26, 2017
@kaicataldo
Copy link
Member

TSC Summary: I'm bringing this to the TSC because of the complicated history of this PR - given the number of iterations and changes that have happened since the issue was originally accepted, I figured it would be easier to have the TSC decide.

Some history: The original PR - that this now includes - was accepted as a bug fix, and during the course of the original PR author working on it, another separate (but related) bug was discovered. It sounds like there is consensus to fix this bug, however, I'm concerned about putting it behind the properties option, since it doesn't really have anything to do with properties.

TSC Question: Should this be accepted as it currently is (behind the properties option), actually be on by default (as a semver-minor bug fix, which it technically already currently is) or put behind a destructuring configuration option to make it non-breaking?

@kaicataldo kaicataldo removed the tsc agenda This issue will be discussed by ESLint's TSC at the next meeting label Oct 26, 2017
@erindepew erindepew changed the title Fix: handle destructuring with defaults in camelcase rule (fixes #8511) Update:: handle destructuring with defaults in camelcase rule (fixes #8511) Nov 13, 2017
@platinumazure platinumazure changed the title Update:: handle destructuring with defaults in camelcase rule (fixes #8511) Update: handle destructuring with defaults in camelcase rule (fixes #8511) Nov 13, 2017
@erindepew erindepew force-pushed the 8511-default-destructuring branch 2 times, most recently from fe35472 to 6b82e4a Compare November 13, 2017 22:29
return;
if (node.parent.parent && node.parent.parent.type === "ObjectPattern") {

if (node.parent.key === node && node.parent.value !== node) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be helpful to have a short comment that explains what this is checking.

return;
}

if (node.parent.value.right && node.parent.value.right.type === "Identifier" && isUnderscored(node.parent.value.right.name)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be helpful to have a short comment that explains what this is checking.

report(node);
}

if (node.parent.value.name && isUnderscored(node.parent.value.name)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be helpful to have a short comment that explains what this is checking.

// ...
};

function foo({ no_camelcased: my_default }) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this example would be clearer as something like:
function foo({ isCamelcased: no_camelcased }) {

@@ -60,6 +78,19 @@ var { category_id: category } = query;

### never


Examples of **incorrect** code for this rule with the default `{ "properties": "never" }` option:
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this or this change any more, since this behavior is the same as the cases listed above.

@@ -79,6 +79,20 @@ ruleTester.run("camelcase", rule, {
{
code: "import { no_camelcased as camelCased, anoterCamelCased } from \"external-module\";",
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: "const { no_camelcased = false } = bar;",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be failing?

parserOptions: { ecmaVersion: 6 }
},
{
code: "function foo({ no_camelcased = 'default value' }) {};",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be failing?

},
{
code: "const { no_camelcased = false } = bar;",
options: [{ properties: "never" }],
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need the properties any more in most of these valid tests. Maybe one with properties: "always" and one with properties: "never" at the end of the test suite to ensure they don't affect the outcome?

parserOptions: { ecmaVersion: 6 }
},
{
code: "function foo({ no_camelcased: camelCased }) {};",
Copy link
Member

Choose a reason for hiding this comment

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

I think we're missing some of the test cases outlined in the docs.

type: "Identifier"
},
{
message: "Identifier 'no_camelcased' is not in camel case.",
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be warning for the assignment of no_camelcased. In other words, I don't think we should be checking the right hand side of destructured assignments with default values since they're only being referenced and not defined. The rule should warn on the declaration (which it correctly does).

@kaicataldo
Copy link
Member

kaicataldo commented Dec 3, 2017

Looks like this has been updated.

@eslint/eslint-team Can we get some other eyes on this? This is a semver-minor bug fix (it will result in more errors being reported by default).

@kaicataldo kaicataldo added the enhancement This change enhances an existing feature of ESLint label Dec 3, 2017
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.

Just one question about a comment, otherwise looks good to me. Thanks for contributing!

return;
}

if (isUnderscored(name) && !ALLOWED_PARENT_TYPES.has(effectiveParent.type)) {
// check right hand side of assignment to prevent duplicate warnings
Copy link
Member

Choose a reason for hiding this comment

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

Should this say "Don't check right hand side of AssignmentExpression (etc.)"?

@erindepew
Copy link
Contributor Author

@platinumazure you're right, updated the comment! and thanks @kaicataldo for holding my hand through the process :)

Copy link
Member

@kaicataldo kaicataldo 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 for sticking with us on this one! I know it took a while with it being an inherited issue and the discussions that surrounded the implementation.

@kaicataldo kaicataldo changed the title Update: handle destructuring with defaults in camelcase rule (fixes #8511) Update: update handling of destructuring in camelcase (fixes #8511) Dec 8, 2017
@kaicataldo kaicataldo merged commit 256481b into eslint:master Dec 8, 2017
@kaicataldo
Copy link
Member

Thanks for contributing to ESLint!

@rodrigok
Copy link

Should it mark _id as wrong too?

Example:

const { _id, msg, rid } = this.props.actionMessage;
/home/circleci/repo/app/containers/MessageActions.js
  232:11  error  Identifier '_id' is not in camel case  camelcase

@kaicataldo
Copy link
Member

@rodrigok Can you make a new issue for this? These kinds of comments don't get much visibility. Thanks!

@rodrigok
Copy link

@kaicataldo Thanks, here is the issue #9709

@j-f1
Copy link
Contributor

j-f1 commented Dec 11, 2017

@rodrigok See #9700 for the issue reporting this, and #9701 for the PR fixing the problem.

@rodrigok
Copy link

@j-f1 Thanks, I'll reference and close my issue.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 7, 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 Jun 7, 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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants