Skip to content

Commit c91a7c0

Browse files
danbevMylesBorins
authored andcommitted
tools: add check for using process.binding crypto
Currently, when configuring --without-ssl any tests that use process.binding('crypto') will not report a lint warning. This is because the eslint check only generates a warning when using require. This commit adds a check for using binding in addition to require. PR-URL: #17867 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 421eb75 commit c91a7c0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tools/eslint-rules/crypto-check.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ const utils = require('./rules-utils.js');
1616
const msg = 'Please add a hasCrypto check to allow this test to be skipped ' +
1717
'when Node is built "--without-ssl".';
1818

19+
const cryptoModules = ['crypto', 'http2'];
20+
const requireModules = cryptoModules.concat(['tls', 'https']);
21+
const bindingModules = cryptoModules.concat(['tls_wrap']);
22+
1923
module.exports = function(context) {
2024
const missingCheckNodes = [];
2125
const requireNodes = [];
2226
var hasSkipCall = false;
2327

2428
function testCryptoUsage(node) {
25-
if (utils.isRequired(node, ['crypto', 'tls', 'https', 'http2'])) {
29+
if (utils.isRequired(node, requireModules) ||
30+
utils.isBinding(node, bindingModules)) {
2631
requireNodes.push(node);
2732
}
2833
}

tools/eslint-rules/rules-utils.js

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ module.exports.isRequired = function(node, modules) {
1212
modules.includes(node.arguments[0].value);
1313
};
1414

15+
/**
16+
* Returns true if any of the passed in modules are used in
17+
* binding calls.
18+
*/
19+
module.exports.isBinding = function(node, modules) {
20+
if (node.callee.object) {
21+
return node.callee.object.name === 'process' &&
22+
node.callee.property.name === 'binding' &&
23+
modules.includes(node.arguments[0].value);
24+
}
25+
};
26+
1527
/**
1628
* Returns true is the node accesses any property in the properties
1729
* array on the 'common' object.

0 commit comments

Comments
 (0)