Skip to content

Commit

Permalink
Fixed bug #1817 : Blank line not enforced after control structure if …
Browse files Browse the repository at this point in the history
…comment on same line as closing brace
  • Loading branch information
gsherwood committed Jan 2, 2018
1 parent 2f5af2d commit a7d4118
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Raúl Arellano for the patch
- Fixed bug #1793 : PSR2 forcing exact indent for function call opening statements
- Fixed bug #1803 : Squiz.WhiteSpace.ScopeKeywordSpacing removes member var name while fixing if no space after scope keyword
- Fixed bug #1817 : Blank line not enforced after control structure if comment on same line as closing brace
</notes>
<contents>
<dir name="/">
Expand Down
1 change: 0 additions & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,6 @@ public function processLongArgument($arg, $pos)
$this->processUnknownArgument('--'.$arg, $pos);
}
}//end if

break;
}//end switch

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public function process(File $phpcsFile, $stackPtr)

if ($tokens[$nextCode]['code'] === T_ELSE
|| $tokens[$nextCode]['code'] === T_ELSEIF
|| $tokens[$trailingContent]['line'] === $tokens[$scopeCloser]['line']
) {
$trailingContent = $nextCode;
}
Expand Down Expand Up @@ -319,7 +320,20 @@ public function process(File $phpcsFile, $stackPtr)
$error = 'No blank line found after control structure';
$fix = $phpcsFile->addFixableError($error, $scopeCloser, 'NoLineAfterClose');
if ($fix === true) {
$phpcsFile->fixer->addNewline($scopeCloser);
$trailingContent = $phpcsFile->findNext(
T_WHITESPACE,
($scopeCloser + 1),
null,
true
);

if ($tokens[$trailingContent]['code'] === T_COMMENT
&& $tokens[$trailingContent]['line'] === $tokens[$scopeCloser]['line']
) {
$phpcsFile->fixer->addNewline($trailingContent);
} else {
$phpcsFile->fixer->addNewline($scopeCloser);
}
}
}//end if

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ if (true) { echo 'foo';
echo 'foo';
}

if ($true) {
echo 'hi 2';
}//end if
echo 'hi';

?>
<?php foreach($formset['Fieldset'] as $fieldset): ?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ if (true) { echo 'foo';
echo 'foo';
}

if ($true) {
echo 'hi 2';
}//end if

echo 'hi';

?>
<?php foreach($formset['Fieldset'] as $fieldset): ?>
<?php foreach($fieldset['Field'] as $field):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ public function getErrorList($testFile='ControlStructureSpacingUnitTest.inc')
179 => 1,
189 => 1,
222 => 1,
233 => 1,
235 => 1,
234 => 1,
238 => 1,
240 => 1,
];
break;
case 'ControlStructureSpacingUnitTest.js':
Expand Down
2 changes: 0 additions & 2 deletions src/Tokenizers/CSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ public function tokenize($string)
$finalTokens[($stackPtr + 1)]['content'] = '-'.$finalTokens[($stackPtr + 1)]['content'];
unset($finalTokens[$stackPtr]);
}//end if

break;
case T_COLON:
// Only interested in colons that are defining styles.
Expand Down Expand Up @@ -472,7 +471,6 @@ public function tokenize($string)
unset($finalTokens[$stackPtr]);
}
}//end if

break;
case T_ASPERAND:
$asperandStart = true;
Expand Down

0 comments on commit a7d4118

Please sign in to comment.