Skip to content

Commit

Permalink
Merge pull request #51 from ec-europa/feature/MULTISITE-21477
Browse files Browse the repository at this point in the history
MULTISITE-21477: Whitespace colon fixer.
  • Loading branch information
jonhy81 authored Jun 20, 2019
2 parents 8823030 + 844b9a6 commit c1deefa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -82,7 +88,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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* @file
* Default theme implementation to display a file.
*/
?>
<?php print $id; ?>
<?php if (isset($classes['something'])): ?><?php print $classes; ?>
<?php endif; ?>
<?php print $attributes; ?>
<?php
print theme('image', array(
'path' => $picture['thumb_img_url'],
'alt' => $picture['description'],
'title' => $picture['description'],
'width' => '',
'height' => '',
'attributes' => array(),
));
?>
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit c1deefa

Please sign in to comment.