sindresorhus/eslint-plugin-unicorn

prefer-set-has doesn't autofix types

Fechada

#1.148 aberto em 24 de mar. de 2021

 (1 comentário) (1 reação) (0 responsável)JavaScript (468 forks)user submission
enhancementhelp wanted

Métricas do repositório

Stars
 (5.022 estrelas)
Métricas de merge de PR
 (Mesclagem média 1d 16h) (399 fundiu PRs em 30d)

Description

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.

Guia do colaborador