Skip to content

Commit

Permalink
tools: lint for use of internalBinding()
Browse files Browse the repository at this point in the history
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 MylesBorins committed May 16, 2019
1 parent 8f0fa61 commit e6d1eb3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
18 changes: 18 additions & 0 deletions test/parallel/test-eslint-crypto-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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")'
}
]
});
13 changes: 7 additions & 6 deletions tools/eslint-rules/rules-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down

0 comments on commit e6d1eb3

Please sign in to comment.