Skip to content
← Back to rules

unicorn/consistent-empty-array-spread Pedantic

💡 A suggestion is available for this rule.

작동 방식

배열에서 조건부 연산자를 펼칠 때, 대체로 빈 배열([])과 빈 문자열("")을 사용할 수 있지만, 두 가지 분기 모두에서 일관된 타입을 유지하는 것이 더 낫습니다.

왜 문제가 되는가?

두 분기 모두에서 일관된 타입을 사용하면 코드를 더 쉽게 읽고 이해할 수 있습니다.

예시

이 규칙에 잘못된 예시:

javascript
const array = [a, ...(foo ? [b, c] : "")];

const array = [a, ...(foo ? "bc" : [])];

이 규칙에 올바른 예시:

javascript
const array = [a, ...(foo ? [b, c] : [])];

const array = [a, ...(foo ? "bc" : "")];

사용 방법

이 규칙을 구성 파일이나 명령줄 인터페이스에서 활성화하려면 다음을 사용하세요:

json
{
  "rules": {
    "unicorn/consistent-empty-array-spread": "error"
  }
}
bash
oxlint --deny unicorn/consistent-empty-array-spread

참고 자료