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: https://github.com/nodejs/node/pull/25399 Refs: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
6cc74b038f
commit
4c9ea8f3fb
@ -22,6 +22,14 @@ new RuleTester().run('crypto-check', rule, {
|
|||||||
`
|
`
|
||||||
],
|
],
|
||||||
invalid: [
|
invalid: [
|
||||||
|
{
|
||||||
|
code: 'require("common")\n' +
|
||||||
|
'require("crypto")\n' +
|
||||||
|
'if (!common.hasCrypto) {\n' +
|
||||||
|
' common.skip("missing crypto");\n' +
|
||||||
|
'}',
|
||||||
|
errors: [{ message }]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
code: 'require("common")\n' +
|
code: 'require("common")\n' +
|
||||||
'require("crypto")',
|
'require("crypto")',
|
||||||
|
@ -66,6 +66,22 @@ module.exports = function(context) {
|
|||||||
|
|
||||||
function reportIfMissingCheck() {
|
function reportIfMissingCheck() {
|
||||||
if (hasSkipCall) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user