| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3db7a9f commit f0409be
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,12 @@ new RuleTester().run('crypto-check', rule, { | |||
| 19 | 19 | common.skip("missing crypto"); | |
| 20 | 20 | } | |
| 21 | 21 | require("crypto"); | |
| 22 | + `, | ||
| 23 | + ` | ||
| 24 | + if (!common.hasCrypto) { | ||
| 25 | + common.skip("missing crypto"); | ||
| 26 | + } | ||
| 27 | + internalBinding("crypto"); | ||
| 22 | 28 | ` | |
| 23 | 29 | ], | |
| 24 | 30 | invalid: [ | |
@@ -51,6 +57,18 @@ new RuleTester().run('crypto-check', rule, { | |||
| 51 | 57 | '}\n' + | |
| 52 | 58 | 'if (common.foo) {}\n' + | |
| 53 | 59 | 'require("crypto")' | |
| 60 | + }, | ||
| 61 | + { | ||
| 62 | + code: 'require("common")\n' + | ||
| 63 | + 'if (common.foo) {}\n' + | ||
| 64 | + 'internalBinding("crypto")', | ||
| 65 | + errors: [{ message }], | ||
| 66 | + output: 'require("common")\n' + | ||
| 67 | + 'if (!common.hasCrypto) {' + | ||
| 68 | + ' common.skip("missing crypto");' + | ||
| 69 | + '}\n' + | ||
| 70 | + 'if (common.foo) {}\n' + | ||
| 71 | + 'internalBinding("crypto")' | ||
| 54 | 72 | } | |
| 55 | 73 | ] | |
| 56 | 74 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,14 +33,15 @@ module.exports.isCommonModule = function(node) { | |||
| 33 | 33 | ||
| 34 | 34 | /** | |
| 35 | 35 | * Returns true if any of the passed in modules are used in | |
| 36 | - * binding calls. | ||
| 36 | + * process.binding() or internalBinding() calls. | ||
| 37 | 37 | */ | |
| 38 | 38 | module.exports.isBinding = function(node, modules) { | |
| 39 | - if (node.callee.object) { | ||
| 40 | - return node.callee.object.name === 'process' && | ||
| 41 | - node.callee.property.name === 'binding' && | ||
| 42 | - modules.includes(node.arguments[0].value); | ||
| 43 | - } | ||
| 39 | + const isProcessBinding = node.callee.object && | ||
| 40 | + node.callee.object.name === 'process' && | ||
| 41 | + node.callee.property.name === 'binding'; | ||
| 42 | + | ||
| 43 | + return (isProcessBinding || node.callee.name === 'internalBinding') && | ||
| 44 | + modules.includes(node.arguments[0].value); | ||
| 44 | 45 | }; | |
| 45 | 46 | ||
| 46 | 47 | /** | |
| Back | FazBrowse Home | New Git URL |
0 commit comments