mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 20:42:10 +00:00
Add formatting for StmtMatch
(#6286)
## Summary This PR adds support for `StmtMatch` with subs for `MatchCase`. ## Test Plan Add a few additional test cases around `match` statement, comments, line breaks. resolves: #6298
This commit is contained in:
parent
87984e9ac7
commit
001aa486df
12 changed files with 882 additions and 444 deletions
|
@ -1,12 +1,45 @@
|
|||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use ruff_python_ast::MatchCase;
|
||||
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::not_yet_implemented_custom_text;
|
||||
use crate::prelude::*;
|
||||
use crate::{FormatNodeRule, PyFormatter};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatMatchCase;
|
||||
|
||||
impl FormatNodeRule<MatchCase> for FormatMatchCase {
|
||||
fn fmt_fields(&self, item: &MatchCase, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
let MatchCase {
|
||||
range: _,
|
||||
pattern: _,
|
||||
guard,
|
||||
body,
|
||||
} = item;
|
||||
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
text("case"),
|
||||
space(),
|
||||
not_yet_implemented_custom_text("NOT_YET_IMPLEMENTED_Pattern"),
|
||||
]
|
||||
)?;
|
||||
|
||||
if let Some(guard) = guard {
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
space(),
|
||||
text("if"),
|
||||
space(),
|
||||
maybe_parenthesize_expression(guard, item, Parenthesize::IfBreaks)
|
||||
]
|
||||
)?;
|
||||
}
|
||||
|
||||
write!(f, [text(":"), block_indent(&body.format())])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue