# no-document-cookie

Rule `unicorn/no-document-cookie`. Do not use `document.cookie` directly.

- Source: unicorn
- Technologies: JavaScript
- Kind: suspicious
- Needs type information: no
- Autofix: no
- Reach: 40.5M weekly downloads of presets that enable it
- Trend: +81.2% last quarter
- Rank: #417 by reach, #409 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-document-cookie` | no | no | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-document-cookie.md) |
| Oxlint | `unicorn/no-document-cookie` | no | no | plugin `unicorn`, category restriction | [docs](https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-document-cookie.html) |
| Biome | `suspicious/noDocumentCookie` | yes | no | group suspicious, since 1.9.4 | [docs](https://biomejs.dev/linter/rules/no-document-cookie/) |

## Code examples

### Incorrect: the rule reports this

```js
document.cookie =
  'foo=bar' +
  '; Path=/' +
  '; Domain=example.com' +
  '; expires=Fri, 31 Dec 9999 23:59:59 GMT' +
  '; Secure';
```

```js
document.cookie += '; foo=bar';
```

### Correct: the rule accepts this

```js
await cookieStore.set({
  name: 'foo',
  value: 'bar',
  expires: Date.now() + 24 * 60 * 60 * 1000,
  domain: 'example.com'
});
```

```js
await cookieStore.set('foo', 'bar');
```

```js
import Cookies from 'js-cookie';

Cookies.set('foo', 'bar');
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-document-cookie": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "unicorn/no-document-cookie": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "suspicious": {
        "noDocumentCookie": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/no-console-spaces](https://lintradar.dev/rules/unicorn/no-console-spaces.md): Do not use leading/trailing space between `console.log` parameters.
- [unicorn/no-magic-array-flat-depth](https://lintradar.dev/rules/unicorn/no-magic-array-flat-depth.md): Disallow a magic number as the `depth` argument in `Array#flat(…).`
- [unicorn/consistent-date-clone](https://lintradar.dev/rules/unicorn/consistent-date-clone.md): Prefer passing `Date` directly to the constructor when cloning.
- [unicorn/no-useless-switch-case](https://lintradar.dev/rules/unicorn/no-useless-switch-case.md): Disallow useless case in switch statements.
- [unicorn/prefer-array-flat-map](https://lintradar.dev/rules/unicorn/prefer-array-flat-map.md): Prefer `.flatMap(…)` over `.map(…).flat()` and `.filter(…).flatMap(…)`.
- [unicorn/prefer-array-index-of](https://lintradar.dev/rules/unicorn/prefer-array-index-of.md): Prefer `Array#{indexOf,lastIndexOf}()` over `Array#{findIndex,findLastIndex}()` when looking for the index of an item.

---

Web page: https://lintradar.dev/rules/unicorn/no-document-cookie. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
