Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda