Skip to content
Permalink
Browse files

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 <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
  • Loading branch information...
cjihrig authored and addaleax committed Jan 8, 2019
1 parent 46ec26f commit 2a85cc7cae2c1cb055492cc6a7b85d882362452a
Showing with 24 additions and 0 deletions.
  1. +8 −0 test/parallel/test-eslint-crypto-check.js
  2. +16 −0 tools/eslint-rules/crypto-check.js
@@ -22,6 +22,14 @@ new RuleTester().run('crypto-check', rule, {
`
],
invalid: [
{
code: 'require("common")\n' +
'require("crypto")\n' +
'if (!common.hasCrypto) {\n' +
' common.skip("missing crypto");\n' +
'}',
errors: [{ message }]
},
{
code: 'require("common")\n' +
'require("crypto")',
@@ -66,6 +66,22 @@ module.exports = function(context) {

function reportIfMissingCheck() {
if (hasSkipCall) {
// There is a skip, which is good, but verify that the require() calls
// in question come after at least one check.
if (missingCheckNodes.length > 0) {
requireNodes.forEach((requireNode) => {
const beforeAllChecks = missingCheckNodes.every((checkNode) => {
return requireNode.start < checkNode.start;
});

if (beforeAllChecks) {
context.report({
node: requireNode,
message: msg
});
}
});
}
return;
}

0 comments on commit 2a85cc7

Please sign in to comment.
You can’t perform that action at this time.