Skip to content

Commit 19ed280

Browse files
committed
Issue #582: disallow tabs before inline comments
1 parent 533073e commit 19ed280

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pycodestyle.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,9 @@ def whitespace_before_comment(logical_line, tokens):
10881088
if token_type == tokenize.COMMENT:
10891089
inline_comment = line[:start[1]].strip()
10901090
if inline_comment:
1091-
if prev_end[0] == start[0] and start[1] < prev_end[1] + 2:
1091+
contains_tab = '\t' in line[prev_end[1]: prev_end[1] + 2]
1092+
nottwo = prev_end[0] == start[0] and start[1] < prev_end[1] + 2
1093+
if contains_tab or nottwo:
10921094
yield (prev_end,
10931095
"E261 at least two spaces before inline comment")
10941096
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)