1/** 2 * @fileoverview Check that common.skipIfEslintMissing is used if 3 * the eslint module is required. 4 */ 5'use strict'; 6 7const utils = require('./rules-utils.js'); 8 9//------------------------------------------------------------------------------ 10// Rule Definition 11//------------------------------------------------------------------------------ 12const msg = 'Please add a skipIfEslintMissing() call to allow this test to ' + 13 'be skipped when Node.js is built from a source tarball.'; 14 15module.exports = function(context) { 16 const missingCheckNodes = []; 17 let commonModuleNode = null; 18 let 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': () => reportIfMissing(context) 59 }; 60}; 61 62module.exports.meta = { 63 fixable: 'code' 64}; 65