Skip to content

Beta. consent-kit is at 0.x: expect breaking changes between releases, and treat everything it generates as a draft. Report a problem or share feedback.

@consent-kit/eslint-plugin has one rule, @consent-kit/no-raw-storage, which reports raw browser storage and beacon APIs in first-party code and points at the generated storage facade instead. This page lists what the rule reports, its options, the recommended config and the helper for finding disable comments.

The plugin needs ESLint 9 or later and is written for flat config.

eslint.config.js
import consentKit from '@consent-kit/eslint-plugin';
export default [consentKit.configs.recommended];

The recommended config registers the plugin under the @consent-kit namespace and sets @consent-kit/no-raw-storage to error. It is also a named export:

import { recommended } from '@consent-kit/eslint-plugin';

To pass options, or to limit the rule to some files, register the plugin yourself:

eslint.config.js
import consentKit from '@consent-kit/eslint-plugin';
export default [
{
files: ['src/**/*.ts'],
plugins: { '@consent-kit': consentKit },
rules: {
'@consent-kit/no-raw-storage': ['error', { facadeModule: '@/lib/storage', facadeName: 'store' }],
},
},
];

A problem rule with suggestions. It has no automatic fix.

API Reported uses Facade equivalent named in the message
localStorage Every use of the object: getItem, setItem, removeItem, clear, length, localStorage.foo = 1, localStorage[key], delete localStorage.foo, passing it as an argument, assigning it to a variable storage.local, or storage.local.get(key), .set(key, value), .remove(key)
sessionStorage The same storage.session and its methods
cookieStore Every use of the object storage.cookies, or .get(name), .set(name, value), .remove(name)
document.cookie Reads and writes, including += storage.cookies.get(name) for a read, storage.cookies.set(name, value) for a write
indexedDB.open The call and any other reference to the member storage.openDatabase(name)
navigator.sendBeacon The call and any other reference to the member None; see sendBeacon

The rule follows the global through the forms it can take:

  • through the global object, in any depth: window.localStorage, globalThis.sessionStorage, self.localStorage, window.window.localStorage, window.document.cookie, window.navigator.sendBeacon;
  • with a computed property that is a string literal: window['localStorage'], document['cookie'], localStorage['getItem']('a');
  • through destructuring: const { localStorage: store } = window, const { cookie } = document, const { sendBeacon } = window.navigator;
  • through optional chaining and TypeScript wrappers: localStorage?.getItem('a'), (localStorage as Storage).getItem('a'), localStorage!.setItem(...), (<any>window).sessionStorage.

It works with ESLint’s default parser and with @typescript-eslint/parser, and whether or not the browser globals are declared in languageOptions.globals.

  • A local binding with the same name. function f(localStorage) { ... }, const navigator = { sendBeacon() {} } or import { sessionStorage } from './fake' is somebody else’s object. A shadow in one scope does not hide the global in another.
  • The same names as properties of other objects. request.cookie, app.localStorage.getItem('a'), this.cookie.
  • Other members of document, navigator and indexedDB. document.title, navigator.userAgent, indexedDB.deleteDatabase('x').
  • Dynamic property names. document[name] and window[name] cannot be judged.
  • Type positions. type Store = typeof localStorage touches nothing at runtime.
  • The facade. storage.local.set('theme', 'dark') is an ordinary member call.
  • An aliased global object. const w = window; w.localStorage.getItem('a') and const d = document; d.cookie = 'a=1' are not followed. Aliasing a store itself is reported at the alias: const s = localStorage.

The rule is a lint on your own source. Code it does not see, such as a vendor’s script, is the business of the guard and the Content-Security-Policy.

Message id Text
useFacade Raw `{{api}}` bypasses the consent registry. Use `{{replacement}}` from '{{module}}' instead.
noFacade Raw `{{api}}` bypasses the consent registry and has no facade equivalent yet. Check consent for the declared endpoint first, then disable this rule for the line with a reason: `// eslint-disable-next-line {{ruleId}} -- <reason>`.
suggestFacade Replace with `{{replacement}}` (values are JSON-serialised and writes return a result instead of throwing).

{{api}} is one of document.cookie, localStorage, sessionStorage, cookieStore, indexedDB.open or navigator.sendBeacon. {{module}} and the facade name in {{replacement}} come from the options.

With the default options:

Raw `localStorage` bypasses the consent registry. Use `storage.local.set(key, value)` from './storage.gen' instead.

The rule offers an editor suggestion for one shape only: a direct call of getItem, setItem or removeItem on localStorage or sessionStorage, with exactly the expected number of arguments and no spread.

