Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…es in file
  • Loading branch information...
commit 0640e1f35538506a2e87995ea3697b6674ccde8e 1 parent 1e493d4
Greg Sherwood authored July 23, 2012
12  CodeSniffer/Standards/Generic/Sniffs/Files/LineEndingsSniff.php
@@ -84,6 +84,18 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
84 84
         $found = str_replace("\r", '\r', $found);
85 85
 
86 86
         if ($found !== $this->eolChar) {
  87
+            // Check for single line files without an EOL. This is a very special
  88
+            // case and the EOL char is set to \n when this happens.
  89
+            if ($found === '\n') {
  90
+                $tokens    = $phpcsFile->getTokens();
  91
+                $lastToken = ($phpcsFile->numTokens - 1);
  92
+                if ($tokens[$lastToken]['line'] === 1
  93
+                    && $tokens[$lastToken]['content'] !== "\n"
  94
+                ) {
  95
+                    return;
  96
+                }
  97
+            }
  98
+
87 99
             $error    = 'End of line character is invalid; expected "%s" but found "%s"';
88 100
             $expected = $this->eolChar;
89 101
             $expected = str_replace("\n", '\n', $expected);
1  package.xml
@@ -30,6 +30,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
30 30
   - Squiz FunctionDeclarationArgumentSpacingSniff now supports closures
31 31
   - Squiz OperatorSpacingSniff no longer throws an error for negative values inside an inline THEN statement
32 32
     -- Thanks to Klaus Purer for the patch
  33
+  - Fixed bug #19502 : Generic.Files.LineEndingsSniff fails if no new-lines in file
33 34
   - Fixed bug #19508 : switch+return: Closing brace indented incorrectly
34 35
  </notes>
35 36
  <contents>

0 notes on commit 0640e1f

Please sign in to comment.
Something went wrong with that request. Please try again.