Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda