Skip to content

Commit

Permalink
Fixed bug #19502 : Generic.Files.LineEndingsSniff fails if no new-lin…
Browse files Browse the repository at this point in the history
…es in file
  • Loading branch information
gsherwood committed Jul 23, 2012
1 parent 1e493d4 commit 0640e1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CodeSniffer/Standards/Generic/Sniffs/Files/LineEndingsSniff.php
Expand Up @@ -84,6 +84,18 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$found = str_replace("\r", '\r', $found);

if ($found !== $this->eolChar) {
// Check for single line files without an EOL. This is a very special
// case and the EOL char is set to \n when this happens.
if ($found === '\n') {
$tokens = $phpcsFile->getTokens();
$lastToken = ($phpcsFile->numTokens - 1);
if ($tokens[$lastToken]['line'] === 1
&& $tokens[$lastToken]['content'] !== "\n"
) {
return;
}
}

$error = 'End of line character is invalid; expected "%s" but found "%s"';
$expected = $this->eolChar;
$expected = str_replace("\n", '\n', $expected);
Expand Down
1 change: 1 addition & 0 deletions package.xml
Expand Up @@ -30,6 +30,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Squiz FunctionDeclarationArgumentSpacingSniff now supports closures
- Squiz OperatorSpacingSniff no longer throws an error for negative values inside an inline THEN statement
-- Thanks to Klaus Purer for the patch
- Fixed bug #19502 : Generic.Files.LineEndingsSniff fails if no new-lines in file
- Fixed bug #19508 : switch+return: Closing brace indented incorrectly
</notes>
<contents>
Expand Down

0 comments on commit 0640e1f

Please sign in to comment.