mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-21 20:15:11 +00:00
Format assert
statement (#5168)
This commit is contained in:
parent
5a4516b812
commit
a961f75e13
14 changed files with 442 additions and 370 deletions
|
@ -1,4 +1,7 @@
|
|||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::prelude::{space, text};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::StmtAssert;
|
||||
|
||||
|
@ -7,6 +10,32 @@ pub struct FormatStmtAssert;
|
|||
|
||||
impl FormatNodeRule<StmtAssert> for FormatStmtAssert {
|
||||
fn fmt_fields(&self, item: &StmtAssert, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
let StmtAssert {
|
||||
range: _,
|
||||
test,
|
||||
msg,
|
||||
} = item;
|
||||
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
text("assert"),
|
||||
space(),
|
||||
maybe_parenthesize_expression(test, item, Parenthesize::IfBreaks)
|
||||
]
|
||||
)?;
|
||||
|
||||
if let Some(msg) = msg {
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
text(","),
|
||||
space(),
|
||||
maybe_parenthesize_expression(msg, item, Parenthesize::IfBreaks),
|
||||
]
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue