diff options
author | Daniel Bevenius <daniel.bevenius@gmail.com> | 2017-12-26 09:48:38 +0100 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2017-12-29 06:08:16 +0100 |
commit | acbe00792d3e73ded9d309002974a095e1433afe (patch) | |
tree | 79d76ae96a64e2002ab05f76eea6634ebdc3925d /tools/eslint-rules | |
parent | c64ca56def8651c2ad679bcdf1283fa7560e88f3 (diff) | |
download | android-node-v8-acbe00792d3e73ded9d309002974a095e1433afe.tar.gz android-node-v8-acbe00792d3e73ded9d309002974a095e1433afe.tar.bz2 android-node-v8-acbe00792d3e73ded9d309002974a095e1433afe.zip |
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: https://github.com/nodejs/node/pull/17867
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'tools/eslint-rules')
-rw-r--r-- | tools/eslint-rules/crypto-check.js | 7 | ||||
-rw-r--r-- | tools/eslint-rules/rules-utils.js | 12 |
2 files changed, 18 insertions, 1 deletions
diff --git a/tools/eslint-rules/crypto-check.js b/tools/eslint-rules/crypto-check.js index 9d24d3355d..9570c24c03 100644 --- a/tools/eslint-rules/crypto-check.js +++ b/tools/eslint-rules/crypto-check.js @@ -16,13 +16,18 @@ const utils = require('./rules-utils.js'); const msg = 'Please add a hasCrypto check to allow this test to be skipped ' + 'when Node is built "--without-ssl".'; +const cryptoModules = ['crypto', 'http2']; +const requireModules = cryptoModules.concat(['tls', 'https']); +const bindingModules = cryptoModules.concat(['tls_wrap']); + module.exports = function(context) { const missingCheckNodes = []; const requireNodes = []; var hasSkipCall = false; function testCryptoUsage(node) { - if (utils.isRequired(node, ['crypto', 'tls', 'https', 'http2'])) { + if (utils.isRequired(node, requireModules) || + utils.isBinding(node, bindingModules)) { requireNodes.push(node); } } diff --git a/tools/eslint-rules/rules-utils.js b/tools/eslint-rules/rules-utils.js index f2f5428ed1..2bfab1c639 100644 --- a/tools/eslint-rules/rules-utils.js +++ b/tools/eslint-rules/rules-utils.js @@ -13,6 +13,18 @@ module.exports.isRequired = function(node, modules) { }; /** + * Returns true if any of the passed in modules are used in + * binding calls. + */ +module.exports.isBinding = function(node, modules) { + if (node.callee.object) { + return node.callee.object.name === 'process' && + node.callee.property.name === 'binding' && + modules.includes(node.arguments[0].value); + } +}; + +/** * Returns true is the node accesses any property in the properties * array on the 'common' object. */ |