mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Support fmt: skip
on compound statements (#6593)
This commit is contained in:
parent
4dc32a00d0
commit
fa7442da2f
23 changed files with 1385 additions and 625 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue