Change Request: Always check data for message in rule tester #18016
Description
ESLint version
current
What problem do you want to solve?
Currently the rule tester only checks whether placeholders in messages are replaceable if the data
property is set.
As a result there may be non-replaced placeholders even if this could be caught in the rule teser.
In other words the additional check can assure rule authors that all placeholders for their messages are available.
With the additional check the following can be caught:
// Rule
export default {
messages: {
id: "{{ expected }}"
},
create(context) {
context.report({ messageId: "id", data: { actual: true } });
},
}
// Rule Tester
ruleTester.run("Rule", rule, {
valid: [],
invalid: [{ messageId: "id" }]
});
This is especially helpful as with the upcoming stricter rule tests as message
cannot be set with messageId
to check whether the placeholders are correctly replaced.
What do you think is the correct solution?
Extend the logic for error / suggestion matcher to check whether all placeholders from the referenced message are available if there is no data
property in the matcher.
This should also check that the data
properties are not nullish.
Participation
- I am willing to submit a pull request for this change.
Additional comments
I proposed this as a part of stricter rule tester testing in #17654 .