Skip to content

Commit 21500a8

Browse files
cjihrigMylesBorins
authored andcommitted
tools: update crypo check rule
This commit updates the custom crypto-check ESLint rule to detect require() calls that come before any hasCrypto checks. PR-URL: #25399 Refs: #25388 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
1 parent 3f51a60 commit 21500a8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ new RuleTester().run('crypto-check', rule,{
2222
`
2323
],
2424
invalid: [
25+
{
26+
code: 'require("common")\n'+
27+
'require("crypto")\n'+
28+
'if (!common.hasCrypto){\n'+
29+
' common.skip("missing crypto");\n'+
30+
'}',
31+
errors: [{ message }]
32+
},
2533
{
2634
code: 'require("common")\n'+
2735
'require("crypto")',

‎tools/eslint-rules/crypto-check.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ module.exports = function(context){
6666

6767
functionreportIfMissingCheck(){
6868
if(hasSkipCall){
69+
// There is a skip, which is good, but verify that the require() calls
70+
// in question come after at least one check.
71+
if(missingCheckNodes.length>0){
72+
requireNodes.forEach((requireNode)=>{
73+
constbeforeAllChecks=missingCheckNodes.every((checkNode)=>{
74+
returnrequireNode.start<checkNode.start;
75+
});
76+
77+
if(beforeAllChecks){
78+
context.report({
79+
node: requireNode,
80+
message: msg
81+
});
82+
}
83+
});
84+
}
6985
return;
7086
}
7187

0 commit comments

Comments
(0)