Skip to content

Commit

Permalink
Correct indentation when auto-fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed May 26, 2023
1 parent ca0ebae commit 0f21272
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public function process(File $phpcsFile, $stackPtr): void
$original = $token['content'];
$replacement = str_replace(' />', '>', $original);
$replacement = str_replace('/>', '>', $replacement);

if (preg_match('{^\s* />}', $original)) {
$replacement = ' ' . $replacement;
}

$phpcsFile->fixer->replaceToken($ptr, $replacement);
}
}
Expand Down
5 changes: 5 additions & 0 deletions Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public function process(File $phpcsFile, $stackPtr)
$original = $token['content'];
$replacement = str_replace(' />', '></' . $match[1] . '>', $original);
$replacement = str_replace('/>', '></' . $match[1] . '>', $replacement);

if (preg_match('{^\s* />}', $original)) {
$replacement = ' ' . $replacement;
}

$phpcsFile->fixer->replaceToken($ptr, $replacement);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<input type="text"
id="multi-line-input"
placeholder="Alert should be on last line"
>
>
<input type="text"
id="multi-line-input2"
placeholder="Alert should be on last line">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<label for="test_input"></label>
<label
for="multi-line-input"
></label>
></label>
<label
for="multi-line-input2"></label>
<style type="text/css"></style>
Expand Down

0 comments on commit 0f21272

Please sign in to comment.