-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
43 changed files
with
1,170 additions
and
1,517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
use crate::AsFormat; | ||
use crate::{FormatNodeRule, PyFormatter}; | ||
use crate::builders::{JoinNodesBuilder, PyFormatterExtensions}; | ||
use crate::context::NodeLevel; | ||
use crate::statement::suite::SuiteLevel; | ||
use crate::{AsFormat, FormatNodeRule, PyFormatter}; | ||
use ruff_formatter::prelude::hard_line_break; | ||
use ruff_formatter::{write, Buffer, FormatResult}; | ||
|
||
use ruff_formatter::{write, Buffer, Format, FormatResult}; | ||
use rustpython_parser::ast::ModModule; | ||
|
||
#[derive(Default)] | ||
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), | ||
hard_line_break() | ||
] | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.