mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-23 03:45:14 +00:00
Implement module formatting using JoinNodesBuilder (#4808)
* Implement module formatting using JoinNodesBuilder This uses JoinNodesBuilder to implement module formatting for #4800 See the snapshots for the changed behaviour. See one PR up for a CLI that i used to verify the trailing new line behaviour
This commit is contained in:
parent
c65f47d7c4
commit
ff37d7af23
43 changed files with 1176 additions and 1524 deletions
|
@ -1,8 +1,7 @@
|
|||
use crate::AsFormat;
|
||||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use crate::statement::suite::SuiteLevel;
|
||||
use crate::{AsFormat, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::prelude::hard_line_break;
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
|
||||
use rustpython_parser::ast::ModModule;
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -10,9 +9,13 @@ pub struct FormatModModule;
|
|||
|
||||
impl FormatNodeRule<ModModule> for FormatModModule {
|
||||
fn fmt_fields(&self, item: &ModModule, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
for stmt in &item.body {
|
||||
write!(f, [stmt.format(), hard_line_break()])?;
|
||||
}
|
||||
Ok(())
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
item.body.format().with_options(SuiteLevel::TopLevel),
|
||||
// Trailing newline at the end of the file
|
||||
hard_line_break()
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue