Skip to content

Commit 43f248b

Browse files
mariolamacchiamysticatea
authored andcommitted
Fix: html-end-tags don't fail for self-closing elements (#221)
* Add test case * Fix html-end-tags for self closing elements * Add self closing example in html-end-tags doc
1 parent 0a8eb8e commit 43f248b

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

docs/rules/html-end-tags.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ This rule reports the following elements:
3636
<div></div>
3737
<p></p>
3838
<p></p>
39+
<div />
3940
<input>
4041
<br>
4142
</div>

lib/rules/html-end-tags.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function create (context) {
2727
const name = node.name
2828
const isVoid = utils.isHtmlVoidElementName(name)
2929
const hasEndTag = node.endTag != null
30+
const isSelfClosing = node.startTag.selfClosing
3031

3132
if (isVoid && hasEndTag) {
3233
context.report({
@@ -37,7 +38,7 @@ function create (context) {
3738
fix: (fixer) => fixer.remove(node.endTag)
3839
})
3940
}
40-
if (!isVoid && !hasEndTag) {
41+
if (!isVoid && !(hasEndTag || isSelfClosing)) {
4142
context.report({
4243
node: node.startTag,
4344
loc: node.startTag.loc,

tests/lib/rules/html-end-tags.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ tester.run('html-end-tags', rule, {
4646
{
4747
filename: 'test.vue',
4848
code: '<template><div><img></div></template>'
49+
},
50+
{
51+
filename: 'test.vue',
52+
code: '<template><div><div /></div></template>'
4953
}
5054
],
5155
invalid: [

0 commit comments

Comments
 (0)