Commit 2aaddc2d authored by David Sveningsson's avatar David Sveningsson

fix(rules): `no-trailing-whitespace` handles CRLF (windows) newlines

fixes #93
parent a2579400
Pipeline #158468546 passed with stages
in 9 minutes and 37 seconds
......@@ -10,34 +10,48 @@ describe("rule no-trailing-whitespace", () => {
});
});
it("should not report when there is no trailing whitespace", () => {
expect.assertions(1);
const report = htmlvalidate.validateString("<div>\n foo\n</div>");
expect(report).toBeValid();
});
describe.each`
newline | description
${"\n"} | ${"LR"}
${"\r\n"} | ${"CRLF"}
`("$description", ({ newline }) => {
it("should not report when there is no trailing whitespace", () => {
expect.assertions(1);
const report = htmlvalidate.validateString(
`<div>${newline} foo${newline}</div>`
);
expect(report).toBeValid();
});
it("should report error when tag have trailing whitespace", () => {
expect.assertions(2);
const report = htmlvalidate.validateString("<p> \n</p>");
expect(report).toBeInvalid();
expect(report).toHaveError("no-trailing-whitespace", "Trailing whitespace");
});
it("should report error when tag have trailing whitespace", () => {
expect.assertions(2);
const report = htmlvalidate.validateString(`<p> ${newline}</p>`);
expect(report).toBeInvalid();
expect(report).toHaveError(
"no-trailing-whitespace",
"Trailing whitespace"
);
});
it("should report error when empty line have trailing whitespace", () => {
expect.assertions(2);
const report = htmlvalidate.validateString("<p>\n \n</p>");
expect(report).toBeInvalid();
expect(report).toHaveError("no-trailing-whitespace", "Trailing whitespace");
});
it("should report error when empty line have trailing whitespace", () => {
expect.assertions(2);
const report = htmlvalidate.validateString(`<p>${newline} \n</p>`);
expect(report).toBeInvalid();
expect(report).toHaveError(
"no-trailing-whitespace",
"Trailing whitespace"
);
});
it("should report error for both tabs and spaces", () => {
expect.assertions(2);
const report = htmlvalidate.validateString("<p>\n \n\t\n</p>");
expect(report).toBeInvalid();
expect(report).toHaveErrors([
["no-trailing-whitespace", "Trailing whitespace"],
["no-trailing-whitespace", "Trailing whitespace"],
]);
it("should report error for both tabs and spaces", () => {
expect.assertions(2);
const report = htmlvalidate.validateString("<p>\n \n\t\n</p>");
expect(report).toBeInvalid();
expect(report).toHaveErrors([
["no-trailing-whitespace", "Trailing whitespace"],
["no-trailing-whitespace", "Trailing whitespace"],
]);
});
});
it("smoketest", () => {
......
......@@ -12,7 +12,7 @@ export default class NoTrailingWhitespace extends Rule {
public setup(): void {
this.on("whitespace", (event: WhitespaceEvent) => {
if (event.text.match(/^[ \t]+\n$/)) {
if (event.text.match(/^[ \t]+\r?\n$/)) {
this.report(undefined, "Trailing whitespace", event.location);
}
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment