Are you an LLM? You can read better optimized documentation at /docs/guide/usage/linter/rules/unicorn/no-document-cookie.md for this page in Markdown format
unicorn/no-document-cookie 限制
它做了什么
禁止直接使用 document.cookie。
为什么这是不好的?
不建议直接使用 document.cookie,因为很容易写错字符串。相反,你应该使用 Cookie Store API 或一个 cookie 库。
示例
此规则的 错误 代码示例:
javascript
document.cookie =
"foo=bar" +
"; Path=/" +
"; Domain=example.com" +
"; expires=Fri, 31 Dec 9999 23:59:59 GMT" +
"; Secure";此规则的 正确 代码示例:
javascript
async function storeCookies() {
await cookieStore.set({
name: "foo",
value: "bar",
expires: Date.now() + 24 * 60 * 60 * 1000,
domain: "example.com",
});
}如何使用
要通过配置文件或 CLI 启用 此规则,可以使用:
json
{
"rules": {
"unicorn/no-document-cookie": "error"
}
}bash
oxlint --deny unicorn/no-document-cookie