sindresorhus/eslint-plugin-unicorn

prefer-set-has doesn't autofix types

Chiusa

#1148 aperta il 24 mar 2021

 (1 commento) (1 reazione) (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

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.

Guida contributor