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}') {
|
||||
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:") {
|
||||
return Ok(Cow::Owned(std::format!("# \u{A0}{trimmed}")));
|
||||
}
|
||||
|
||||
// Black replaces the non-breaking space with a space if followed by a space.
|
||||
if trimmed.starts_with(' ') {
|
||||
return Ok(Cow::Owned(std::format!("# {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.
|
||||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue