Skip to content

Commit

Permalink
WhiteSpace\BraceBlankLine - fixer issue with empty structure
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbundyra committed Jun 8, 2019
1 parent 5df57b6 commit ac227bd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function process(File $phpcsFile, $stackPtr)
}

$closer = $tokens[$stackPtr]['bracket_closer'];
$prev = $phpcsFile->findPrevious(T_WHITESPACE, $closer - 1, null, true);
if ($tokens[$closer]['line'] > $tokens[$prev]['line'] + 1) {
$prev = $phpcsFile->findPrevious(T_WHITESPACE, $closer - 1, $stackPtr + 1, true);
if ($prev && $tokens[$closer]['line'] > $tokens[$prev]['line'] + 1) {
$error = 'Blank line found before closing brace';
$fix = $phpcsFile->addFixableError($error, $closer, 'SpacingBeforeClose');

Expand Down
6 changes: 6 additions & 0 deletions test/Sniffs/WhiteSpace/BraceBlankLineUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,9 @@ if (true) {
// comment here

}

try {
new DateTime();
} catch (Throwable $th) {

}
5 changes: 5 additions & 0 deletions test/Sniffs/WhiteSpace/BraceBlankLineUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,8 @@ $a{1};
if (true) {
// comment here
}

try {
new DateTime();
} catch (Throwable $th) {
}
1 change: 1 addition & 0 deletions test/Sniffs/WhiteSpace/BraceBlankLineUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected function getErrorList(string $testFile = '') : array
127 => 1,
131 => 1,
135 => 1,
139 => 1,
];
}

Expand Down

0 comments on commit ac227bd

Please sign in to comment.