Skip to content
← Back to rules

typescript/prefer-string-starts-ends-with Nursery

This rule is turned on by default when type-aware linting is enabled.
💭 This rule requires type information.

무엇을 하는가

startsWithendsWith를 수동 문자열 경계 검사보다 우선합니다.

왜 좋지 않은가?

slice, indexOf, 정규식 앵커 또는 수동 인덱싱을 사용한 경계 검사는 startsWith/endsWith보다 읽기 어렵고 유지보수가 어렵습니다.

예시

이 규칙에 대한 잘못된 코드 예시:

ts
value.slice(0, 3) === "foo";
value.slice(-3) === "bar";

이 규칙에 대한 올바른 코드 예시:

ts
value.startsWith("foo");
value.endsWith("bar");

구성

이 규칙은 다음 속성을 가진 구성 객체를 받습니다:

allowSingleElementEquality

type: "always" | "never"

기본값: null

첫 번째/마지막 문자와의 등가성 검사를 허용할지 여부.

사용 방법

이 규칙을 설정 파일이나 CLI에서 활성화하려면 다음을 사용할 수 있습니다:

json
{
  "rules": {
    "typescript/prefer-string-starts-ends-with": "error"
  }
}
bash
oxlint --type-aware --deny typescript/prefer-string-starts-ends-with

참고 자료