sindresorhus/eslint-plugin-unicorn

Improve `prefer-set-has`

Chiusa

#1338 aperta il 4 giu 2021

 (2 commenti) (3 reazioni) (0 assegnatari)JavaScript (468 fork)user submission
enhancementhelp wanted

Metriche repository

Star
 (5022 stelle)
Metriche merge PR
 (Merge medio 4h 30m) (26 PR mergiate in 30 g)

Descrizione

Currently, we only report cases that Array only called .includes(). But in some other cases, it should still be preferred.

const foo = [1, 2, 3];

if (foo.includes(1));

// Still work the same if we use `Set`
for (const element of foo);
const bar = [...foo, somethingElse];
call(...foo);
const length = foo.length; // Use `.size` when switch to Set

// Even this, if the callback don't use the second parameter, they are the same
foo.forEach(element => call(element));

We only need make sure the original Array have unique values.

Guida contributor