mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
23 lines
637 B
Rust
23 lines
637 B
Rust
use ruff_formatter::write;
|
|
use ruff_python_ast::Keyword;
|
|
|
|
use crate::prelude::*;
|
|
|
|
#[derive(Default)]
|
|
pub struct FormatKeyword;
|
|
|
|
impl FormatNodeRule<Keyword> for FormatKeyword {
|
|
fn fmt_fields(&self, item: &Keyword, f: &mut PyFormatter) -> FormatResult<()> {
|
|
let Keyword {
|
|
range: _,
|
|
arg,
|
|
value,
|
|
} = item;
|
|
// Comments after the `=` or `**` are reassigned as leading comments on the value.
|
|
if let Some(arg) = arg {
|
|
write!(f, [arg.format(), token("="), value.format()])
|
|
} else {
|
|
write!(f, [token("**"), value.format()])
|
|
}
|
|
}
|
|
}
|