question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rule change proposal: destructured properties to be non-camelcased with camelcase rule

See original GitHub issue

Hi 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:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
alunny-stripecommented, Jan 5, 2018

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:

const {some_property, some_other_one, ...rest} = remoteObject;
// do something with rest

is improved by:

const {some_property: someProperty, some_other_one: someOtherOne, ...rest} = remoteObject;
// do something with rest

or

/* eslint-disable camelcase */
const {some_property, some_other_one, ...rest} = remoteObject;
/* eslint-enable camelcase */
// do something with rest

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:

  getIframeURL() {
    const {title, some_other_param} = this.props;
    const queryParams = qs.stringify({
      title,
      some_other_param,
    });
    return `${IFRAME_URL}?${queryParams}`;
  }

without modifying the rule this becomes:

  getIframeURL() {
    const {title, some_other_param: someOtherParam} = this.props;
    const queryParams = qs.stringify({
      title,
      some_other_param: someOtherParam,
    });
    return `${IFRAME_URL}?${queryParams}`;
  }

which is just more typing, and no more readable or maintainable.

4reactions
platinumazurecommented, May 2, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found