-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
feat!: Rule Tester checks for missing placeholder data in the message #18073
Changes from 1 commit
5895060
c881a45
d354d58
a10b636
494317e
a39edf7
e1b49fc
5ee4d25
22ee891
600da81
c636cdd
9e4030c
5483b37
b7a82af
1305386
371fa25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ta properties
- Loading branch information
There are no files selected for viewing
DMartens marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1907,13 +1907,22 @@ describe("RuleTester", () => { | |
}, "Hydrated message \"Avoid using variables named 'notFoo'.\" does not match \"Avoid using variables named 'foo'.\""); | ||
}); | ||
|
||
it("should throw if the message has missing placeholders when data is not specified", () => { | ||
it("should throw if the message has a single missing placeholders when data is not specified", () => { | ||
assert.throws(() => { | ||
ruleTester.run("foo", require("../../fixtures/testers/rule-tester/messageId").withMissingData, { | ||
valid: [], | ||
invalid: [{ code: "foo", errors: [{ messageId: "avoidFoo" }] }] | ||
}); | ||
}, "The reported message has missing placeholders: name. Please provide them via the 'data' property in the context.report call"); | ||
}, "The reported message has a missing placeholder 'name'. Please provide them via the 'data' property in the context.report() call."); | ||
}); | ||
|
||
it("should throw if the message has multiple missing placeholders when data is not specified", () => { | ||
assert.throws(() => { | ||
ruleTester.run("foo", require("../../fixtures/testers/rule-tester/messageId").withMultipleMissingDataProperties, { | ||
valid: [], | ||
invalid: [{ code: "foo", errors: [{ messageId: "avoidFoo" }] }] | ||
}); | ||
}, "The reported message has the missing placeholders: 'type', 'name'. Please provide them via the 'data' property in the context.report() call."); | ||
}); | ||
|
||
it("should throw if the data in the message contains placeholders", () => { | ||
|
@@ -1922,7 +1931,7 @@ describe("RuleTester", () => { | |
valid: [], | ||
invalid: [{ code: "foo", errors: [{ messageId: "avoidFoo" }] }] | ||
}); | ||
}, "The reported message has missing placeholders: placeholder. Please provide them via the 'data' property in the context.report call"); | ||
}, "The reported message has a missing placeholder 'placeholder'. Please provide them via the 'data' property in the context.report() call."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error message seems misleading since, as @mdjermanovic said, we don't want to suggest that recursive/multipass interpolation is allowed. If there was some way to escape placeholders in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When only |
||
}); | ||
|
||
// messageId/message misconfiguration cases | ||
|
@@ -2176,7 +2185,7 @@ describe("RuleTester", () => { | |
}); | ||
}); | ||
|
||
it("should fail with missing data placeholders when data is not specified", () => { | ||
it("should fail with a single missing data placeholder when data is not specified", () => { | ||
assert.throws(() => { | ||
ruleTester.run("suggestions-messageIds", require("../../fixtures/testers/rule-tester/suggestions").withMissingPlaceholderData, { | ||
valid: [], | ||
|
@@ -2191,7 +2200,25 @@ describe("RuleTester", () => { | |
}] | ||
}] | ||
}); | ||
}, "The message of the suggestion has missing placeholders: newName. Please provide them via the 'data' property for the suggestion in the context.report call"); | ||
}, "The message of the suggestion has a missing placeholder 'newName'. Please provide them via the 'data' property for the suggestion in the context.report() call."); | ||
}); | ||
|
||
it("should fail with multiple missing data placeholders when data is not specified", () => { | ||
assert.throws(() => { | ||
ruleTester.run("suggestions-messageIds", require("../../fixtures/testers/rule-tester/suggestions").withMultipleMissingPlaceholderDataProperties, { | ||
valid: [], | ||
invalid: [{ | ||
code: "var foo;", | ||
errors: [{ | ||
messageId: "avoidFoo", | ||
suggestions: [{ | ||
messageId: "rename", | ||
output: "var bar;" | ||
}] | ||
}] | ||
}] | ||
}); | ||
}, "The message of the suggestion has the missing placeholders: 'currentName', 'newName'. Please provide them via the 'data' property for the suggestion in the context.report() call."); | ||
}); | ||
|
||
it("should fail when tested using empty suggestion test objects even if the array length is correct", () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think this regexp should be exported by a shared util file so it can be used in multiple places.