2018-04-27 15:57:52 -04:00
|
|
|
/**
|
|
|
|
* @fileoverview Check that common.skipIfEslintMissing is used if
|
|
|
|
* the eslint module is required.
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const utils = require('./rules-utils.js');
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Rule Definition
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
const msg = 'Please add a skipIfEslintMissing() call to allow this test to ' +
|
|
|
|
'be skipped when Node.js is built from a source tarball.';
|
|
|
|
|
2022-09-26 19:39:39 -07:00
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
fixable: 'code',
|
|
|
|
},
|
|
|
|
create: function(context) {
|
|
|
|
const missingCheckNodes = [];
|
|
|
|
let commonModuleNode = null;
|
|
|
|
let hasEslintCheck = false;
|
2018-04-27 15:57:52 -04:00
|
|
|
|
2022-09-26 19:39:39 -07:00
|
|
|
function testEslintUsage(context, node) {
|
2024-06-19 21:54:08 +02:00
|
|
|
if (utils.isRequired(node, ['../../tools/eslint/node_modules/eslint'])) {
|
2022-09-26 19:39:39 -07:00
|
|
|
missingCheckNodes.push(node);
|
|
|
|
}
|
2018-04-27 15:57:52 -04:00
|
|
|
|
2022-09-26 19:39:39 -07:00
|
|
|
if (utils.isCommonModule(node)) {
|
|
|
|
commonModuleNode = node;
|
|
|
|
}
|
2018-04-27 15:57:52 -04:00
|
|
|
}
|
|
|
|
|
2022-09-26 19:39:39 -07:00
|
|
|
function checkMemberExpression(context, node) {
|
|
|
|
if (utils.usesCommonProperty(node, ['skipIfEslintMissing'])) {
|
|
|
|
hasEslintCheck = true;
|
|
|
|
}
|
2018-04-27 15:57:52 -04:00
|
|
|
}
|
|
|
|
|
2022-09-26 19:39:39 -07:00
|
|
|
function reportIfMissing(context) {
|
|
|
|
if (!hasEslintCheck) {
|
|
|
|
missingCheckNodes.forEach((node) => {
|
|
|
|
context.report({
|
|
|
|
node,
|
|
|
|
message: msg,
|
|
|
|
fix: (fixer) => {
|
|
|
|
if (commonModuleNode) {
|
|
|
|
return fixer.insertTextAfter(
|
|
|
|
commonModuleNode,
|
2022-12-18 17:39:39 +01:00
|
|
|
'\ncommon.skipIfEslintMissing();',
|
2022-09-26 19:39:39 -07:00
|
|
|
);
|
|
|
|
}
|
2022-12-18 17:39:39 +01:00
|
|
|
},
|
2022-09-26 19:39:39 -07:00
|
|
|
});
|
2018-04-27 15:57:52 -04:00
|
|
|
});
|
2022-09-26 19:39:39 -07:00
|
|
|
}
|
2018-04-27 15:57:52 -04:00
|
|
|
}
|
|
|
|
|
2022-09-26 19:39:39 -07:00
|
|
|
return {
|
|
|
|
'CallExpression': (node) => testEslintUsage(context, node),
|
|
|
|
'MemberExpression': (node) => checkMemberExpression(context, node),
|
2022-12-18 17:39:39 +01:00
|
|
|
'Program:exit': () => reportIfMissing(context),
|
2022-09-26 19:39:39 -07:00
|
|
|
};
|
2022-12-18 17:39:39 +01:00
|
|
|
},
|
2020-08-01 14:22:51 -04:00
|
|
|
};
|