Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2a85cc7

Browse filesBrowse files
cjihrigaddaleax
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 <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
1 parent 46ec26f commit 2a85cc7
Copy full SHA for 2a85cc7

File tree

Expand file treeCollapse file tree

2 files changed

+24
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-0
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-eslint-crypto-check.js
+8Lines 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")',
Collapse file

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

Copy file name to clipboardExpand all lines: tools/eslint-rules/crypto-check.js
+16Lines changed: 16 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.