|  | 
|  | 1 | +/** | 
|  | 2 | + * @fileoverview Check that common.skipIfEslintMissing is used if | 
|  | 3 | + *               the eslint module is required. | 
|  | 4 | + */ | 
|  | 5 | +'use strict'; | 
|  | 6 | + | 
|  | 7 | +const utils = require('./rules-utils.js'); | 
|  | 8 | + | 
|  | 9 | +//------------------------------------------------------------------------------ | 
|  | 10 | +// Rule Definition | 
|  | 11 | +//------------------------------------------------------------------------------ | 
|  | 12 | +const msg = 'Please add a skipIfEslintMissing() call to allow this test to ' + | 
|  | 13 | +            'be skipped when Node.js is built from a source tarball.'; | 
|  | 14 | + | 
|  | 15 | +module.exports = function(context) { | 
|  | 16 | +  const missingCheckNodes = []; | 
|  | 17 | +  var commonModuleNode = null; | 
|  | 18 | +  var hasEslintCheck = false; | 
|  | 19 | + | 
|  | 20 | +  function testEslintUsage(context, node) { | 
|  | 21 | +    if (utils.isRequired(node, ['../../tools/node_modules/eslint'])) { | 
|  | 22 | +      missingCheckNodes.push(node); | 
|  | 23 | +    } | 
|  | 24 | + | 
|  | 25 | +    if (utils.isCommonModule(node)) { | 
|  | 26 | +      commonModuleNode = node; | 
|  | 27 | +    } | 
|  | 28 | +  } | 
|  | 29 | + | 
|  | 30 | +  function checkMemberExpression(context, node) { | 
|  | 31 | +    if (utils.usesCommonProperty(node, ['skipIfEslintMissing'])) { | 
|  | 32 | +      hasEslintCheck = true; | 
|  | 33 | +    } | 
|  | 34 | +  } | 
|  | 35 | + | 
|  | 36 | +  function reportIfMissing(context) { | 
|  | 37 | +    if (!hasEslintCheck) { | 
|  | 38 | +      missingCheckNodes.forEach((node) => { | 
|  | 39 | +        context.report({ | 
|  | 40 | +          node, | 
|  | 41 | +          message: msg, | 
|  | 42 | +          fix: (fixer) => { | 
|  | 43 | +            if (commonModuleNode) { | 
|  | 44 | +              return fixer.insertTextAfter( | 
|  | 45 | +                commonModuleNode, | 
|  | 46 | +                '\ncommon.skipIfEslintMissing();' | 
|  | 47 | +              ); | 
|  | 48 | +            } | 
|  | 49 | +          } | 
|  | 50 | +        }); | 
|  | 51 | +      }); | 
|  | 52 | +    } | 
|  | 53 | +  } | 
|  | 54 | + | 
|  | 55 | +  return { | 
|  | 56 | +    'CallExpression': (node) => testEslintUsage(context, node), | 
|  | 57 | +    'MemberExpression': (node) => checkMemberExpression(context, node), | 
|  | 58 | +    'Program:exit': (node) => reportIfMissing(context, node) | 
|  | 59 | +  }; | 
|  | 60 | +}; | 
0 commit comments