From 9394f886c3c733641941b53a4db784574b65375e Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 11 Jun 2019 13:18:17 +0000 Subject: [PATCH 1/3] MULTISITE-21477: Whitespace colon fixer. --- .../QualityAssurance/Sniffs/Theming/WhiteSpaceSniff.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phpcs/Standards/QualityAssurance/Sniffs/Theming/WhiteSpaceSniff.php b/phpcs/Standards/QualityAssurance/Sniffs/Theming/WhiteSpaceSniff.php index 3b078df..5357763 100644 --- a/phpcs/Standards/QualityAssurance/Sniffs/Theming/WhiteSpaceSniff.php +++ b/phpcs/Standards/QualityAssurance/Sniffs/Theming/WhiteSpaceSniff.php @@ -78,7 +78,10 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) // Check if element 3 positions before closing PHP tag is a whitespace. if ($nonSpace['type'] === 'T_WHITESPACE') { $error = "There shouldn't be any whitespace found before the colon."; - $phpcsFile->addError($error, $stackPtr, 'WhiteSpaceFound', true); + $fix = $phpcsFile->addFixableError($error, ($tagClose - 3), 'WhiteSpaceFound'); + if ($fix === true) { + $phpcsFile->fixer->replaceToken(($tagClose - 3), ''); + } } } }//end process() From 790868471e5334a4175b00c44b31ac073673b7bf Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Wed, 12 Jun 2019 13:41:22 +0000 Subject: [PATCH 2/3] MULTISITE-21477: Add fixer for other two errors. --- .../Sniffs/Theming/WhiteSpaceSniff.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/phpcs/Standards/QualityAssurance/Sniffs/Theming/WhiteSpaceSniff.php b/phpcs/Standards/QualityAssurance/Sniffs/Theming/WhiteSpaceSniff.php index 4ec1cb3..7c1f150 100644 --- a/phpcs/Standards/QualityAssurance/Sniffs/Theming/WhiteSpaceSniff.php +++ b/phpcs/Standards/QualityAssurance/Sniffs/Theming/WhiteSpaceSniff.php @@ -65,14 +65,20 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) // Check for missing whitespace before closing PHP tag. if ($beforeClosePhp['type'] !== 'T_WHITESPACE') { $error = "Missing white space before closing php tag."; - $phpcsFile->addError($error, $stackPtr, 'MissingWhiteSpace', true); + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'MissingWhiteSpace'); + if ($fix === true) { + $phpcsFile->fixer->addContent(($stackPtr -1), ' '); + } } // Check for existent whitespace lenght. if ($beforeClosePhp['type'] === 'T_WHITESPACE' && $beforeClosePhp['line'] === $tokens[$tagBeforeWhtsp]['line'] && $beforeClosePhp['length'] > 1) { $error = "There should be just one white space before the closing php tag."; - $phpcsFile->addError($error, $stackPtr, 'MultipleWhiteSpaces', true); + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'MultipleWhiteSpaces'); + if ($fix === true) { + $phpcsFile->fixer->replaceToken(($stackPtr -1), ' '); + } } // Check if element 2 positions before closing PHP tag is a colon. From 844b9a6e324ab3826108c43701c22a93758b18b9 Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Wed, 12 Jun 2019 13:54:05 +0000 Subject: [PATCH 3/3] MULTISITE-21477: Add fixed test files. --- .../Theming/WhiteSpaceError.fixed.tpl.php | 20 +++++++++++++++++++ .../Tests/Theming/WhiteSpaceUnitTest.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 phpcs/Standards/QualityAssurance/Tests/Theming/WhiteSpaceError.fixed.tpl.php diff --git a/phpcs/Standards/QualityAssurance/Tests/Theming/WhiteSpaceError.fixed.tpl.php b/phpcs/Standards/QualityAssurance/Tests/Theming/WhiteSpaceError.fixed.tpl.php new file mode 100644 index 0000000..a24ac78 --- /dev/null +++ b/phpcs/Standards/QualityAssurance/Tests/Theming/WhiteSpaceError.fixed.tpl.php @@ -0,0 +1,20 @@ + + + + + + $picture['thumb_img_url'], + 'alt' => $picture['description'], + 'title' => $picture['description'], + 'width' => '', + 'height' => '', + 'attributes' => array(), + )); +?> diff --git a/phpcs/Standards/QualityAssurance/Tests/Theming/WhiteSpaceUnitTest.php b/phpcs/Standards/QualityAssurance/Tests/Theming/WhiteSpaceUnitTest.php index 0d92d3b..e6b24cc 100644 --- a/phpcs/Standards/QualityAssurance/Tests/Theming/WhiteSpaceUnitTest.php +++ b/phpcs/Standards/QualityAssurance/Tests/Theming/WhiteSpaceUnitTest.php @@ -44,7 +44,7 @@ public function getWarningList($testFile) */ public function getTestFiles() { return array( - 'WhiteSpaceError.tpl.php' => '', + 'WhiteSpaceError.tpl.php' => 'WhiteSpaceError.fixed.tpl.php', ); }// end getTestFiles()