Permalink
Browse files

Fixed bug #19502 : Generic.Files.LineEndingsSniff fails if no new-lin…

…es in file
  • Loading branch information...
1 parent 1e493d4 commit 0640e1f35538506a2e87995ea3697b6674ccde8e @gsherwood gsherwood committed Jul 23, 2012
Showing with 13 additions and 0 deletions.
  1. +12 −0 CodeSniffer/Standards/Generic/Sniffs/Files/LineEndingsSniff.php
  2. +1 −0 package.xml
@@ -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);
View
@@ -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>

0 comments on commit 0640e1f

Please sign in to comment.