Skip to content
← Back to rules

unicorn/prefer-set-has 성능

An auto-fix is available for this rule.

작동 방식

존재 여부 또는 비존재 여부를 확인할 때 Array#includes() 대신 Set#has()를 사용하도록 권장합니다.

왜 문제가 되나요?

Set#has()Array#includes()보다 더 빠릅니다.

예시

이 규칙에 부적절한 코드 예시:

js
const array = [1, 2, 3];
const hasValue = (value) => array.includes(value);

이 규칙에 적절한 코드 예시:

js
const set = new Set([1, 2, 3]);
const hasValue = (value) => set.has(value);
js
const array = [1, 2, 3];
const hasOne = array.includes(1);

사용 방법

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

json
{
  "rules": {
    "unicorn/prefer-set-has": "error"
  }
}
bash
oxlint --deny unicorn/prefer-set-has

참고 자료