From fdffb501bf62e25bc59a2f960abb0bcc9327e81d Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Fri, 12 Aug 2022 02:33:08 -0400 Subject: [PATCH] fix: handle spread in context.report() in require-meta-has-suggestions (#287) --- lib/rules/require-meta-has-suggestions.js | 6 +++--- tests/lib/rules/require-meta-has-suggestions.js | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/rules/require-meta-has-suggestions.js b/lib/rules/require-meta-has-suggestions.js index 939b5175..44ea702e 100644 --- a/lib/rules/require-meta-has-suggestions.js +++ b/lib/rules/require-meta-has-suggestions.js @@ -49,9 +49,9 @@ module.exports = { (node.arguments.length === 1 && node.arguments[0].type === 'ObjectExpression')) ) { - const suggestProp = node.arguments[0].properties.find( - (prop) => utils.getKeyName(prop) === 'suggest' - ); + const suggestProp = utils + .evaluateObjectProperties(node.arguments[0], scopeManager) + .find((prop) => utils.getKeyName(prop) === 'suggest'); if (suggestProp) { const staticValue = getStaticValue( suggestProp.value, diff --git a/tests/lib/rules/require-meta-has-suggestions.js b/tests/lib/rules/require-meta-has-suggestions.js index fa3adc60..5b2cceff 100644 --- a/tests/lib/rules/require-meta-has-suggestions.js +++ b/tests/lib/rules/require-meta-has-suggestions.js @@ -171,7 +171,7 @@ ruleTester.run('require-meta-has-suggestions', rule, { } }; `, - // Unrelated spread syntax. + // Unrelated spread syntax in rule. { code: ` const extra = {}; @@ -185,7 +185,7 @@ ruleTester.run('require-meta-has-suggestions', rule, { ecmaVersion: 9, }, }, - // Related spread. + // Related spread in meta. ` const extra = { hasSuggestions: true }; module.exports = { @@ -195,6 +195,16 @@ ruleTester.run('require-meta-has-suggestions', rule, { } }; `, + // Spread in report. + ` + module.exports = { + meta: { hasSuggestions: true }, + create(context) { + const extra = { suggest: [{}] }; + context.report({node, message, ...extra }); + } + }; + `, ], invalid: [