unicorn/no-unnecessary-slice-end Pedantic
작동 방식
end 인수를 생략하면 기본적으로 객체의 .length로 설정됩니다.
이를 명시적으로 전달하거나 Infinity를 사용하는 것은 불필요합니다.
왜 좋지 않은가?
자바스크립트에서는 end 인덱스를 생략할 경우 이미 .slice()가 대상의 끝까지 실행되므로,
길이 또는 Infinity를 명시적으로 전달하는 것은 중복됩니다.
예시
이 규칙에 부적절한 코드 예시:
js
const foo = string.slice(1, string.length);
const foo = string.slice(1, Infinity);
const foo = string.slice(1, Number.POSITIVE_INFINITY);이 규칙에 적절한 코드 예시:
js
const foo = string.slice(1);사용 방법
설정 파일이나 명령줄 인터페이스에서 이 규칙을 활성화하려면 다음을 사용하세요:
json
{
"rules": {
"unicorn/no-unnecessary-slice-end": "error"
}
}bash
oxlint --deny unicorn/no-unnecessary-slice-end