Use single lookup for leading, dangling, and trailing comments (#6589)

This commit is contained in:
Micha Reiser 2023-08-15 17:39:45 +02:00 committed by GitHub
parent 81b1176f99
commit 29c0b9f91c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 319 additions and 387 deletions

View file

@ -117,8 +117,10 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
SuiteKind::TopLevel => SuiteChildStatement::Other(first),
};
let (mut preceding, mut after_class_docstring) = if comments
.leading_comments(first)
let first_comments = comments.leading_dangling_trailing_comments(first);
let (mut preceding, mut after_class_docstring) = if first_comments
.leading
.iter()
.any(|comment| comment.is_suppression_off_comment(source))
{
@ -128,8 +130,8 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
)?,
false,
)
} else if comments
.trailing_comments(first)
} else if first_comments
.trailing
.iter()
.any(|comment| comment.is_suppression_off_comment(source))
{
@ -291,8 +293,10 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
}
}
if comments
.leading_comments(following)
let following_comments = comments.leading_dangling_trailing_comments(following);
if following_comments
.leading
.iter()
.any(|comment| comment.is_suppression_off_comment(source))
{
@ -301,8 +305,8 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
&mut iter,
f,
)?;
} else if comments
.trailing_comments(following)
} else if following_comments
.trailing
.iter()
.any(|comment| comment.is_suppression_off_comment(source))
{