diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-04-14 16:23:12 +0200 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-04-14 16:23:12 +0200 |
commit | b6da3926871b581d5ff2b5635777de71748ecb24 (patch) | |
tree | 8317b2b856f669bbf63f87a962bc857dd985bea0 | |
parent | 74996fe0ad4c881bdd6d139129aa9e83a35cf935 (diff) | |
download | pep8-b6da3926871b581d5ff2b5635777de71748ecb24.tar.gz |
Check the last line even if it has not EOL; issue #273
-rw-r--r-- | CHANGES.txt | 8 | ||||
-rwxr-xr-x | pep8.py | 11 | ||||
-rw-r--r-- | testsuite/W29.py | 14 | ||||
-rw-r--r-- | testsuite/support.py | 5 |
4 files changed, 29 insertions, 9 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index f683df8..49921f2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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) ------------------ @@ -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() diff --git a/testsuite/W29.py b/testsuite/W29.py index 42802ca..688667f 100644 --- a/testsuite/W29.py +++ b/testsuite/W29.py @@ -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 diff --git a/testsuite/support.py b/testsuite/support.py index 3c767ed..5185005 100644 --- a/testsuite/support.py +++ b/testsuite/support.py @@ -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) |