Support fmt: skip on compound statements (#6593)

This commit is contained in:
Micha Reiser 2023-08-17 08:05:41 +02:00 committed by GitHub
parent 4dc32a00d0
commit fa7442da2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1385 additions and 625 deletions

View file

@ -1,11 +1,12 @@
use ruff_formatter::{format_args, write};
use ruff_python_ast::StmtMatch;
use crate::comments::{leading_alternate_branch_comments, trailing_comments, SourceComment};
use crate::comments::{leading_alternate_branch_comments, SourceComment};
use crate::context::{NodeLevel, WithNodeLevel};
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::statement::clause::{clause_header, ClauseHeader};
use crate::FormatNodeRule;
#[derive(Default)]
@ -25,16 +26,16 @@ impl FormatNodeRule<StmtMatch> for FormatStmtMatch {
// There can be at most one dangling comment after the colon in a match statement.
debug_assert!(dangling_item_comments.len() <= 1);
write!(
f,
[
clause_header(
ClauseHeader::Match(item),
dangling_item_comments,
&format_args![
text("match"),
space(),
maybe_parenthesize_expression(subject, item, Parenthesize::IfBreaks),
text(":"),
trailing_comments(dangling_item_comments)
]
)?;
],
)
.fmt(f)?;
let mut cases_iter = cases.iter();
let Some(first) = cases_iter.next() else {