Loading docs/rules/__tests__/__snapshots__/doctype-html.md.spec.ts.snap +2 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ exports[`docs/rules/doctype-html.md inline validation: incorrect 1`] = ` "messages": [ { "column": 11, "fix": [Function], "line": 1, "message": "doctype should be "html"", "offset": 10, Loading @@ -34,6 +35,7 @@ exports[`docs/rules/doctype-html.md inline validation: legacy 1`] = ` "messages": [ { "column": 11, "fix": [Function], "line": 1, "message": "doctype should be "html"", "offset": 10, Loading src/rules/doctype-html.spec.ts +13 −0 Original line number Diff line number Diff line Loading @@ -60,4 +60,17 @@ describe("rule doctype-html", () => { const docs = await htmlvalidate.getRuleDocumentation("doctype-html"); expect(docs).toMatchSnapshot(); }); describe("autofix", () => { it("should replace legacy doctype with html", async () => { expect.assertions(1); const html = /* eslint-disable-next-line unicorn/prefer-https -- test should ensure this works */ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'; const report = await htmlvalidate.validateString(html); const [message] = report.results[0].messages; const result = await htmlvalidate.autofixString("inline", html, message.fix!); expect(result).toBe("<!DOCTYPE html>"); }); }); }); src/rules/doctype-html.ts +10 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ import { type DoctypeEvent } from "../event"; import { type RuleDocumentation, Rule, ruleDocumentationUrl } from "../rule"; export default class NoStyleTag extends Rule { public static override readonly fixable = true; public override documentation(): RuleDocumentation { return { description: [ Loading @@ -19,7 +21,14 @@ export default class NoStyleTag extends Rule { this.on("doctype", (event: DoctypeEvent) => { const doctype = event.value.toLowerCase(); if (doctype !== "html") { this.report(null, 'doctype should be "html"', event.valueLocation); this.report({ node: null, message: 'doctype should be "html"', location: event.valueLocation, fix(fixer) { fixer.replaceText(event.valueLocation, "html"); }, }); } }); } Loading Loading
docs/rules/__tests__/__snapshots__/doctype-html.md.spec.ts.snap +2 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ exports[`docs/rules/doctype-html.md inline validation: incorrect 1`] = ` "messages": [ { "column": 11, "fix": [Function], "line": 1, "message": "doctype should be "html"", "offset": 10, Loading @@ -34,6 +35,7 @@ exports[`docs/rules/doctype-html.md inline validation: legacy 1`] = ` "messages": [ { "column": 11, "fix": [Function], "line": 1, "message": "doctype should be "html"", "offset": 10, Loading
src/rules/doctype-html.spec.ts +13 −0 Original line number Diff line number Diff line Loading @@ -60,4 +60,17 @@ describe("rule doctype-html", () => { const docs = await htmlvalidate.getRuleDocumentation("doctype-html"); expect(docs).toMatchSnapshot(); }); describe("autofix", () => { it("should replace legacy doctype with html", async () => { expect.assertions(1); const html = /* eslint-disable-next-line unicorn/prefer-https -- test should ensure this works */ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'; const report = await htmlvalidate.validateString(html); const [message] = report.results[0].messages; const result = await htmlvalidate.autofixString("inline", html, message.fix!); expect(result).toBe("<!DOCTYPE html>"); }); }); });
src/rules/doctype-html.ts +10 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ import { type DoctypeEvent } from "../event"; import { type RuleDocumentation, Rule, ruleDocumentationUrl } from "../rule"; export default class NoStyleTag extends Rule { public static override readonly fixable = true; public override documentation(): RuleDocumentation { return { description: [ Loading @@ -19,7 +21,14 @@ export default class NoStyleTag extends Rule { this.on("doctype", (event: DoctypeEvent) => { const doctype = event.value.toLowerCase(); if (doctype !== "html") { this.report(null, 'doctype should be "html"', event.valueLocation); this.report({ node: null, message: 'doctype should be "html"', location: event.valueLocation, fix(fixer) { fixer.replaceText(event.valueLocation, "html"); }, }); } }); } Loading