Skip to content

Commit

Permalink
fix: handle spread in context.report() in require-meta-has-suggestions (
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Aug 12, 2022
1 parent 01d0eef commit fdffb50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/rules/require-meta-has-suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 12 additions & 2 deletions tests/lib/rules/require-meta-has-suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ ruleTester.run('require-meta-has-suggestions', rule, {
}
};
`,
// Unrelated spread syntax.
// Unrelated spread syntax in rule.
{
code: `
const extra = {};
Expand All @@ -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 = {
Expand All @@ -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: [
Expand Down

0 comments on commit fdffb50

Please sign in to comment.