From f1d28848c34d5d8a773896c531c12390a7192508 Mon Sep 17 00:00:00 2001 From: Florian Best Date: Fri, 17 Sep 2021 00:06:05 +0200 Subject: Issue #588: E201: detect tabs as whitespace --- pycodestyle.py | 4 ++-- testsuite/E20.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pycodestyle.py b/pycodestyle.py index cc1720e..ca6a2bd 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -144,7 +144,7 @@ RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,') RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,.*,\s*\w+\s*$') ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b') DOCSTRING_REGEX = re.compile(r'u?r?["\']') -EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[\[({] | [\]}),;]| :(?!=)') +EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[\[({][ \t]|[ \t][\]}),;:](?!=)') WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)') COMPARE_SINGLETON_REGEX = re.compile(r'(\bNone|\bFalse|\bTrue)?\s*([=!]=)' r'\s*(?(1)|(None|False|True))\b') @@ -471,7 +471,7 @@ def extraneous_whitespace(logical_line): text = match.group() char = text.strip() found = match.start() - if text == char + ' ': + if text[-1].isspace(): # assert char in '([{' yield found + 1, "E201 whitespace after '%s'" % char elif line[found - 1] != ',': diff --git a/testsuite/E20.py b/testsuite/E20.py index 2f1ecc2..20c6dfd 100644 --- a/testsuite/E20.py +++ b/testsuite/E20.py @@ -4,6 +4,12 @@ spam( ham[1], {eggs: 2}) spam(ham[ 1], {eggs: 2}) #: E201:1:15 spam(ham[1], { eggs: 2}) +#: E201:1:6 +spam( ham[1], {eggs: 2}) +#: E201:1:10 +spam(ham[ 1], {eggs: 2}) +#: E201:1:15 +spam(ham[1], { eggs: 2}) #: Okay spam(ham[1], {eggs: 2}) #: @@ -15,6 +21,12 @@ spam(ham[1], {eggs: 2} ) spam(ham[1], {eggs: 2 }) #: E202:1:11 spam(ham[1 ], {eggs: 2}) +#: E202:1:23 +spam(ham[1], {eggs: 2} ) +#: E202:1:22 +spam(ham[1], {eggs: 2 }) +#: E202:1:11 +spam(ham[1 ], {eggs: 2}) #: Okay spam(ham[1], {eggs: 2}) @@ -39,13 +51,24 @@ result = [ if x == 4 : print x, y x, y = y, x +#: E203:1:10 +if x == 4 : + print x, y + x, y = y, x #: E203:2:15 E702:2:16 if x == 4: print x, y ; x, y = y, x +#: E203:2:15 E702:2:16 +if x == 4: + print x, y ; x, y = y, x #: E203:3:13 if x == 4: print x, y x, y = y , x +#: E203:3:13 +if x == 4: + print x, y + x, y = y , x #: Okay if x == 4: print x, y -- cgit v1.2.1