-
-
Notifications
You must be signed in to change notification settings - Fork 381
/
no-document-cookie.mjs
35 lines (33 loc) · 1.01 KB
/
no-document-cookie.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import outdent from 'outdent';
import {getTester} from './utils/test.mjs';
const {test} = getTester(import.meta);
test.snapshot({
valid: [
'document.cookie',
'const foo = document.cookie',
'foo = document.cookie',
'foo = document?.cookie',
'foo = document.cookie + ";foo=bar"',
'delete document.cookie',
'if (document.cookie.includes("foo")){}',
'Object.assign(document, {cookie: "foo=bar"})',
'document[CONSTANTS_COOKIE] = "foo=bar"',
'document[cookie] = "foo=bar"',
outdent`
const CONSTANTS_COOKIE = "cookie";
document[CONSTANTS_COOKIE] = "foo=bar";
`,
],
invalid: [
'document.cookie = "foo=bar"',
'document.cookie += ";foo=bar"',
'document.cookie = document.cookie + ";foo=bar"',
'document.cookie &&= true',
'document["coo" + "kie"] = "foo=bar"',
'foo = document.cookie = "foo=bar"',
'var doc = document; doc.cookie = "foo=bar"',
'let doc = document; doc.cookie = "foo=bar"',
'const doc = globalThis.document; doc.cookie = "foo=bar"',
'window.document.cookie = "foo=bar"',
],
});