Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 05b71f1

Browse files
cjihrigBethGriggs
authored andcommittedApr 28, 2019
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 b49889d commit 05b71f1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

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

+8
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

+16
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ module.exports = function(context) {
6666

6767
function reportIfMissingCheck() {
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+
const beforeAllChecks = missingCheckNodes.every((checkNode) => {
74+
return requireNode.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)
Please sign in to comment.