Support fmt: skip for simple-statements and decorators (#6561)

This commit is contained in:
Micha Reiser 2023-08-17 07:58:19 +02:00 committed by GitHub
parent e3ecbe660e
commit 4dc32a00d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 545 additions and 316 deletions

View file

@ -215,6 +215,18 @@ pub(crate) enum SuppressionKind {
Skip,
}
impl SuppressionKind {
pub(crate) fn has_skip_comment(trailing_comments: &[SourceComment], source: &str) -> bool {
trailing_comments.iter().any(|comment| {
comment.line_position().is_end_of_line()
&& matches!(
comment.suppression_kind(source),
Some(SuppressionKind::Skip | SuppressionKind::Off)
)
})
}
}
impl Ranged for SourceComment {
#[inline]
fn range(&self) -> TextRange {

View file

@ -905,7 +905,7 @@ fn handle_leading_class_with_decorators_comment<'a>(
comment: DecoratedComment<'a>,
class_def: &'a ast::StmtClassDef,
) -> CommentPlacement<'a> {
if comment.start() < class_def.name.start() {
if comment.line_position().is_own_line() && comment.start() < class_def.name.start() {
if let Some(decorator) = class_def.decorator_list.last() {
if decorator.end() < comment.start() {
return CommentPlacement::dangling(class_def, comment);