no-cookie-mutation
Disallow in-place mutation of cookie state.
Targeted pattern scopeâ
This rule targets cookie mutation through document.cookie writes and through CookieStore mutator calls.
What this rule reportsâ
- Assignments/deletes/updates involving
document.cookie cookieStore.set(...)cookieStore.delete(...)
Why this rule existsâ
Cookies are shared mutable global state. Direct writes can introduce hidden side effects across modules, requests, and security boundaries.
This rule enforces immutable cookie handling patterns by disallowing direct cookie mutation primitives.
â Incorrectâ
document.cookie = "theme=dark";
â Correctâ
const rawCookie = document.cookie;
Additional examplesâ
// â Mutates cookie storage via CookieStore API
await cookieStore.set({ name: "theme", value: "dark" });
// â
Read-only cookie access
await cookieStore.get("theme");
ESLint flat config exampleâ
import immutable from "eslint-plugin-immutable-2";
export default [
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts,tsx}"],
plugins: { immutable },
rules: {
"immutable/no-cookie-mutation": "error",
},
},
];
When not to use itâ
If your platform intentionally centralizes imperative cookie writes in a dedicated adapter, this rule may be too strict outside that adapter layer.
Rule catalog ID: R934