Skip to content

Commit

Permalink
Allow empty {} on single line in Squiz.WhiteSpace.ScopeClosingBrace.C…
Browse files Browse the repository at this point in the history
…ontentBefore

Allows non-awkward single line syntax for empty functions/classes.

Fixes one of the cases mentioned in squizlabs#1580.
  • Loading branch information
tgr committed Oct 8, 2017
1 parent 1eb9067 commit 41dee00
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ public function process(File $phpcsFile, $stackPtr)
$scopeStart = $tokens[$stackPtr]['scope_opener'];
$scopeEnd = $tokens[$stackPtr]['scope_closer'];

// Check that the closing brace is on it's own line.
// Check that the closing brace is on it's own line. Empty {} is always allowed.
$lastContent = $phpcsFile->findPrevious(array(T_INLINE_HTML, T_WHITESPACE, T_OPEN_TAG), ($scopeEnd - 1), $scopeStart, true);
if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) {
if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']
&& $scopeEnd !== ($scopeStart + 1)
) {
$error = 'Closing brace must be on a line by itself';
$fix = $phpcsFile->addFixableError($error, $scopeEnd, 'ContentBefore');
if ($fix === true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ class Test
{
}

function test2() {}
function test2() {foo();}

private function _test3()
function test3() {}

private function _test4()
{
}

Expand Down Expand Up @@ -92,6 +94,8 @@ switch ($blah) {
<?php
public function foo()
{
$foo('description', function () {});

$foo('some
long description', function () {
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ class Test
{
}

function test2() {
function test2() {foo();
}

private function _test3()
function test3() {}

private function _test4()
{
}

Expand Down Expand Up @@ -93,6 +95,8 @@ switch ($blah) {
<?php
public function foo()
{
$foo('description', function () {});

$foo('some
long description', function () {
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function getErrorList()
return array(
11 => 1,
13 => 1,
24 => 1,
80 => 1,
102 => 1,
26 => 1,
82 => 1,
106 => 1,
);

}//end getErrorList()
Expand Down

0 comments on commit 41dee00

Please sign in to comment.