From 19ed2806fd95cd19ddcaa46fa44a77a42de6445c Mon Sep 17 00:00:00 2001 From: Florian Best Date: Fri, 17 Sep 2021 00:30:45 +0200 Subject: [PATCH] Issue #582: disallow tabs before inline comments --- pycodestyle.py | 4 +++- testsuite/E26.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pycodestyle.py b/pycodestyle.py index cb2690473..bbcdc5d32 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -1088,7 +1088,9 @@ def whitespace_before_comment(logical_line, tokens): if token_type == tokenize.COMMENT: inline_comment = line[:start[1]].strip() if inline_comment: - if prev_end[0] == start[0] and start[1] < prev_end[1] + 2: + contains_tab = '\t' in line[prev_end[1]: prev_end[1] + 2] + nottwo = prev_end[0] == start[0] and start[1] < prev_end[1] + 2 + if contains_tab or nottwo: yield (prev_end, "E261 at least two spaces before inline comment") symbol, sp, comment = text.partition(' ') diff --git a/testsuite/E26.py b/testsuite/E26.py index c3537ff50..fea612a86 100644 --- a/testsuite/E26.py +++ b/testsuite/E26.py @@ -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