Skip to content

Commit 0736b18

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

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pycodestyle.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1092,9 +1092,9 @@ 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+
if prev_end[0] == start[0] and start[1] < prev_end[1] + 2 or '\t' in line[prev_end[1]: prev_end[1] + 2]:
10981098
yield (prev_end,
10991099
"E261 at least two spaces before inline comment")
11001100
symbol, sp, comment = text.partition(' ')

testsuite/E26.py

+8
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)