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.

`prefer-destructuring` flags a property assignment

See original GitHub issue

_Edit: read this comment instead https://github.com/eslint/eslint/issues/11584#issuecomment-479892994_

Tell us about your environment

  • ESLint Version: 5.16
  • Node Version: any, happens on repl
  • npm Version: any, happens on repl

What parser (default, Babel-ESLint, etc.) are you using?

default

Please show your full configuration:

Configuration
{
    "parserOptions": {
        "ecmaVersion": 9,
        "sourceType": "script",
        "ecmaFeatures": {}
    },
    "rules": {
        "prefer-destructuring": 2
    },
    "env": {}
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

const arr = ['value'];

exports.value = arr[0];

https://eslint.org/demo/#eyJ0ZXh0IjoiY29uc3QgYXJyID0gWyd2YWx1ZSddO1xuXG5leHBvcnRzLnZhbHVlID0gYXJyWzBdOyIsIm9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hVmVyc2lvbiI6OSwic291cmNlVHlwZSI6InNjcmlwdCIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6eyJwcmVmZXItZGVzdHJ1Y3R1cmluZyI6Mn0sImVudiI6e319fQ==

What did you expect to happen?

No prefer-destructuring error should appear

What actually happened? Please include the actual, raw output from ESLint.

Use array destructuring

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Apr 5, 2019

@bfred-it Thanks for your response. I would say in this case, there is no bug in the rule.

Please feel free to open an enhancement request if you think the rule could be improved.

Closing as ESLint is working as intended here.

1reaction
platinumazurecommented, Apr 4, 2019

Reopening as this is, at very least, not a duplicate.

I did look on MDN and see nothing about destructured assignment into an object property. I don’t know enough about ES2015 to say if this is definitely a bug, but I can’t rule it out at this point.

Read more comments on GitHub >

github_iconTop Results From Across the Web

prefer-destructuring - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
What to do when ESLint rule "prefer-destructuring" makes ...
Here is a link to an Issue about that topic prefer-destructuring flags a property assignment #11584 · Share. Share a link to this...
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 objects, ...
Read more >
JavaScript object destructuring usages you must know
The mechanism is called Destructuring (also known as destructuring assignment). It is more of a new syntax added to the language than a...
Read more >
Destructuring Assignment In JavaScript
The destructuring assignment is a unique syntax that helps “to unpack” objects or arrays into a group of variables. Destructuring can also operate ......
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