diff options
author | Anthony Sottile <asottile@umich.edu> | 2021-11-09 09:45:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-09 09:45:31 -0500 |
commit | f0ce4dca62dd53cde18f3e613222074d737a48af (patch) | |
tree | d704f04f7313bc7a8b3bc90ec1c7b745c7b1706a | |
parent | 598092fbb21def8b56b9e676a433517b7a69ba1b (diff) | |
parent | 59854e1caa96d31a5e100a7a3edbe32cf8fc5209 (diff) | |
download | pep8-f0ce4dca62dd53cde18f3e613222074d737a48af.tar.gz |
Merge pull request #1035 from Pierre-Sassoulas/false-negative-e262-with-non-breaking-whitespace
Properly warn for E262 with non breaking whitespaces
-rw-r--r-- | docs/intro.rst | 4 | ||||
-rwxr-xr-x | pycodestyle.py | 13 | ||||
-rw-r--r-- | testsuite/E26.py | 7 |
3 files changed, 17 insertions, 7 deletions
diff --git a/docs/intro.rst b/docs/intro.rst index 7945053..7fbf654 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -406,9 +406,9 @@ This is the current list of error and warning codes: +------------+----------------------------------------------------------------------+ | **W5** | *Line break warning* | +------------+----------------------------------------------------------------------+ -| W503 (*) | line break before binary operator | +| W503 (*) | line break before binary operator | +------------+----------------------------------------------------------------------+ -| W504 (*) | line break after binary operator | +| W504 (*) | line break after binary operator | +------------+----------------------------------------------------------------------+ | W505 (\*^) | doc line too long (82 > 79 characters) | +------------+----------------------------------------------------------------------+ diff --git a/pycodestyle.py b/pycodestyle.py index d324544..b839e35 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -126,7 +126,7 @@ WS_NEEDED_OPERATORS = frozenset([ '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=', 'and', 'in', 'is', 'or', '->'] + ASSIGNMENT_EXPRESSION_OP) -WHITESPACE = frozenset(' \t') +WHITESPACE = frozenset(' \t\xa0') NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE]) SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT]) # ERRORTOKEN is triggered by backticks in Python 3 @@ -1056,21 +1056,24 @@ def whitespace_around_named_parameter_equals(logical_line, tokens): @register_check def whitespace_before_comment(logical_line, tokens): - r"""Separate inline comments by at least two spaces. + """Separate inline comments by at least two spaces. An inline comment is a comment on the same line as a statement. Inline comments should be separated by at least two spaces from the statement. They should start with a # and a single space. - Each line of a block comment starts with a # and a single space - (unless it is indented text inside the comment). + Each line of a block comment starts with a # and one or multiple + spaces as there can be indented text inside the comment. Okay: x = x + 1 # Increment x Okay: x = x + 1 # Increment x - Okay: # Block comment + Okay: # Block comments: + Okay: # - Block comment list + Okay: # \xa0- Block comment list E261: x = x + 1 # Increment x E262: x = x + 1 #Increment x E262: x = x + 1 # Increment x + E262: x = x + 1 # \xa0Increment x E265: #Block comment E266: ### Block comment """ diff --git a/testsuite/E26.py b/testsuite/E26.py index c3537ff..937ef72 100644 --- a/testsuite/E26.py +++ b/testsuite/E26.py @@ -57,3 +57,10 @@ def oof(): # ################################################################ # # ####################### another separator ###################### # # ################################################################ # +#: E262:3:9 +# -*- coding: utf8 -*- +# (One space one NBSP) Ok for block comment +a = 42 # (One space one NBSP) +#: E262:2:9 +# (Two spaces) Ok for block comment +a = 42 # (Two spaces) |