mirror of
https://github.com/astral-sh/ruff
synced 2026-01-21 13:30:49 -05:00
Implement basic module formatting (#4784)
* Add Format for Stmt * Implement basic module formatting This implements formatting each statement in a module with a hard line break in between, so that we can start formatting statements. Basic testing is done by the snapshots
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::AsFormat;
|
||||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::prelude::hard_line_break;
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
|
||||
use rustpython_parser::ast::ModModule;
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -7,6 +10,9 @@ pub struct FormatModModule;
|
||||
|
||||
impl FormatNodeRule<ModModule> for FormatModModule {
|
||||
fn fmt_fields(&self, item: &ModModule, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
for stmt in &item.body {
|
||||
write!(f, [stmt.format(), hard_line_break()])?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user