From 3ad0fae89d3cab90d08d890df79c13aefda82081 Mon Sep 17 00:00:00 2001 From: andiemontoyeah <55297964+andiemontoyeah@users.noreply.github.com> Date: Mon, 26 Sep 2022 19:39:39 -0700 Subject: [PATCH] tools: update eslint-check.js to object style Updated rule from deprecated function-style format to object-style format. Refs: https://eslint.org/docs/latest/developer-guide/working-with-rules PR-URL: https://github.com/nodejs/node/pull/44706 Reviewed-By: Rich Trott --- tools/eslint-rules/eslint-check.js | 79 +++++++++++++++--------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/tools/eslint-rules/eslint-check.js b/tools/eslint-rules/eslint-check.js index 0edf7d2899cbf9..df82257ccd1443 100644 --- a/tools/eslint-rules/eslint-check.js +++ b/tools/eslint-rules/eslint-check.js @@ -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) + }; + } };