From 0f21272e5364bfe0bf9a4cdf404c99155c2cbb81 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Fri, 26 May 2023 12:26:14 +0100 Subject: [PATCH] Correct indentation when auto-fixing --- Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php | 5 +++++ Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php | 5 +++++ Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed | 2 +- Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc.fixed | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php b/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php index 90144639..6c8a67f2 100644 --- a/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php +++ b/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php @@ -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); } } diff --git a/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php b/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php index 5fd75e3d..7c3cf9bc 100644 --- a/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php +++ b/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php @@ -84,6 +84,11 @@ public function process(File $phpcsFile, $stackPtr) $original = $token['content']; $replacement = str_replace(' />', '>', $original); $replacement = str_replace('/>', '>', $replacement); + + if (preg_match('{^\s* />}', $original)) { + $replacement = ' ' . $replacement; + } + $phpcsFile->fixer->replaceToken($ptr, $replacement); } } diff --git a/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed b/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed index 0b04c24f..42b503a0 100644 --- a/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed +++ b/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed @@ -25,7 +25,7 @@ + > diff --git a/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc.fixed b/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc.fixed index cf12aa1b..38f04704 100644 --- a/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc.fixed +++ b/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc.fixed @@ -40,7 +40,7 @@ + >