sindresorhus/eslint-plugin-unicorn

prefer-set-has doesn't autofix types

Geschlossen

#1.148 geöffnet am 24.03.2021

 (1 Kommentar) (1 Reaktion) (0 zugewiesene Personen)JavaScript (468 Forks)user submission
enhancementhelp wanted

Repository-Metriken

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

Beschreibung

When "autofixing" an array to a set, the type definition should be fixed too (or the fix should be skipped).

prefer-set-has

const a: Array<'foo' | 'bar'> = ['foo', 'bar']

for (let i = 0; i < 3; i++) {
  if (a.includes(someString)) {
    console.log(123)
  }
}

This is corrected to:

const a: Array<'foo' | 'bar'> = new Set(['foo', 'bar'])

for (let i = 0; i < 3; i++) {
  if (a.has(someString)) {
    console.log(123)
  }
}

Which is confusing and wrong.

Contributor Guide