Sitelet https://github.com/nodejs/node/pull/25395/commits/cf9bcdeabe1cac2c19785183e9f34e1a01cb9047
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 committed Jan 11, 2019
commit cf9bcdeabe1cac2c19785183e9f34e1a01cb9047
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) {

@joyeecheung joyeecheung Jan 10, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in a separate test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. We don't have separate testing for tools/eslint-rules/rules-utils.js (nor do I think we need it at this point).

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