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 Restriction
作用
禁止直接使用 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",
});
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/no-document-cookie": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"unicorn/no-document-cookie": "error",
},
});bash
oxlint --deny unicorn/no-document-cookie版本
此规则于 v0.0.18 中加入。
