Skip to content

Commit

Permalink
Fix: html-end-tags don't fail for self-closing elements (#221)
Browse files Browse the repository at this point in the history
* Add test case

* Fix html-end-tags for self closing elements

* Add self closing example in html-end-tags doc
  • Loading branch information
mariolamacchia authored and mysticatea committed Oct 27, 2017
1 parent 0a8eb8e commit 43f248b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/rules/html-end-tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This rule reports the following elements:
<div></div>
<p></p>
<p></p>
<div />
<input>
<br>
</div>
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/html-end-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function create (context) {
const name = node.name
const isVoid = utils.isHtmlVoidElementName(name)
const hasEndTag = node.endTag != null
const isSelfClosing = node.startTag.selfClosing

if (isVoid && hasEndTag) {
context.report({
Expand All @@ -37,7 +38,7 @@ function create (context) {
fix: (fixer) => fixer.remove(node.endTag)
})
}
if (!isVoid && !hasEndTag) {
if (!isVoid && !(hasEndTag || isSelfClosing)) {
context.report({
node: node.startTag,
loc: node.startTag.loc,
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/html-end-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ tester.run('html-end-tags', rule, {
{
filename: 'test.vue',
code: '<template><div><img></div></template>'
},
{
filename: 'test.vue',
code: '<template><div><div /></div></template>'
}
],
invalid: [
Expand Down

0 comments on commit 43f248b

Please sign in to comment.