Skip to content

Commit

Permalink
Remove NBSP at the beggining of comments
Browse files Browse the repository at this point in the history
Closes #2091
  • Loading branch information
Pierre-Sassoulas committed Apr 7, 2021
1 parent 9cbf1f1 commit ee28570
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -4,6 +4,8 @@

#### _Black_

- `Black` now remove leading non-breaking spaces in comments before adding a space (#2092)

- `Black` now respects `--skip-string-normalization` when normalizing multiline
docstring quotes (#1637)

Expand Down
2 changes: 2 additions & 0 deletions src/black/__init__.py
Expand Up @@ -2709,6 +2709,8 @@ def make_comment(content: str) -> str:

if content[0] == "#":
content = content[1:]
if content and content[0] == " ": # This is a non-breaking space
content = " " + content[1:] # And this is a simple space
if content and content[0] not in " !:#'%":
content = " " + content
return "#" + content
Expand Down
18 changes: 9 additions & 9 deletions tests/data/comments7.py
Expand Up @@ -6,7 +6,7 @@
Int,
Path,
# String,
# resolve_to_config_type,
#  resolve_to_config_type,
# DEFAULT_TYPE_ATTRIBUTES,
)

Expand All @@ -18,12 +18,12 @@
ConfigTypeAttributes,
Int,
no_comma_here_yet
# and some comments,
#  and some comments,
# resolve_to_config_type,
# DEFAULT_TYPE_ATTRIBUTES,
)
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
MyLovelyCompanyTeamProjectComponent # NOT DRY
MyLovelyCompanyTeamProjectComponent # NOT DRY
)
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
MyLovelyCompanyTeamProjectComponent as component # DRY
Expand All @@ -33,7 +33,7 @@
result = 1 # look ma, no comment migration xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

result = (
1 # look ma, no comment migration xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1 # look ma, no comment migration xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
)

result = (
Expand All @@ -50,7 +50,7 @@ def func():
0.0789,
0.0123,
0.0789,
a[-1], # type: ignore
a[-1], # type: ignore
)
c = call(
0.0123,
Expand All @@ -73,7 +73,7 @@ def func():
a[-1] # type: ignore
)

# The type: ignore exception only applies to line length, not
# The type: ignore exception only applies to line length, not
# other types of formatting.
c = call(
"aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", # type: ignore
Expand All @@ -85,7 +85,7 @@ class C:
@pytest.mark.parametrize(
("post_data", "message"),
[
# metadata_version errors.
# metadata_version errors.
(
{},
"None is an invalid value for Metadata-Version. Error: This field is"
Expand All @@ -98,7 +98,7 @@ class C:
" Version see"
" https://packaging.python.org/specifications/core-metadata"
),
# name errors.
# name errors.
(
{"metadata_version": "1.2"},
"'' is an invalid value for Name. Error: This field is required. see"
Expand All @@ -110,7 +110,7 @@ class C:
" letter or numeral and contain only ascii numeric and '.', '_' and"
" '-'. see https://packaging.python.org/specifications/core-metadata"
),
# version errors.
# version errors.
(
{"metadata_version": "1.2", "name": "example"},
"'' is an invalid value for Version. Error: This field is required. see"
Expand Down

0 comments on commit ee28570

Please sign in to comment.