Skip to content

Commit

Permalink
PEAR.Functions.FunctionDeclaration now reports an error for blank lin…
Browse files Browse the repository at this point in the history
…es found inside a function declaration (ref #1360)
  • Loading branch information
gsherwood committed Feb 21, 2017
1 parent 244d084 commit b7c84a0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $st
} else if ($tokens[$i]['line'] !== $tokens[($i + 1)]['line']) {
// This is an empty line, so don't check the indent.
$foundIndent = $expectedIndent;

$error = 'Blank lines are not allowed in a multi-line function declaration';
$fix = $phpcsFile->addFixableError($error, $i, 'EmptyLine');
if ($fix === true) {
$phpcsFile->fixer->replaceToken($i, '');
}
} else {
$foundIndent = strlen($tokens[$i]['content']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ function foo(

function foo(
$param1,

$param2,

$param3,
) : SomeClass {
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public function getErrorList()
171 => 1,
173 => 1,
201 => 1,
206 => 1,
208 => 1,
);

}//end getErrorList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function getErrorList($testFile='MultiLineFunctionDeclarationUnitTest.inc
137 => 1,
141 => 2,
142 => 1,
158 => 1,
160 => 1,
);
} else {
$errors = array(
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
<notes>
- The PHP-supplied T_COALESCE_EQUAL token has been replicated for PHP versions before 7.2
- PEAR.Functions.FunctionDeclaration now reports an error for blank lines found inside a function declaration
- PEAR.Functions.FunctionDeclaration no longer reports indent errors for blank lines in a function declaration
- Squiz.Functions.MultiLineFunctionDeclaration no longer reports errors for blank lines in a function declaration
-- It would previously report that only one argument is allowed per line
Expand All @@ -45,6 +46,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #1349 : Squiz.Strings.DoubleQuoteUsage.NotRequired message is badly formatted when string contains a CR newline char
-- Thanks to Algirdas Gurevicius for the patch
- Fixed bug #1350 : Invalid Squiz.Formatting.OperatorBracket error when using namespaces
- Fixed bug #1369 : Empty line in multi-line function declaration cause infinite loop
</notes>
<contents>
<dir name="/">
Expand Down

0 comments on commit b7c84a0

Please sign in to comment.