Skip to content

Commit 8752629

Browse files
committed
Update list of void elements
1 parent ffd4818 commit 8752629

6 files changed

+12
-17
lines changed

Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ class HtmlClosingVoidTagsSniff implements Sniff
4444
'col',
4545
'embed',
4646
'hr',
47+
'img',
4748
'input',
48-
'keygen',
4949
'link',
50-
'menuitem',
5150
'meta',
52-
'param',
5351
'source',
5452
'track',
55-
'wbr'
53+
'wbr',
5654
];
5755

5856
/**

Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
class HtmlSelfClosingTagsSniff implements Sniff
1818
{
1919
/**
20-
* List of void elements
20+
* List of void elements.
2121
*
22-
* https://www.w3.org/TR/html51/syntax.html#writing-html-documents-elements
22+
* https://html.spec.whatwg.org/multipage/syntax.html#void-elements
2323
*
2424
* @var string[]
2525
*/
26-
private $voidElements = [
26+
private const HTML_VOID_ELEMENTS = [
2727
'area',
2828
'base',
2929
'br',
@@ -32,11 +32,8 @@ class HtmlSelfClosingTagsSniff implements Sniff
3232
'hr',
3333
'img',
3434
'input',
35-
'keygen',
3635
'link',
37-
'menuitem',
3836
'meta',
39-
'param',
4037
'source',
4138
'track',
4239
'wbr',
@@ -70,7 +67,7 @@ public function process(File $phpcsFile, $stackPtr)
7067

7168
if (preg_match_all('$<(\w{2,})\s?[^<]*\/>$', $html, $matches, PREG_SET_ORDER)) {
7269
foreach ($matches as $match) {
73-
if (!in_array($match[1], $this->voidElements)) {
70+
if (!in_array($match[1], self::HTML_VOID_ELEMENTS)) {
7471
$phpcsFile->addError(
7572
'Avoid using self-closing tag with non-void html element'
7673
. ' - "' . $match[0] . PHP_EOL,

Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
<hr/>
2323
<img src="" alt=""/>
2424
<input type="text" id="test_input"/>
25-
<keygen/>
2625
<link/>
2726
<meta/>
28-
<param name="" value=""/>
2927
<video>
3028
<source/>
3129
<track src=""/>

Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public function getErrorList()
2222
*/
2323
public function getWarningList()
2424
{
25-
return [1 => 15];
25+
return [
26+
1 => 14,
27+
];
2628
}
2729
}

Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
<hr/>
2323
<img src="" alt=""/>
2424
<input type="text" id="test_input"/>
25-
<keygen/>
2625
<link/>
2726
<meta/>
28-
<param name="" value=""/>
2927
<video>
3028
<source/>
3129
<track src=""/>

Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class HtmlSelfClosingTagsUnitTest extends AbstractSniffUnitTest
1414
*/
1515
public function getErrorList()
1616
{
17-
return [1 => 9];
17+
return [
18+
1 => 9,
19+
];
1820
}
1921

2022
/**

0 commit comments

Comments
 (0)