-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Update: Add ignoreDestructing option to camelcase rule (refs #9807) #10373
Conversation
docs/rules/camelcase.md
Outdated
|
||
### always | ||
### Defaults (properties: "always", "ignoreDestructuring": false) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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! |
There was a problem hiding this 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.
docs/rules/camelcase.md
Outdated
|
||
### always | ||
### Defaults (properties: "always", "ignoreDestructuring": false) |
There was a problem hiding this comment.
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.
lib/rules/camelcase.js
Outdated
return false; | ||
} | ||
|
||
return node.parent.type === "ObjectPattern" || isInsideObjectPattern(node.parent); |
There was a problem hiding this comment.
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;", |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.
@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! |
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! |
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. |
19763c0
to
3ecd3e4
Compare
if (node.parent.shorthand && node.parent.value.left && isUnderscored(name)) { | ||
|
||
report(node); | ||
} | ||
|
||
const assignmentKeyEqualsValue = node.parent.key.name === node.parent.value.name; |
There was a problem hiding this comment.
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
There was a problem hiding this 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!)
docs/rules/camelcase.md
Outdated
var { category_id: category_id } = query; | ||
``` | ||
|
||
Examples of **incorrect** code for this rule with the `{ "ignoreDestructuring": true }` option: |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
3ecd3e4
to
99f2042
Compare
Thanks for contributing to ESLint! |
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:
Please provide some example code that this change will affect:
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
Creating a non-camelcased identifier for rest props: