Are you an LLM? You can read better optimized documentation at /docs/guide/usage/linter/rules/unicorn/no-invalid-fetch-options.md for this page in Markdown format
unicorn/no-invalid-fetch-options 정확성
✅ This rule is turned on by default.
작동 방식
fetch() 및 new Request()에서 유효하지 않은 옵션을 허용하지 않습니다. 특히, 메서드가 GET 또는 HEAD인 경우 본문을 제공하지 않도록 보장합니다. 그렇지 않으면 TypeError가 발생합니다.
왜 문제가 되는가?
fetch() 함수는 메서드가 GET 또는 HEAD이고 본문이 제공된 경우 TypeError를 던집니다. 이는 코드에서 예기치 못한 동작과 오류를 유발할 수 있습니다. 이러한 유효하지 않은 옵션을 금지함으로써, 요청이 올바르게 구성되도록 보장하고 불필요한 오류를 방지합니다.
예시
이 규칙에 대해 잘못된 코드 예시:
javascript
const response = await fetch("/", { method: "GET", body: "foo=bar" });
const request = new Request("/", { method: "GET", body: "foo=bar" });이 규칙에 대해 올바른 코드 예시:
javascript
const response = await fetch("/", { method: "POST", body: "foo=bar" });
const request = new Request("/", { method: "POST", body: "foo=bar" });사용 방법
설정 파일 또는 명령줄 인터페이스를 통해 이 규칙을 활성화하려면 다음을 사용할 수 있습니다:
json
{
"rules": {
"unicorn/no-invalid-fetch-options": "error"
}
}bash
oxlint --deny unicorn/no-invalid-fetch-options