mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
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: https://github.com/nodejs/node/pull/24952 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
3db7a9ffba
commit
f0409be2a7
2 files changed
+25
-6
No files matched your search
@@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user