noDocumentCookie
¥Summary
-
规则生效日期:
v1.9.4¥Rule available since:
v1.9.4 -
诊断类别:
lint/suspicious/noDocumentCookie¥Diagnostic Category:
lint/suspicious/noDocumentCookie -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
与
unicorn/no-document-cookie相同¥Same as
unicorn/no-document-cookie
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noDocumentCookie": "error" } } }}¥Description
禁止直接向 document.cookie 赋值。
¥Disallow direct assignments to document.cookie.
不建议直接使用 document.cookie,因为很容易出错。相反,你应该使用 Cookie Store API。
¥It’s not recommended to use document.cookie directly as it’s easy to get the string wrong. Instead, you should use the Cookie Store API.
¥Examples
¥Invalid
document.cookie = "foo=bar";code-block.js:1:1 lint/suspicious/noDocumentCookie ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Direct assigning to document.cookie is not recommended.
> 1 │ document.cookie = “foo=bar”;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Consider using the Cookie Store API.
document.cookie += "; foo=bar";code-block.js:1:1 lint/suspicious/noDocumentCookie ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Direct assigning to document.cookie is not recommended.
> 1 │ document.cookie += ”; foo=bar”;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Consider using the Cookie Store API.
¥Valid
const array = document.cookie.split("; ");await cookieStore .set({ name: "foo", value: "bar", expires: Date.now() + 24 * 60 * 60, domain: "example.com",})import Cookies from 'js-cookie';
Cookies.set('foo', 'bar');¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号