Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new error E204 for whitespace after decorator @ #1247

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ This is the current list of error and warning codes:
+------------+----------------------------------------------------------------------+
| E203 | whitespace before ',', ';', or ':' |
+------------+----------------------------------------------------------------------+
| E204 | whitespace after decorator '@' |
+------------+----------------------------------------------------------------------+
+------------+----------------------------------------------------------------------+
| E211 | whitespace before '(' |
+------------+----------------------------------------------------------------------+
Expand Down
7 changes: 7 additions & 0 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b')
DOCSTRING_REGEX = re.compile(r'u?r?["\']')
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[\[({][ \t]|[ \t][\]}),;:](?!=)')
WHITESPACE_AFTER_DECORATOR_REGEX = re.compile(r'@\s')
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')
Expand Down Expand Up @@ -438,6 +439,9 @@ def extraneous_whitespace(logical_line):
E203: if x == 4: print x, y; x, y = y , x
E203: if x == 4: print x, y ; x, y = y, x
E203: if x == 4 : print x, y; x, y = y, x

Okay: @decorator
E204: @ decorator
"""
line = logical_line
for match in EXTRANEOUS_WHITESPACE_REGEX.finditer(line):
Expand All @@ -451,6 +455,9 @@ def extraneous_whitespace(logical_line):
code = ('E202' if char in '}])' else 'E203') # if char in ',;:'
yield found, f"{code} whitespace before '{char}'"

if WHITESPACE_AFTER_DECORATOR_REGEX.match(logical_line):
yield 1, "E204 whitespace after decorator '@'"


@register_check
def whitespace_around_keywords(logical_line):
Expand Down
17 changes: 17 additions & 0 deletions testing/data/E20.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,21 @@
x, y = y, x
a[b1, :] == a[b1, ...]
b = a[:, b1]
#: E204:1:2
@ decorator
def f():
pass
#: E204:1:2
@ decorator
def f():
pass
#: E204:1:2
@ decorator
def f():
pass
#: E204:2:6
if True:
@ decorator
def f():
pass
#:
Loading