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.

cannot assign variables from destructure with camelCase rule `ignoreDestructure` set to true

See original GitHub issue

I am reopening #11226 as suggested at the end of that issue to bring this to light again. The problem can be seen here. Basically though you cannot assign any variable that is not camel cased from a destructured statement:

  /* eslint camelcase: [error, { ignoreDestructuring: true, properties: "never" }] */

  const { field_formatted_text } = someObject;

  const underscoreOnObjectProperty = {
    abc: field_formatted_text . // this is fine
  };
  
  // throws: Identifier 'field_formatted_text' is not camel case
  const myVar = field_formatted_text + 'abc';

There is an obvious solution to just rename the variable when it’s destructured:

  const { field_formatted_test: fieldFormattedText } = someObject;

However, this is annoying to have to do and you may also lose semantic meaning from the different cases (i.e. variables returned from an api).

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kaicataldocommented, Nov 10, 2019

@DMR-coding The options for this rule currently only toggles the behavior for when new variables are created. This means that other references to the variable aren’t affected, which leads to the somewhat confusing behavior of the rule not warning on, say, destructured assignments, but will then warn when the variable is actually used.

1reaction
mdjermanoviccommented, Oct 28, 2019

I believe it would be better to open a ‘Rule change request’ issue with a backward-compatible enhancement proposal.

Destructuring creates new variables that might be used many times in the rest of the code. A change to allow underscores in this case (instead of enforcing the user to ‘rename variables’ in the destructuring pattern) without opt-in might be undesirable for some users.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why i cannot assign values to destructured object variables?
You can just reassign the values to your generalCurrencyInfo object, so no need to destructure: // reassign values if (DATA.
Read more >
prefer-destructuring - ESLint - Pluggable JavaScript Linter
By default, array and object are set to true for both VariableDeclarator and ... This rule therefore guesses the assignment type by checking...
Read more >
How to overwrite the default typescript-eslint/naming- ...
There is a specific rule I'm trying to add to the default typescript-eslint/naming-convention rule I added the following to my eslintrc file ...
Read more >
Destructuring in JavaScript: the not so good parts
Generally speaking, I would say everybody loves the destructuring assignment , and for good reasons. Next, I list some of the amazing…
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 >

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