cannot assign variables from destructure with camelCase rule `ignoreDestructure` set to true
See original GitHub issueI 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:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top 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 >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
@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.
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.