rule change proposal: destructured properties to be non-camelcased with camelcase rule
See original GitHub issueHi eslint team! I’ve filled out the questions from https://github.com/eslint/eslint/blob/master/templates/rule-change-proposal.md but please let me know if you’d like any more detail here. I’m happy to work on a PR myself if this sounds like a sensible approach.
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).
See related discussion in #3185 and #9715
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).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:9 (6 by maintainers)
Top Results From Across the Web
camelcase - ESLint - Pluggable JavaScript Linter
This rule focuses on using the camelcase approach. If your style guide calls for camelCasing your variable names, then this rule is for...
Read more >Disable check of camel case rule in eslint - Stack Overflow
I am trying to disable them and address them one at a time. The code below shows that I can disable them all...
Read more >Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >ESLint: prefer-destructuring - Styleguide JavaScript
Use object destructuring when accessing and using multiple properties of an object. Destructuring avoids the usage of ... Incorrect code for this rule:...
Read more >JavaScript Object Destructuring, Spread Syntax, and the Rest ...
There are hardly any JavaScript applications that do not deal with objects. Web developers commonly extract values from an object property to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Mostly, I think
const { foo_bar: fooBar } = baz
is harder to read and noisier.One case that also comes up a lot in the app I work on is somebody picking off properties from object (perhaps from a remote api) in order to use rest destructuring - I don’t think this code:
is improved by:
or
It’s also useful for object shorthand, when you’re taking some remote data that has snake cased property names and using that for a subsequent request - for example:
without modifying the rule this becomes:
which is just more typing, and no more readable or maintainable.
I’m a bit confused by the proposed option values. What does “always” or “never” mean: allow always/never, or warn always/never? I would much prefer something like
ignoreDestructuring: true
(or false) to make it more clear exactly what the configuration means.