Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
What to do when ESLint rule "prefer-destructuring" makes no sense

In many cases the rule "prefer-destructuring" of ESLint is pretty weird. Consider the following example:

obj.someVar = myList[0];

The linter is warning me in both cases.

What's the expected behavior that the linter wants? I can use a temp var to save the value of the list item and later on do the rest of the logic, but I don't see any benefit in it. Any ideas what's the reason for that?

EDIT:

I can see the benefit of the rule in some situations, i.e:

// bad
const someVar = myList[0];

// good
const [ someVar ] = myList;

But when the assignment is not directly to a var (like when assigning a property of an object) the rule seems irrelevant.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

What ESLint expects for obj.someVar = myList[0] is:

let obj = {};
let myList = [1,2];

[obj.someVar] = myList;

console.dir(obj);

Here is a link to an Issue about that topic prefer-destructuring flags a property assignment #11584

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!