Loading docs/rules/__tests__/__snapshots__/no-trailing-whitespace.md.spec.ts.snap +1 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ exports[`docs/rules/no-trailing-whitespace.md inline validation: incorrect 1`] = "messages": [ { "column": 19, "fix": [Function], "line": 1, "message": "Trailing whitespace", "offset": 18, Loading src/rules/no-trailing-whitespace.spec.ts +9 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,15 @@ describe("rule no-trailing-whitespace", () => { ["no-trailing-whitespace", "Trailing whitespace"], ]); }); it("should remove trailing whitespace but keep the newline", async () => { expect.assertions(1); const markup = /* RAW */ `<p> ${newline}</p>`; const report = await htmlvalidate.validateString(markup); const [message] = report.results[0].messages; const result = await htmlvalidate.autofixString("inline", markup, message.fix!); expect(result).toBe(`<p>${newline}</p>`); }); }); it("smoketest", async () => { Loading src/rules/no-trailing-whitespace.ts +13 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ import { type WhitespaceEvent } from "../event"; import { type RuleDocumentation, Rule, ruleDocumentationUrl } from "../rule"; export default class NoTrailingWhitespace extends Rule { public static override readonly fixable = true; public override documentation(): RuleDocumentation { return { description: Loading @@ -12,9 +14,18 @@ export default class NoTrailingWhitespace extends Rule { public setup(): void { this.on("whitespace", (event: WhitespaceEvent) => { if (/^[\t ]+\r?\n$/.test(event.text)) { this.report(null, "Trailing whitespace", event.location); const match = /^[\t ]+(\r?\n)$/.exec(event.text); if (!match) { return; } this.report({ node: null, message: "Trailing whitespace", location: event.location, fix(fixer) { fixer.replaceText(event.location, match[1]); }, }); }); } } Loading
docs/rules/__tests__/__snapshots__/no-trailing-whitespace.md.spec.ts.snap +1 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ exports[`docs/rules/no-trailing-whitespace.md inline validation: incorrect 1`] = "messages": [ { "column": 19, "fix": [Function], "line": 1, "message": "Trailing whitespace", "offset": 18, Loading
src/rules/no-trailing-whitespace.spec.ts +9 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,15 @@ describe("rule no-trailing-whitespace", () => { ["no-trailing-whitespace", "Trailing whitespace"], ]); }); it("should remove trailing whitespace but keep the newline", async () => { expect.assertions(1); const markup = /* RAW */ `<p> ${newline}</p>`; const report = await htmlvalidate.validateString(markup); const [message] = report.results[0].messages; const result = await htmlvalidate.autofixString("inline", markup, message.fix!); expect(result).toBe(`<p>${newline}</p>`); }); }); it("smoketest", async () => { Loading
src/rules/no-trailing-whitespace.ts +13 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ import { type WhitespaceEvent } from "../event"; import { type RuleDocumentation, Rule, ruleDocumentationUrl } from "../rule"; export default class NoTrailingWhitespace extends Rule { public static override readonly fixable = true; public override documentation(): RuleDocumentation { return { description: Loading @@ -12,9 +14,18 @@ export default class NoTrailingWhitespace extends Rule { public setup(): void { this.on("whitespace", (event: WhitespaceEvent) => { if (/^[\t ]+\r?\n$/.test(event.text)) { this.report(null, "Trailing whitespace", event.location); const match = /^[\t ]+(\r?\n)$/.exec(event.text); if (!match) { return; } this.report({ node: null, message: "Trailing whitespace", location: event.location, fix(fixer) { fixer.replaceText(event.location, match[1]); }, }); }); } }