Skip to content

Commit

Permalink
feat: skip check when html tag does not exists (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjuan authored Nov 1, 2023
1 parent aba345c commit 952917f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
5 changes: 4 additions & 1 deletion packages/eslint-plugin/lib/rules/require-doctype.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ module.exports = {
Doctype() {
hasDocType = true;
},
"Program:exit"(node) {
"Tag:exit"(node) {
if (node.name !== "html") {
return;
}
if (!hasDocType) {
context.report({
node,
Expand Down
31 changes: 5 additions & 26 deletions packages/eslint-plugin/tests/rules/require-doctype.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ ruleTester.run("require-doctype", rule, {
</html>
`,
},
{
code: `
<div></div>
`,
},
],
invalid: [
{
Expand All @@ -23,32 +28,6 @@ ruleTester.run("require-doctype", rule, {
</html>
`,

errors: [
{
messageId: "missing",
},
],
},
{
code: `<body>
</body>
`,
output: `<!DOCTYPE html>
<body>
</body>
`,

errors: [
{
messageId: "missing",
},
],
},
{
code: ``,
output: `<!DOCTYPE html>
`,

errors: [
{
messageId: "missing",
Expand Down

0 comments on commit 952917f

Please sign in to comment.