MCPcopy Index your code
hub / github.com/nodejs/node / create

Function create

tools/eslint-rules/crypto-check.js:24–123  ·  view source on GitHub ↗
(context)

Source from the content-addressed store, hash-verified

22 fixable: 'code',
23 },
24 create(context) {
25 const missingCheckNodes = [];
26 const requireNodes = [];
27 let commonModuleNode = null;
28 let hasSkipCall = false;
29
30 function testCryptoUsage(node) {
31 if (utils.isRequired(node, requireModules) ||
32 utils.isBinding(node, bindingModules)) {
33 requireNodes.push(node);
34 }
35
36 if (utils.isCommonModule(node)) {
37 commonModuleNode = node;
38 }
39 }
40
41 function testIfStatement(node) {
42 if (node.test.argument === undefined) {
43 return;
44 }
45 if (isCryptoCheck(node.test.argument)) {
46 checkCryptoCall(node);
47 }
48 }
49
50 function isCryptoCheck(node) {
51 return utils.usesCommonProperty(node, ['hasCrypto', 'hasFipsCrypto']);
52 }
53
54 function checkCryptoCall(node) {
55 if (utils.inSkipBlock(node)) {
56 hasSkipCall = true;
57 } else {
58 missingCheckNodes.push(node);
59 }
60 }
61
62 function testMemberExpression(node) {
63 if (isCryptoCheck(node)) {
64 checkCryptoCall(node);
65 }
66 }
67
68 function reportIfMissingCheck() {
69 if (hasSkipCall) {
70 // There is a skip, which is good, but verify that the require() calls
71 // in question come after at least one check.
72 if (missingCheckNodes.length > 0) {
73 requireNodes.forEach((requireNode) => {
74 const beforeAllChecks = missingCheckNodes.every((checkNode) => {
75 return requireNode.range[0] < checkNode.range[0];
76 });
77
78 if (beforeAllChecks) {
79 context.report({
80 node: requireNode,
81 message: msg,

Callers

nothing calls this directly

Calls 4

testCryptoUsageFunction · 0.85
testIfStatementFunction · 0.85
testMemberExpressionFunction · 0.85
reportIfMissingCheckFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…