Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: update eslint-check.js to object style #44706

Merged
merged 1 commit into from Sep 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 40 additions & 39 deletions tools/eslint-rules/eslint-check.js
Expand Up @@ -12,53 +12,54 @@ const utils = require('./rules-utils.js');
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;
module.exports = {
meta: {
fixable: 'code',
},
create: 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);
}
function testEslintUsage(context, node) {
if (utils.isRequired(node, ['../../tools/node_modules/eslint'])) {
missingCheckNodes.push(node);
}

if (utils.isCommonModule(node)) {
commonModuleNode = node;
if (utils.isCommonModule(node)) {
commonModuleNode = node;
}
}
}

function checkMemberExpression(context, node) {
if (utils.usesCommonProperty(node, ['skipIfEslintMissing'])) {
hasEslintCheck = true;
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();'
);
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': () => reportIfMissing(context)
};
};

module.exports.meta = {
fixable: 'code'
return {
'CallExpression': (node) => testEslintUsage(context, node),
'MemberExpression': (node) => checkMemberExpression(context, node),
'Program:exit': () => reportIfMissing(context)
};
}
};