forked from mysticatea/eslint-plugin-node
-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathcrypto.js
More file actions
57 lines (54 loc) · 1.85 KB
/
crypto.js
File metadata and controls
57 lines (54 loc) · 1.85 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @author Pixel998
* See LICENSE file in root directory for full license.
*/
"use strict"
const RuleTester = require("#test-helpers").RuleTester
const rule = require("../../../../lib/rules/prefer-global/crypto")
const provideModuleMethods = ["require", "process.getBuiltinModule"]
new RuleTester().run("prefer-global/crypto", rule, {
valid: [
"crypto.randomUUID()",
{
code: "crypto.randomUUID()",
options: ["always"],
},
...provideModuleMethods.flatMap(method => [
{
code: `const { webcrypto } = ${method}('crypto'); webcrypto.randomUUID()`,
options: ["never"],
},
{
code: `const { webcrypto } = ${method}('node:crypto'); webcrypto.randomUUID()`,
options: ["never"],
},
]),
],
invalid: [
...provideModuleMethods.flatMap(method => [
{
code: `const { webcrypto } = ${method}('crypto'); webcrypto.randomUUID()`,
errors: [{ messageId: "preferGlobal" }],
},
{
code: `const { webcrypto } = ${method}('node:crypto'); webcrypto.randomUUID()`,
errors: [{ messageId: "preferGlobal" }],
},
{
code: `const { webcrypto } = ${method}('crypto'); webcrypto.randomUUID()`,
options: ["always"],
errors: [{ messageId: "preferGlobal" }],
},
{
code: `const { webcrypto } = ${method}('node:crypto'); webcrypto.randomUUID()`,
options: ["always"],
errors: [{ messageId: "preferGlobal" }],
},
]),
{
code: "crypto.randomUUID()",
options: ["never"],
errors: [{ messageId: "preferModule" }],
},
],
})