unicorn/prefer-string-raw 스타일
작동 방식
문자열에서 백슬래시를 피하기 위해 String.raw 사용을 선호합니다.
왜 나쁜가요?
과도한 백슬래시는 문자열 값의 가독성을 떨어뜨릴 수 있으며, 이는 String.raw를 사용함으로써 회피할 수 있습니다.
예시
이 규칙에 대한 잘못된 코드 예시:
javascript
const file = "C:\\windows\\style\\path\\to\\file.js";
const regexp = new RegExp("foo\\.bar");이 규칙에 대한 올바른 코드 예시:
javascript
const file = String.raw`C:\windows\style\path\to\file.js`;
const regexp = new RegExp(String.raw`foo\.bar`);사용 방법
구성 파일 또는 명령줄 인터페이스를 통해 이 규칙을 활성화하려면 다음을 사용하세요:
json
{
"rules": {
"unicorn/prefer-string-raw": "error"
}
}bash
oxlint --deny unicorn/prefer-string-raw