Check the last line even if it has not EOL; issue #273
authorFlorent Xicluna <florent.xicluna@gmail.com>
Mon, 14 Apr 2014 14:23:12 +0000 (16:23 +0200)
committerFlorent Xicluna <florent.xicluna@gmail.com>
Mon, 14 Apr 2014 14:23:12 +0000 (16:23 +0200)
CHANGES.txt
pep8.py
testsuite/W29.py
testsuite/support.py

index f683df864234a2a3693a44fca8dec624e32a25b6..49921f24b02c332850aa11d8c71496d3a32b51a4 100644 (file)
@@ -2,6 +2,14 @@ Changelog
 =========
 
 
+1.x (unreleased)
+----------------
+
+Bug fixes:
+
+* Check the last line even if it has no end-of-line. (Issue #273)
+
+
 1.5.5 (2014-04-10)
 ------------------
 
diff --git a/pep8.py b/pep8.py
index 9552bab3a3166838b664db6c9b2db60cf34f97b1..fe679c93465f528dac4ac61a3141d6384da4826a 100755 (executable)
--- a/pep8.py
+++ b/pep8.py
@@ -46,7 +46,7 @@ W warnings
 """
 from __future__ import with_statement
 
-__version__ = '1.5.5'
+__version__ = '1.5.6a0'
 
 import os
 import sys
@@ -1265,9 +1265,9 @@ class Checker(object):
 
     def readline(self):
         """Get the next line from the input buffer."""
-        self.line_number += 1
-        if self.line_number > len(self.lines):
+        if self.line_number >= len(self.lines):
             return ''
+        self.line_number += 1
         line = self.lines[self.line_number - 1]
         if self.indent_char is None and line[:1] in WHITESPACE:
             self.indent_char = line[0]
@@ -1451,6 +1451,11 @@ class Checker(object):
                         token[3] = (token[2][0], token[2][1] + len(token[1]))
                         self.tokens = [tuple(token)]
                         self.check_logical()
+        if len(self.tokens) > 1 and (token_type == tokenize.ENDMARKER and
+                                     self.tokens[-2][0] not in SKIP_TOKENS):
+            self.tokens.pop()
+            self.check_physical(self.tokens[-1][4])
+            self.check_logical()
         return self.report.get_file_results()
 
 
index 42802ca82106c40060efb9f5155285411a7816e0..688667f0eaa6d72b9f0d6cf32eca6ad9cf250785 100644 (file)
@@ -1,13 +1,17 @@
 #: Okay
 # 情
-#: W291
+#: W291:1:6
 print 
-#: W293
+#: W293:2:1
 class Foo(object):
     
     bang = 12
-#: W291
+#: W291:2:35
 '''multiline
 string with trailing whitespace'''   
-#: W292
-# This line doesn't have a linefeed
\ No newline at end of file
+#: W292:1:36 noeol
+# This line doesn't have a linefeed
+#: W292:1:5 E225:1:2 noeol
+1+ 1
+#: W292:1:27 E261:1:12 noeol
+import this # no line feed
index 3c767ed61340efc35f8d6d5ecda6e648300b8e06..5185005750cab39ad7ad40175b9983c67db43086 100644 (file)
@@ -157,7 +157,10 @@ def init_tests(pep8style):
                     testcase.append(line)
                 continue
             if codes and index:
-                codes = [c for c in codes if c != 'Okay']
+                if 'noeol' in codes:
+                    testcase[-1] = testcase[-1].rstrip('\n')
+                codes = [c for c in codes
+                         if c not in ('Okay', 'noeol')]
                 # Run the checker
                 runner(filename, testcase, expected=codes,
                        line_offset=line_offset)