Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion packages/eslint-plugin/lib/rules/lowercase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/**
* @import {Tag, StyleTag, ScriptTag} from "@html-eslint/types";
* @import {
* Tag,
* StyleTag,
* ScriptTag,
* Doctype,
* } from "@html-eslint/types";
* @import {RuleModule} from "../types";
*/

Expand Down Expand Up @@ -128,6 +133,48 @@ module.exports = {
}
}

/**
* @param {Doctype} doctype
*/
function checkDoctype(doctype) {
if (doctype.open.value !== doctype.open.value.toLowerCase()) {
context.report({
node: doctype.open,
messageId: MESSAGE_IDS.UNEXPECTED,
data: {
name: doctype.open.value.slice(1),
},
fix(fixer) {
return fixer.replaceTextRange(doctype.open.range, "<!doctype");
},
});
}
if (doctype.attributes && doctype.attributes.length) {
doctype.attributes.forEach((attribute) => {
if (
attribute.value &&
attribute.value.value !== attribute.value.value.toLowerCase()
) {
context.report({
node: attribute.value,
messageId: MESSAGE_IDS.UNEXPECTED,
data: {
name: attribute.value.value,
},
fix(fixer) {
return fixer.replaceText(
// @ts-ignore
attribute.value,
// @ts-ignore
attribute.value.value.toLowerCase()
);
},
});
}
});
}
}

return createVisitors(context, {
Tag(node) {
if (node.name.toLocaleLowerCase() === "svg") {
Expand All @@ -142,6 +189,7 @@ module.exports = {
},
StyleTag: check,
ScriptTag: check,
Doctype: checkDoctype,
});
},
};
21 changes: 21 additions & 0 deletions packages/eslint-plugin/tests/rules/lowercase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ ruleTester.run("lowercase", rule, {
</svg>
`,
},
{
code: `<!doctype html>`,
},
{
code: "<div {{ID}}></div>",
languageOptions: {
Expand Down Expand Up @@ -127,6 +130,24 @@ ruleTester.run("lowercase", rule, {
},
],
},
{
code: `<!DOCTYPE html>`,
output: `<!doctype html>`,
errors: [
{
message: "'!DOCTYPE' is not in lowercase.",
},
],
},
{
code: `<!doctype HTML>`,
output: `<!doctype html>`,
errors: [
{
message: "'HTML' is not in lowercase.",
},
],
},
{
code: "<div ID={{ID}}></div>",
output: "<div id={{ID}}></div>",
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/scripts/playground/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function escapeHTML(str) {
.replace(/>/g, "&gt;");
}

export const INITIAL_HTML = html`<!DOCTYPE html>
export const INITIAL_HTML = html`<!doctype html>
<html>
<head>
</head>
Expand Down