Skip to content

Improve developer experience with closing tags #435

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

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove space before self-close when auto-fixed
  • Loading branch information
fredden committed Feb 2, 2023
commit 809cfabe1928ad5accabd0e5e6bda2e036bade3d
3 changes: 2 additions & 1 deletion Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function process(File $phpcsFile, $stackPtr): void
if ($fix) {
$token = $phpcsFile->getTokens()[$ptr];
$original = $match[0];
$replacement = str_replace('/>', '>', $original);
$replacement = str_replace(' />', '>', $original);
$replacement = str_replace('/>', '>', $replacement);
$phpcsFile->fixer->replaceToken(
$ptr,
str_replace($original, $replacement, $token['content'])
Expand Down
3 changes: 2 additions & 1 deletion Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public function process(File $phpcsFile, $stackPtr)
if ($fix) {
$token = $phpcsFile->getTokens()[$ptr];
$original = $match[0];
$replacement = str_replace('/>', '></' . $match[1] . '>', $original);
$replacement = str_replace(' />', '></' . $match[1] . '>', $original);
$replacement = str_replace('/>', '></' . $match[1] . '>', $replacement);
$phpcsFile->fixer->replaceToken(
$ptr,
str_replace($original, $replacement, $token['content'])
Expand Down
1 change: 1 addition & 0 deletions Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
</video>
<wbr/>
<hr/>
<hr style="color: red" />
</body>
</html>
1 change: 1 addition & 0 deletions Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
</video>
<wbr>
<hr>
<hr style="color: red">
</body>
</html>
1 change: 1 addition & 0 deletions Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function getWarningList()
29 => 1,
31 => 1,
32 => 1,
33 => 1,
];
}
}
1 change: 1 addition & 0 deletions Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
<translate/>
<scope/>
<span/>
<span style="color: red" />
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
<translate></translate>
<scope></scope>
<span></span>
<span style="color: red"></span>
</body>
</html>
1 change: 1 addition & 0 deletions Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function getErrorList()
40 => 1,
41 => 1,
42 => 1,
43 => 1,
];
}

Expand Down