mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 17:10:53 +00:00
Track formatted comments (#4979)
This commit is contained in:
parent
646ab64850
commit
68d52da43b
6 changed files with 60 additions and 85 deletions
|
@ -36,7 +36,10 @@ impl Format<PyFormatContext<'_>> for FormatLeadingComments<'_> {
|
|||
FormatLeadingComments::Comments(comments) => comments,
|
||||
};
|
||||
|
||||
for comment in leading_comments {
|
||||
for comment in leading_comments
|
||||
.iter()
|
||||
.filter(|comment| comment.is_unformatted())
|
||||
{
|
||||
let slice = comment.slice();
|
||||
|
||||
let lines_after_comment = lines_after(slice.end(), f.context().contents());
|
||||
|
@ -127,7 +130,10 @@ impl Format<PyFormatContext<'_>> for FormatTrailingComments<'_> {
|
|||
|
||||
let mut has_trailing_own_line_comment = false;
|
||||
|
||||
for trailing in trailing_comments {
|
||||
for trailing in trailing_comments
|
||||
.iter()
|
||||
.filter(|comment| comment.is_unformatted())
|
||||
{
|
||||
let slice = trailing.slice();
|
||||
|
||||
has_trailing_own_line_comment |= trailing.position().is_own_line();
|
||||
|
@ -198,7 +204,10 @@ impl Format<PyFormatContext<'_>> for FormatDanglingComments<'_> {
|
|||
};
|
||||
|
||||
let mut first = true;
|
||||
for comment in dangling_comments {
|
||||
for comment in dangling_comments
|
||||
.iter()
|
||||
.filter(|comment| comment.is_unformatted())
|
||||
{
|
||||
if first && comment.position().is_end_of_line() {
|
||||
write!(f, [space(), space()])?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue