From b70ef8793c5bb1ad844b6a44677cacca30447abf Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Sun, 26 Sep 2021 13:14:41 -0400 Subject: [PATCH] Breaking: Update `report-message-format` to also apply to suggestion messages --- lib/rules/report-message-format.js | 13 +++++++--- tests/lib/rules/report-message-format.js | 33 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/rules/report-message-format.js b/lib/rules/report-message-format.js index 343f46af..c8deecfb 100644 --- a/lib/rules/report-message-format.js +++ b/lib/rules/report-message-format.js @@ -83,12 +83,19 @@ module.exports = { ) { const reportInfo = utils.getReportInfo(node.arguments, context); const message = reportInfo && reportInfo.message; + const suggest = reportInfo && reportInfo.suggest; - if (!message) { - return; + if (message) { + processMessageNode(message); } - processMessageNode(message); + if (suggest && suggest.type === 'ArrayExpression') { + suggest.elements + .flatMap(obj => obj.properties) + .filter(prop => prop.type === 'Property' && prop.key.type === 'Identifier' && prop.key.name === 'message') + .map(prop => prop.value) + .forEach(processMessageNode); + } } }, }; diff --git a/tests/lib/rules/report-message-format.js b/tests/lib/rules/report-message-format.js index 0dff15ac..1f637d35 100644 --- a/tests/lib/rules/report-message-format.js +++ b/tests/lib/rules/report-message-format.js @@ -109,6 +109,28 @@ ruleTester.run('report-message-format', rule, { `, options: ['^foo$'], }, + { + // Suggestion message + code: ` + module.exports = { + create(context) { + context.report({node, suggest: [{message: 'foo'}]}); + } + }; + `, + options: ['^foo$'], + }, + { + // Suggestion message with ternary expression + code: ` + module.exports = { + create(context) { + context.report({node, suggest: foo ? []: [{}]}); + } + }; + `, + options: ['^foo$'], + }, { code: ` module.exports = { @@ -250,6 +272,17 @@ ruleTester.run('report-message-format', rule, { `, options: ['foo'], }, + { + // Suggestion message + code: ` + module.exports = { + create(context) { + context.report({node, suggest: [{message: 'FOO'}]}); + } + }; + `, + options: ['foo'], + }, { code: ` module.exports = {