Skip to content

Commit ce8a334

Browse files
committed
Issue PyCQA#582: disallow tabs before inline comments
1 parent bf0c5bc commit ce8a334

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pycodestyle.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,9 +1092,11 @@ def whitespace_before_comment(logical_line, tokens):
10921092
prev_end = (0, 0)
10931093
for token_type, text, start, end, line in tokens:
10941094
if token_type == tokenize.COMMENT:
1095-
inline_comment = line[:start[1]].strip()
1095+
inline_comment = line[:start[1]].strip(' ')
10961096
if inline_comment:
1097-
if prev_end[0] == start[0] and start[1] < prev_end[1] + 2:
1097+
contains_tab = '\t' in line[prev_end[1]: prev_end[1] + 2]
1098+
nottwo = prev_end[0] == start[0] and start[1] < prev_end[1] + 2
1099+
if contains_tab or nottwo:
10981100
yield (prev_end,
10991101
"E261 at least two spaces before inline comment")
11001102
symbol, sp, comment = text.partition(' ')

testsuite/E26.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#: E261:1:5
22
pass # an inline comment
3+
#: E261:1:5
4+
pass # an inline comment
5+
#: E261:1:5
6+
pass # an inline comment
7+
#: E261:1:5
8+
pass # an inline comment
39
#: E262:1:12
410
x = x + 1 #Increment x
511
#: E262:1:12
12+
x = x + 1 # Increment x
13+
#: E262:1:12
614
x = x + 1 # Increment x
715
#: E262:1:12
816
x = y + 1 #: Increment x

0 commit comments

Comments
 (0)