Skip to content

Commit

Permalink
Issue PyCQA#582: disallow tabs before inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
spaceone committed Sep 16, 2021
1 parent bf0c5bc commit 0736b18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,9 +1092,9 @@ def whitespace_before_comment(logical_line, tokens):
prev_end = (0, 0)
for token_type, text, start, end, line in tokens:
if token_type == tokenize.COMMENT:
inline_comment = line[:start[1]].strip()
inline_comment = line[:start[1]].strip(' ')
if inline_comment:
if prev_end[0] == start[0] and start[1] < prev_end[1] + 2:
if prev_end[0] == start[0] and start[1] < prev_end[1] + 2 or '\t' in line[prev_end[1]: prev_end[1] + 2]:
yield (prev_end,
"E261 at least two spaces before inline comment")
symbol, sp, comment = text.partition(' ')
Expand Down
8 changes: 8 additions & 0 deletions testsuite/E26.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#: E261:1:5
pass # an inline comment
#: E261:1:5
pass # an inline comment
#: E261:1:5
pass # an inline comment
#: E261:1:5
pass # an inline comment
#: E262:1:12
x = x + 1 #Increment x
#: E262:1:12
x = x + 1 # Increment x
#: E262:1:12
x = x + 1 # Increment x
#: E262:1:12
x = y + 1 #: Increment x
Expand Down

0 comments on commit 0736b18

Please sign in to comment.