Code Suggestion
localStorage.getItem('theme') storage.local.get('theme')
sessionStorage.removeItem('funnel') storage.session.remove('funnel')
localStorage.setItem(key, JSON.stringify(value)) storage.local.set(key, JSON.stringify(value))

It is a suggestion and not a fix because the facade behaves differently: values are JSON-serialised, and a write returns a result instead of throwing. The arguments are copied as written, so in the last row you still have to remove your own JSON.stringify. The differences are listed in Migrate raw storage calls to the facade.

cookieStore, document.cookie, indexedDB.open and every other use of the storage objects get a message without a suggestion.

navigator.sendBeacon is in the rule because a beacon sends data to an endpoint, and the registry declares endpoints with their purposes. The facade has no equivalent for it. The message tells you to check consent for the declared endpoint yourself and then disable the rule for that line with a reason:

if (isAccepted('analytics')) {
// eslint-disable-next-line @consent-kit/no-raw-storage -- sends to the declared endpoint acme_collect, after the consent check above
navigator.sendBeacon('/collect', body);
}

One optional object.

Option Type Default Meaning
allow array of 'document.cookie', 'localStorage', 'sessionStorage', 'cookieStore', 'indexedDB.open', 'navigator.sendBeacon' [] Raw APIs the rule does not report.
facadeModule string './storage.gen' Import path of the project’s facade module. Used in messages only.
facadeName string 'storage' Name of the facade object, used in messages and suggestions.

Unknown properties, and values of allow outside the list, are rejected by the options schema. The list of API names is exported as RAW_APIS.

'@consent-kit/no-raw-storage': ['error', { allow: ['navigator.sendBeacon'] }]

The rule has no built-in exemption for any file. It does not need one in the usual setup:

  • The generated modules call no raw API. storage.gen.ts only calls createStorage.
  • The facade’s own document.cookie and localStorage calls, and the receipt sender’s navigator.sendBeacon, are inside the @consent-kit/storage package. ESLint does not lint node_modules by default.

If you keep a hand-written wrapper around a raw API, scope the rule with files and ignores in your flat config, or disable it for the lines concerned with a reason.

An exception to the rule is an ordinary ESLint directive. Give it a reason after --:

// eslint-disable-next-line @consent-kit/no-raw-storage -- reads the server's CSRF cookie
const token = document.cookie;

The plugin exports a helper that finds these exceptions in a source text, so that a script can list them or fail when one has no reason:

import { findDisableComments, RULE_ID } from '@consent-kit/eslint-plugin';
function findDisableComments(sourceText: string, ruleId?: string): DisableComment[];

RULE_ID is '@consent-kit/no-raw-storage' and is the default for ruleId. Pass another id when you registered the plugin under a different namespace.

Each DisableComment has:

Field Meaning
directive 'eslint-disable', 'eslint-disable-line' or 'eslint-disable-next-line'.
line 1-based line on which the comment starts.
rules Every rule the comment names, as written.
reason The text after --, trimmed. Absent when there is none.
missingReason true when there is no reason, or an empty one.

A script for CI:

import { readFileSync } from 'node:fs';
import { findDisableComments } from '@consent-kit/eslint-plugin';
let failed = false;
for (const file of process.argv.slice(2)) {
for (const comment of findDisableComments(readFileSync(file, 'utf8'))) {
console.log(`${file}:${comment.line} ${comment.directive} ${comment.reason ?? '(no reason)'}`);
if (comment.missingReason) failed = true;
}
}
process.exit(failed ? 1 : 0);

The helper follows ESLint’s directive grammar: eslint-disable counts only in a block comment, the -line forms count in either kind, rules are separated by commas, and the reason is whatever follows the first --.

What it does not cover:

  • A bare /* eslint-disable */ that names no rule. It silences this rule too, but is not specific to it.
  • A rule switched off in the config: rules: { '@consent-kit/no-raw-storage': 'off' }.
  • Regular expression literals. The helper finds comments with a small scanner that skips string and template literals, not with a parser. A regex literal that contains a quote or // can hide or fake a comment on the same line.
Export What it is
default The plugin object: meta, rules, configs.recommended.
rules { 'no-raw-storage': ... }
recommended The flat config.
RAW_APIS, RawApi, NoRawStorageOptions The API names the rule knows, and the options type.
RULE_ID, findDisableComments, DisableComment The disable-comment helper.
consent-kit

Generate your cookie banner and privacy-policy drafts from one registry, and audit what your site really does against it.

© 2026 consent-kit · Released under the MIT licence.