Skip to content

Commit b6da392

Browse files
committed
Check the last line even if it has not EOL; issue #273
1 parent 74996fe commit b6da392

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

CHANGES.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ Changelog
22
=========
33

44

5+
1.x (unreleased)
6+
----------------
7+
8+
Bug fixes:
9+
10+
* Check the last line even if it has no end-of-line. (Issue #273)
11+
12+
513
1.5.5 (2014-04-10)
614
------------------
715

pep8.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"""
4747
from __future__ import with_statement
4848

49-
__version__ = '1.5.5'
49+
__version__ = '1.5.6a0'
5050

5151
import os
5252
import sys
@@ -1265,9 +1265,9 @@ def report_invalid_syntax(self):
12651265

12661266
def readline(self):
12671267
"""Get the next line from the input buffer."""
1268-
self.line_number += 1
1269-
if self.line_number > len(self.lines):
1268+
if self.line_number >= len(self.lines):
12701269
return ''
1270+
self.line_number += 1
12711271
line = self.lines[self.line_number - 1]
12721272
if self.indent_char is None and line[:1] in WHITESPACE:
12731273
self.indent_char = line[0]
@@ -1451,6 +1451,11 @@ def check_all(self, expected=None, line_offset=0):
14511451
token[3] = (token[2][0], token[2][1] + len(token[1]))
14521452
self.tokens = [tuple(token)]
14531453
self.check_logical()
1454+
if len(self.tokens) > 1 and (token_type == tokenize.ENDMARKER and
1455+
self.tokens[-2][0] not in SKIP_TOKENS):
1456+
self.tokens.pop()
1457+
self.check_physical(self.tokens[-1][4])
1458+
self.check_logical()
14541459
return self.report.get_file_results()
14551460

14561461

testsuite/W29.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#: Okay
22
# 情
3-
#: W291
3+
#: W291:1:6
44
print
5-
#: W293
5+
#: W293:2:1
66
class Foo(object):
77

88
bang = 12
9-
#: W291
9+
#: W291:2:35
1010
'''multiline
1111
string with trailing whitespace'''
12-
#: W292
13-
# This line doesn't have a linefeed
12+
#: W292:1:36 noeol
13+
# This line doesn't have a linefeed
14+
#: W292:1:5 E225:1:2 noeol
15+
1+ 1
16+
#: W292:1:27 E261:1:12 noeol
17+
import this # no line feed

testsuite/support.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ def run_tests(filename):
157157
testcase.append(line)
158158
continue
159159
if codes and index:
160-
codes = [c for c in codes if c != 'Okay']
160+
if 'noeol' in codes:
161+
testcase[-1] = testcase[-1].rstrip('\n')
162+
codes = [c for c in codes
163+
if c not in ('Okay', 'noeol')]
161164
# Run the checker
162165
runner(filename, testcase, expected=codes,
163166
line_offset=line_offset)

0 commit comments

Comments
 (0)