Skip to content
Permalink
Browse files

tools: lint for use of internalBinding()

Use of process.binding() has largely been replaced by
internalBinding(). This commit updates the custom crypto
check ESLint rule to check for both process.binding() and
internalBinding().

Refs: #24952
PR-URL: #25395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information...
cjihrig authored and addaleax committed Jan 8, 2019
1 parent 3db7a9f commit f0409be2a728e58bf4646d7edc2b19f2f3ed5097
Showing with 25 additions and 6 deletions.
  1. +18 −0 test/parallel/test-eslint-crypto-check.js
  2. +7 −6 tools/eslint-rules/rules-utils.js
@@ -19,6 +19,12 @@ new RuleTester().run('crypto-check', rule, {
common.skip("missing crypto");
}
require("crypto");
`,
`
if (!common.hasCrypto) {
common.skip("missing crypto");
}
internalBinding("crypto");
`
],
invalid: [
@@ -51,6 +57,18 @@ new RuleTester().run('crypto-check', rule, {
'}\n' +
'if (common.foo) {}\n' +
'require("crypto")'
},
{
code: 'require("common")\n' +
'if (common.foo) {}\n' +
'internalBinding("crypto")',
errors: [{ message }],
output: 'require("common")\n' +
'if (!common.hasCrypto) {' +
' common.skip("missing crypto");' +
'}\n' +
'if (common.foo) {}\n' +
'internalBinding("crypto")'
}
]
});
@@ -33,14 +33,15 @@ module.exports.isCommonModule = function(node) {

/**
* Returns true if any of the passed in modules are used in
* binding calls.
* process.binding() or internalBinding() 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);
}
const isProcessBinding = node.callee.object &&
node.callee.object.name === 'process' &&
node.callee.property.name === 'binding';

return (isProcessBinding || node.callee.name === 'internalBinding') &&
modules.includes(node.arguments[0].value);
};

/**

0 comments on commit f0409be

Please sign in to comment.
You can’t perform that action at this time.