| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 282b6eb commit 43b97c7
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,107 +20,108 @@ const cryptoModules = ['crypto', 'http2']; | |||
| 20 | 20 | const requireModules = cryptoModules.concat(['tls', 'https']); | |
| 21 | 21 | const bindingModules = cryptoModules.concat(['tls_wrap']); | |
| 22 | 22 | ||
| 23 | - module.exports = function(context) { | ||
| 24 | - const missingCheckNodes = []; | ||
| 25 | - const requireNodes = []; | ||
| 26 | - let commonModuleNode = null; | ||
| 27 | - let hasSkipCall = false; | ||
| 23 | + module.exports = { | ||
| 24 | + meta: { | ||
| 25 | + fixable: 'code', | ||
| 26 | + }, | ||
| 27 | + create(context) { | ||
| 28 | + const missingCheckNodes = []; | ||
| 29 | + const requireNodes = []; | ||
| 30 | + let commonModuleNode = null; | ||
| 31 | + let hasSkipCall = false; | ||
| 32 | + | ||
| 33 | + function testCryptoUsage(node) { | ||
| 34 | + if (utils.isRequired(node, requireModules) || | ||
| 35 | + utils.isBinding(node, bindingModules)) { | ||
| 36 | + requireNodes.push(node); | ||
| 37 | + } | ||
| 28 | 38 | ||
| 29 | - function testCryptoUsage(node) { | ||
| 30 | - if (utils.isRequired(node, requireModules) || | ||
| 31 | - utils.isBinding(node, bindingModules)) { | ||
| 32 | - requireNodes.push(node); | ||
| 39 | + if (utils.isCommonModule(node)) { | ||
| 40 | + commonModuleNode = node; | ||
| 41 | + } | ||
| 33 | 42 | } | |
| 34 | 43 | ||
| 35 | - if (utils.isCommonModule(node)) { | ||
| 36 | - commonModuleNode = node; | ||
| 44 | + function testIfStatement(node) { | ||
| 45 | + if (node.test.argument === undefined) { | ||
| 46 | + return; | ||
| 47 | + } | ||
| 48 | + if (isCryptoCheck(node.test.argument)) { | ||
| 49 | + checkCryptoCall(node); | ||
| 50 | + } | ||
| 37 | 51 | } | |
| 38 | - } | ||
| 39 | 52 | ||
| 40 | - function testIfStatement(node) { | ||
| 41 | - if (node.test.argument === undefined) { | ||
| 42 | - return; | ||
| 43 | - } | ||
| 44 | - if (isCryptoCheck(node.test.argument)) { | ||
| 45 | - checkCryptoCall(node); | ||
| 53 | + function isCryptoCheck(node) { | ||
| 54 | + return utils.usesCommonProperty(node, ['hasCrypto', 'hasFipsCrypto']); | ||
| 46 | 55 | } | |
| 47 | - } | ||
| 48 | - | ||
| 49 | - function isCryptoCheck(node) { | ||
| 50 | - return utils.usesCommonProperty(node, ['hasCrypto', 'hasFipsCrypto']); | ||
| 51 | - } | ||
| 52 | 56 | ||
| 53 | - function checkCryptoCall(node) { | ||
| 54 | - if (utils.inSkipBlock(node)) { | ||
| 55 | - hasSkipCall = true; | ||
| 56 | - } else { | ||
| 57 | - missingCheckNodes.push(node); | ||
| 57 | + function checkCryptoCall(node) { | ||
| 58 | + if (utils.inSkipBlock(node)) { | ||
| 59 | + hasSkipCall = true; | ||
| 60 | + } else { | ||
| 61 | + missingCheckNodes.push(node); | ||
| 62 | + } | ||
| 58 | 63 | } | |
| 59 | - } | ||
| 60 | 64 | ||
| 61 | - function testMemberExpression(node) { | ||
| 62 | - if (isCryptoCheck(node)) { | ||
| 63 | - checkCryptoCall(node); | ||
| 65 | + function testMemberExpression(node) { | ||
| 66 | + if (isCryptoCheck(node)) { | ||
| 67 | + checkCryptoCall(node); | ||
| 68 | + } | ||
| 64 | 69 | } | |
| 65 | - } | ||
| 66 | - | ||
| 67 | - function reportIfMissingCheck() { | ||
| 68 | - 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.range[0] < checkNode.range[0]; | ||
| 75 | - }); | ||
| 76 | 70 | ||
| 77 | - if (beforeAllChecks) { | ||
| 78 | - context.report({ | ||
| 79 | - node: requireNode, | ||
| 80 | - message: msg | ||
| 71 | + function reportIfMissingCheck() { | ||
| 72 | + if (hasSkipCall) { | ||
| 73 | + // There is a skip, which is good, but verify that the require() calls | ||
| 74 | + // in question come after at least one check. | ||
| 75 | + if (missingCheckNodes.length > 0) { | ||
| 76 | + requireNodes.forEach((requireNode) => { | ||
| 77 | + const beforeAllChecks = missingCheckNodes.every((checkNode) => { | ||
| 78 | + return requireNode.range[0] < checkNode.range[0]; | ||
| 81 | 79 | }); | |
| 82 | - } | ||
| 83 | - }); | ||
| 80 | + | ||
| 81 | + if (beforeAllChecks) { | ||
| 82 | + context.report({ | ||
| 83 | + node: requireNode, | ||
| 84 | + message: msg | ||
| 85 | + }); | ||
| 86 | + } | ||
| 87 | + }); | ||
| 88 | + } | ||
| 89 | + return; | ||
| 84 | 90 | } | |
| 85 | - return; | ||
| 86 | - } | ||
| 87 | 91 | ||
| 88 | - if (requireNodes.length > 0) { | ||
| 89 | - if (missingCheckNodes.length > 0) { | ||
| 90 | - report(missingCheckNodes); | ||
| 91 | - } else { | ||
| 92 | - report(requireNodes); | ||
| 92 | + if (requireNodes.length > 0) { | ||
| 93 | + if (missingCheckNodes.length > 0) { | ||
| 94 | + report(missingCheckNodes); | ||
| 95 | + } else { | ||
| 96 | + report(requireNodes); | ||
| 97 | + } | ||
| 93 | 98 | } | |
| 94 | 99 | } | |
| 95 | - } | ||
| 96 | 100 | ||
| 97 | - function report(nodes) { | ||
| 98 | - nodes.forEach((node) => { | ||
| 99 | - context.report({ | ||
| 100 | - node, | ||
| 101 | - message: msg, | ||
| 102 | - fix: (fixer) => { | ||
| 103 | - if (commonModuleNode) { | ||
| 104 | - return fixer.insertTextAfter( | ||
| 105 | - commonModuleNode, | ||
| 106 | - '\nif (!common.hasCrypto) {' + | ||
| 107 | - ' common.skip("missing crypto");' + | ||
| 108 | - '}' | ||
| 109 | - ); | ||
| 101 | + function report(nodes) { | ||
| 102 | + nodes.forEach((node) => { | ||
| 103 | + context.report({ | ||
| 104 | + node, | ||
| 105 | + message: msg, | ||
| 106 | + fix: (fixer) => { | ||
| 107 | + if (commonModuleNode) { | ||
| 108 | + return fixer.insertTextAfter( | ||
| 109 | + commonModuleNode, | ||
| 110 | + '\nif (!common.hasCrypto) {' + | ||
| 111 | + ' common.skip("missing crypto");' + | ||
| 112 | + '}' | ||
| 113 | + ); | ||
| 114 | + } | ||
| 110 | 115 | } | |
| 111 | - } | ||
| 116 | + }); | ||
| 112 | 117 | }); | |
| 113 | - }); | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - return { | ||
| 117 | - 'CallExpression': (node) => testCryptoUsage(node), | ||
| 118 | - 'IfStatement:exit': (node) => testIfStatement(node), | ||
| 119 | - 'MemberExpression:exit': (node) => testMemberExpression(node), | ||
| 120 | - 'Program:exit': () => reportIfMissingCheck() | ||
| 121 | - }; | ||
| 122 | - }; | ||
| 118 | + } | ||
| 123 | 119 | ||
| 124 | - module.exports.meta = { | ||
| 125 | - fixable: 'code' | ||
| 120 | + return { | ||
| 121 | + 'CallExpression': (node) => testCryptoUsage(node), | ||
| 122 | + 'IfStatement:exit': (node) => testIfStatement(node), | ||
| 123 | + 'MemberExpression:exit': (node) => testMemberExpression(node), | ||
| 124 | + 'Program:exit': () => reportIfMissingCheck() | ||
| 125 | + }; | ||
| 126 | + } | ||
| 126 | 127 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,53 +13,54 @@ const utils = require('./rules-utils.js'); | |||
| 13 | 13 | const msg = 'Please add a skipIfInspectorDisabled() call to allow this ' + | |
| 14 | 14 | 'test to be skipped when Node is built \'--without-inspector\'.'; | |
| 15 | 15 | ||
| 16 | - module.exports = function(context) { | ||
| 17 | - const missingCheckNodes = []; | ||
| 18 | - let commonModuleNode = null; | ||
| 19 | - let hasInspectorCheck = false; | ||
| 16 | + module.exports = { | ||
| 17 | + meta: { | ||
| 18 | + fixable: 'code', | ||
| 19 | + }, | ||
| 20 | + create(context) { | ||
| 21 | + const missingCheckNodes = []; | ||
| 22 | + let commonModuleNode = null; | ||
| 23 | + let hasInspectorCheck = false; | ||
| 20 | 24 | ||
| 21 | - function testInspectorUsage(context, node) { | ||
| 22 | - if (utils.isRequired(node, ['inspector'])) { | ||
| 23 | - missingCheckNodes.push(node); | ||
| 24 | - } | ||
| 25 | + function testInspectorUsage(context, node) { | ||
| 26 | + if (utils.isRequired(node, ['inspector'])) { | ||
| 27 | + missingCheckNodes.push(node); | ||
| 28 | + } | ||
| 25 | 29 | ||
| 26 | - if (utils.isCommonModule(node)) { | ||
| 27 | - commonModuleNode = node; | ||
| 30 | + if (utils.isCommonModule(node)) { | ||
| 31 | + commonModuleNode = node; | ||
| 32 | + } | ||
| 28 | 33 | } | |
| 29 | - } | ||
| 30 | 34 | ||
| 31 | - function checkMemberExpression(context, node) { | ||
| 32 | - if (utils.usesCommonProperty(node, ['skipIfInspectorDisabled'])) { | ||
| 33 | - hasInspectorCheck = true; | ||
| 35 | + function checkMemberExpression(context, node) { | ||
| 36 | + if (utils.usesCommonProperty(node, ['skipIfInspectorDisabled'])) { | ||
| 37 | + hasInspectorCheck = true; | ||
| 38 | + } | ||
| 34 | 39 | } | |
| 35 | - } | ||
| 36 | 40 | ||
| 37 | - function reportIfMissing(context) { | ||
| 38 | - if (!hasInspectorCheck) { | ||
| 39 | - missingCheckNodes.forEach((node) => { | ||
| 40 | - context.report({ | ||
| 41 | - node, | ||
| 42 | - message: msg, | ||
| 43 | - fix: (fixer) => { | ||
| 44 | - if (commonModuleNode) { | ||
| 45 | - return fixer.insertTextAfter( | ||
| 46 | - commonModuleNode, | ||
| 47 | - '\ncommon.skipIfInspectorDisabled();' | ||
| 48 | - ); | ||
| 41 | + function reportIfMissing(context) { | ||
| 42 | + if (!hasInspectorCheck) { | ||
| 43 | + missingCheckNodes.forEach((node) => { | ||
| 44 | + context.report({ | ||
| 45 | + node, | ||
| 46 | + message: msg, | ||
| 47 | + fix: (fixer) => { | ||
| 48 | + if (commonModuleNode) { | ||
| 49 | + return fixer.insertTextAfter( | ||
| 50 | + commonModuleNode, | ||
| 51 | + '\ncommon.skipIfInspectorDisabled();' | ||
| 52 | + ); | ||
| 53 | + } | ||
| 49 | 54 | } | |
| 50 | - } | ||
| 55 | + }); | ||
| 51 | 56 | }); | |
| 52 | - }); | ||
| 57 | + } | ||
| 53 | 58 | } | |
| 54 | - } | ||
| 55 | 59 | ||
| 56 | - return { | ||
| 57 | - 'CallExpression': (node) => testInspectorUsage(context, node), | ||
| 58 | - 'MemberExpression': (node) => checkMemberExpression(context, node), | ||
| 59 | - 'Program:exit': () => reportIfMissing(context) | ||
| 60 | - }; | ||
| 61 | - }; | ||
| 62 | - | ||
| 63 | - module.exports.meta = { | ||
| 64 | - fixable: 'code' | ||
| 60 | + return { | ||
| 61 | + 'CallExpression': (node) => testInspectorUsage(context, node), | ||
| 62 | + 'MemberExpression': (node) => checkMemberExpression(context, node), | ||
| 63 | + 'Program:exit': () => reportIfMissing(context) | ||
| 64 | + }; | ||
| 65 | + } | ||
| 65 | 66 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments