Skip to content

Handle spread in context.report() in require-meta-has-suggestions rule #287

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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