mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-11 22:28:27 +00:00
Match Black's formatting of trailing comments containing NBSP (#7030)
This commit is contained in:
parent
60132da7bb
commit
0489bbc54c
2 changed files with 12 additions and 11 deletions
|
@ -474,18 +474,19 @@ fn normalize_comment<'a>(
|
||||||
if content.starts_with('\u{A0}') {
|
if content.starts_with('\u{A0}') {
|
||||||
let trimmed = content.trim_start_matches('\u{A0}');
|
let trimmed = content.trim_start_matches('\u{A0}');
|
||||||
|
|
||||||
// Black adds a space before the non-breaking space if part of a type pragma.
|
|
||||||
if trimmed.trim_start().starts_with("type:") {
|
if trimmed.trim_start().starts_with("type:") {
|
||||||
return Ok(Cow::Owned(std::format!("# \u{A0}{trimmed}")));
|
// Black adds a space before the non-breaking space if part of a type pragma.
|
||||||
}
|
Ok(Cow::Owned(std::format!("# {content}")))
|
||||||
|
} else if trimmed.starts_with(' ') {
|
||||||
// Black replaces the non-breaking space with a space if followed by a space.
|
// Black replaces the non-breaking space with a space if followed by a space.
|
||||||
if trimmed.starts_with(' ') {
|
Ok(Cow::Owned(std::format!("# {trimmed}")))
|
||||||
return Ok(Cow::Owned(std::format!("# {trimmed}")));
|
} else {
|
||||||
|
// Otherwise we replace the first non-breaking space with a regular space.
|
||||||
|
Ok(Cow::Owned(std::format!("# {}", &content["\u{A0}".len()..])))
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Ok(Cow::Owned(std::format!("# {}", content.trim_start())))
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Cow::Owned(std::format!("# {}", content.trim_start())))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper for stripping '#' from comments.
|
/// A helper for stripping '#' from comments.
|
||||||
|
|
|
@ -65,11 +65,11 @@ i = "" # type: Add space before leading NBSP followed by spaces
|
||||||
i = "" # type: A space is added
|
i = "" # type: A space is added
|
||||||
i = "" # type: Add space before leading NBSP followed by a space
|
i = "" # type: Add space before leading NBSP followed by a space
|
||||||
i = "" # type: Add space before leading NBSP
|
i = "" # type: Add space before leading NBSP
|
||||||
i = "" # type: Add space before two leading NBSP
|
i = "" # type: Add space before two leading NBSP
|
||||||
|
|
||||||
|
|
||||||
# A noqa as `#\u{A0}\u{A0}noqa` becomes `# \u{A0}noqa`
|
# A noqa as `#\u{A0}\u{A0}noqa` becomes `# \u{A0}noqa`
|
||||||
i = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # noqa
|
i = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # noqa
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue