-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Change Request: Always check data for message in rule tester #18016
Comments
I think this is a fantastic idea that makes sense in the context of the other |
Can you clarify what exactly will be checked? Would it be a check for the presence of a |
That's my understanding, yes. This would represent an un-interpolated placeholder string. |
The only extra check I can think of for this situation is additional (= unused in the message) if ("data" in error) {
// ...existing error handling
} else {
const dataKeys = Object.keys(message.data);
const placeholders = getPlaceholderNames(messages[messageId]);
const missing = placeholders.filters((placeholder) => dataKeys.includes(placeholder));
assert.strictEqual(missing, [], `The error message is missing data for the placeholders "${missing.join(', ')". Please either provide them in the respective context.report call or remove/rename the placeholders in the message.`)
} The logic for the case with |
There's no But we could look for a |
Per 2024-02-08 |
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:
This is especially helpful as with the upcoming stricter rule tests as
message
cannot be set withmessageId
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
Additional comments
I proposed this as a part of stricter rule tester testing in #17654 .
The text was updated successfully, but these errors were encountered: