-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify no-unclosed-tag
rule
#340
base: master
Are you sure you want to change the base?
Changes from 2 commits
dfbbfae
e0bda3c
53f7b56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,41 @@ tsTest("Report unclosed tags", t => { | |
hasDiagnostic(t, diagnostics, "no-unclosed-tag"); | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In an ideal world, we might want to allow: <p>One
<p>Two Or just: <p>Hi And we'd want to put warnings on dangling closing tags that don't match up to any opening tags. All of those may be somewhat tricky to do with how parse5 represents the tree though, requiring us to notice spans in the original text that aren't represented in the parsed tree. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are very tricky, and another good case to add to an issue for followup. Philosophically though, I wonder if the lit-analyzer should avoid HTML diagnostics and leave that to an HTML specific tool. It may even be worth scoping the |
||
tsTest("Don't report self closed tags", t => { | ||
tsTest("Don't report void elements", t => { | ||
const { diagnostics } = getDiagnostics("html`<img>`", { rules: { "no-unclosed-tag": true } }); | ||
hasNoDiagnostics(t, diagnostics); | ||
}); | ||
|
||
tsTest("Don't report void elements with self closing syntax", t => { | ||
const { diagnostics } = getDiagnostics("html`<img />`", { rules: { "no-unclosed-tag": true } }); | ||
hasNoDiagnostics(t, diagnostics); | ||
}); | ||
|
||
// The `<p>` tag will be closed automatically if immediately followed by a lot of other elements, | ||
// including `<div>`. | ||
// Ref: https://html.spec.whatwg.org/multipage/grouping-content.html#the-p-element | ||
tsTest("Report unclosed 'p' tag that was implicitly closed via tag omission", t => { | ||
const { diagnostics } = getDiagnostics("html`<p><div></div></p>`", { rules: { "no-unclosed-tag": true } }); | ||
hasDiagnostic(t, diagnostics, "no-unclosed-tag"); | ||
}); | ||
|
||
tsTest("Report unclosed 'p' tag that is implicitly closed via tag omission containing text content", t => { | ||
const { diagnostics } = getDiagnostics("html`<p>Unclosed Content<div></div></p>`", { rules: { "no-unclosed-tag": true } }); | ||
hasDiagnostic(t, diagnostics, "no-unclosed-tag"); | ||
}); | ||
|
||
// Self-closing tags do not exist in HTML. They are only valid in SVG and MathML. | ||
tsTest("Report non-void element using self closing syntax", t => { | ||
const { diagnostics } = getDiagnostics("html`<p /><div></div>`", { rules: { "no-unclosed-tag": true } }); | ||
hasDiagnostic(t, diagnostics, "no-unclosed-tag"); | ||
}); | ||
|
||
tsTest("Report self closing 'p' tag containing text content", t => { | ||
const { diagnostics } = getDiagnostics("html`<p />Unclosed Content<div></div>`", { rules: { "no-unclosed-tag": true } }); | ||
hasDiagnostic(t, diagnostics, "no-unclosed-tag"); | ||
}); | ||
|
||
tsTest("Don't report explicit closing 'p' tag containing text content", t => { | ||
const { diagnostics } = getDiagnostics("html`<p>Unclosed Content</p><div></div>`", { rules: { "no-unclosed-tag": true } }); | ||
hasNoDiagnostics(t, diagnostics); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we warn on an invalid closing element for a void element? Seems like it'd be good to do so. For example, this should be a warning on the
</input>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good idea but maybe something we can add incrementally to the
no-unclosed-tag
diagnostic.I'll make an issue.