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: Add ignoreDestructing option to camelcase rule (refs #9807) #10373

Merged
merged 1 commit into from
Jun 9, 2018

Conversation

alunny
Copy link
Contributor

@alunny alunny commented May 18, 2018

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

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

What rule do you want to change?
The camelcase rule.

Does this change cause the rule to produce more or fewer warnings?
Fewer.

How will the change be implemented? (New option, new default behavior, etc.)?
A new option:

"camelcase": [ "error", { "ignoreDestructuring": false }]
"camelcase": [ "error", { "ignoreDestructuring": true }]

Please provide some example code that this change will affect:

const { foo_bar } = baz;

What does the rule currently do for this code?
The rule currently always fails for these expressions (with or without the properties: "never" config option set).

What will the rule do after it's changed?
If the "ignoreDestructuring": true option is set, the line of code above should pass the rule (while the rule should still be enforced for other identifiers in the source).

What changes did you make? (Give an overview)
The changes are in lib/rules/camelcase.js

Is there anything you'd like reviewers to focus on?
There are a couple of edge cases I mentioned on #9807, both of which are errors when ignore_destructuring: true is set in this change:

Creating a new identifier from a destructured assignment

const { category_id: category_alias } = query;

Creating a non-camelcased identifier for rest props:

const { category_id, ...other_props } = query;

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label May 18, 2018

### always
### Defaults (properties: "always", "ignoreDestructuring": false)
Copy link
Member

Choose a reason for hiding this comment

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

Should the docs about different options be separated into different sections?

Copy link
Member

Choose a reason for hiding this comment

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

I agree with this. Let's have sections for properties and ignoreDestructuring options separately, and create subsections for the always/never and true/false cases (respectively) for each.

@platinumazure
Copy link
Member

Hi @alunny, thanks for contributing!

I don't have time to do a full review right now-- apologies-- but I do have two things that will need to change, so it's up to you if you want to fix them now or wait for a full review.

Thanks again for the contribution, hopefully we can get this reviewed and (assuming all goes well) merged soon!

@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels May 20, 2018
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.

Hi @alunny, this generally looks good, just a few minor things.

Besides everything I've identified inline: Could we also add examples in documentation that are incorrect for ignoreDestructuring: true (i.e., the corner cases around renaming to snake case or creating a snake case rest property)?

Thanks for contributing, really looking forward to getting this in.


### always
### Defaults (properties: "always", "ignoreDestructuring": false)
Copy link
Member

Choose a reason for hiding this comment

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

I agree with this. Let's have sections for properties and ignoreDestructuring options separately, and create subsections for the always/never and true/false cases (respectively) for each.

return false;
}

return node.parent.type === "ObjectPattern" || isInsideObjectPattern(node.parent);
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 strongly mind, but it would be nice to use iteration instead of recursion here.

@@ -292,12 +302,36 @@ ruleTester.run("camelcase", rule, {
]
},
{
code: "var { category_id: category_id } = query;",
code: "var { category_id: category_alias } = query;",
Copy link
Member

Choose a reason for hiding this comment

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

Should we have a test for the non-shorthand non-renaming case as well, to show that it should be valid? (I think it should be valid, since object-shorthand could report the redundancy of the property key/value name.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me.

@leipert
Copy link

leipert commented May 28, 2018

@alunny Are you working on this? This is a real pain-point for us, which this update would fix! I could also do the adjustments @platinumazure wanted you to make...

edit: thank you for working on this!

@platinumazure
Copy link
Member

Friendly ping @alunny, are you still working on this? (If not, totally okay!)

If you're busy, would you be okay with someone pushing changes to your branch to help finish this off?

Thanks for all your work so far on this!

@alunny
Copy link
Contributor Author

alunny commented Jun 7, 2018

My bad @platinumazure and @leipert - was a bit busy these last few weeks.

I've blocked out some time today so should be able to push some changes.

@alunny alunny force-pushed the issue9807/camelCase_destructuring branch from 19763c0 to 3ecd3e4 Compare June 7, 2018 22:13
if (node.parent.shorthand && node.parent.value.left && isUnderscored(name)) {

report(node);
}

const assignmentKeyEqualsValue = node.parent.key.name === node.parent.value.name;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hard to see in the GitHub ui since I clobbered the old commit, but in the previous rev this was:
const assignmentKeyEqualsValue = node.parent.key === node.parent.value;
which failed the {category_id: category_id} = query test

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 for contributing!

Left one suggestion in the docs, but this is not a blocker. (And great job with reorganizing the sections!)

var { category_id: category_id } = query;
```

Examples of **incorrect** code for this rule with the `{ "ignoreDestructuring": true }` 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 would love to see this moved to being first in the section, but that's not a blocker for merging this. (Other rules tend to do incorrect than correct in most sections, but this is probably okay as is.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, will push that.

@alunny alunny force-pushed the issue9807/camelCase_destructuring branch from 3ecd3e4 to 99f2042 Compare June 7, 2018 22:42
@platinumazure platinumazure changed the title New: Add ignoreDestructing option to camelcase rule (refs #9807) Update: Add ignoreDestructing option to camelcase rule (refs #9807) Jun 9, 2018
@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 Jun 9, 2018
@kaicataldo kaicataldo merged commit abf400d into eslint:master Jun 9, 2018
@kaicataldo
Copy link
Member

Thanks for contributing to ESLint!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Dec 8, 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 Dec 8, 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 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

5 participants