|
| 1 | +/** |
| 2 | + * @fileoverview Check that common.skipIfInspectorDisabled is used if |
| 3 | + * the inspector module is required. |
| 4 | + * @author Daniel Bevenius <[email protected]> |
| 5 | + */ |
| 6 | +'use strict'; |
| 7 | + |
| 8 | +const utils = require('./rules-utils.js'); |
| 9 | + |
| 10 | +//------------------------------------------------------------------------------ |
| 11 | +// Rule Definition |
| 12 | +//------------------------------------------------------------------------------ |
| 13 | +const msg = 'Please add a skipIfInspectorDisabled() call to allow this ' + |
| 14 | + 'test to be skippped when Node is built \'--without-inspector\'.'; |
| 15 | + |
| 16 | +module.exports = function(context) { |
| 17 | + var usesInspector = false; |
| 18 | + var hasInspectorCheck = false; |
| 19 | + |
| 20 | + function testInspectorUsage(context, node) { |
| 21 | + if (utils.isRequired(node, ['inspector'])) { |
| 22 | + usesInspector = true; |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + function checkMemberExpression(context, node) { |
| 27 | + if (utils.usesCommonProperty(node, ['skipIfInspectorDisabled'])) { |
| 28 | + hasInspectorCheck = true; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + function reportIfMissing(context, node) { |
| 33 | + if (usesInspector && !hasInspectorCheck) { |
| 34 | + context.report(node, msg); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + return { |
| 39 | + 'CallExpression': (node) => testInspectorUsage(context, node), |
| 40 | + 'MemberExpression': (node) => checkMemberExpression(context, node), |
| 41 | + 'Program:exit': (node) => reportIfMissing(context, node) |
| 42 | + }; |
| 43 | +}; |
0 commit comments