Skip to content

Commit e6d1eb3

Browse files
cjihrigMylesBorins
authored andcommitted
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>
1 parent 8f0fa61 commit e6d1eb3

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

test/parallel/test-eslint-crypto-check.js

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ new RuleTester().run('crypto-check', rule, {
1919
common.skip("missing crypto");
2020
}
2121
require("crypto");
22+
`,
23+
`
24+
if (!common.hasCrypto) {
25+
common.skip("missing crypto");
26+
}
27+
internalBinding("crypto");
2228
`
2329
],
2430
invalid: [
@@ -51,6 +57,18 @@ new RuleTester().run('crypto-check', rule, {
5157
'}\n' +
5258
'if (common.foo) {}\n' +
5359
'require("crypto")'
60+
},
61+
{
62+
code: 'require("common")\n' +
63+
'if (common.foo) {}\n' +
64+
'internalBinding("crypto")',
65+
errors: [{ message }],
66+
output: 'require("common")\n' +
67+
'if (!common.hasCrypto) {' +
68+
' common.skip("missing crypto");' +
69+
'}\n' +
70+
'if (common.foo) {}\n' +
71+
'internalBinding("crypto")'
5472
}
5573
]
5674
});

tools/eslint-rules/rules-utils.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ module.exports.isCommonModule = function(node) {
3333

3434
/**
3535
* Returns true if any of the passed in modules are used in
36-
* binding calls.
36+
* process.binding() or internalBinding() calls.
3737
*/
3838
module.exports.isBinding = function(node, modules) {
39-
if (node.callee.object) {
40-
return node.callee.object.name === 'process' &&
41-
node.callee.property.name === 'binding' &&
42-
modules.includes(node.arguments[0].value);
43-
}
39+
const isProcessBinding = node.callee.object &&
40+
node.callee.object.name === 'process' &&
41+
node.callee.property.name === 'binding';
42+
43+
return (isProcessBinding || node.callee.name === 'internalBinding') &&
44+
modules.includes(node.arguments[0].value);
4445
};
4546

4647
/**

0 commit comments

Comments
 (0)