sindresorhus/eslint-plugin-unicorn

Rule proposal: `prefer-destructured-variables`

Geschlossen

#1.230 geöffnet am 28.04.2021

 (4 Kommentare) (7 Reaktionen) (0 zugewiesene Personen)JavaScript (468 Forks)user submission
help wantednew rule

Repository-Metriken

Stars
 (5.022 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 16h) (399 gemergte PRs in 30 T)

Beschreibung

I understand we already have consistent-destructuring, and it already covers cases I'm going to post, but that rule is buggy, and I don't like destructuring all used properties in one, I prefer destructuring when needed, for example:

const {a} = foo;

if (a) {
  // ... do something not related to `foo.b`
}

const {b} = foo;

// ... do something with `b`

Fail

const {a} = foo;
console.log(foo.a); 

Pass

const {a} = foo;
console.log(a, foo.b); 

It's like splitting consistent-destructuring into two rules, this one and another like prefer-one-destructuring.


Contributor Guide