mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
ce8f01cf0c
PR-URL: https://github.com/nodejs/node/pull/26398 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
/**
|
|
* @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.';
|
|
|
|
module.exports = function(context) {
|
|
const missingCheckNodes = [];
|
|
let commonModuleNode = null;
|
|
let hasEslintCheck = false;
|
|
|
|
function testEslintUsage(context, node) {
|
|
if (utils.isRequired(node, ['../../tools/node_modules/eslint'])) {
|
|
missingCheckNodes.push(node);
|
|
}
|
|
|
|
if (utils.isCommonModule(node)) {
|
|
commonModuleNode = node;
|
|
}
|
|
}
|
|
|
|
function checkMemberExpression(context, node) {
|
|
if (utils.usesCommonProperty(node, ['skipIfEslintMissing'])) {
|
|
hasEslintCheck = true;
|
|
}
|
|
}
|
|
|
|
function reportIfMissing(context) {
|
|
if (!hasEslintCheck) {
|
|
missingCheckNodes.forEach((node) => {
|
|
context.report({
|
|
node,
|
|
message: msg,
|
|
fix: (fixer) => {
|
|
if (commonModuleNode) {
|
|
return fixer.insertTextAfter(
|
|
commonModuleNode,
|
|
'\ncommon.skipIfEslintMissing();'
|
|
);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
'CallExpression': (node) => testEslintUsage(context, node),
|
|
'MemberExpression': (node) => checkMemberExpression(context, node),
|
|
'Program:exit': (node) => reportIfMissing(context, node)
|
|
};
|
|
};
|