-
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
41 changed files
with
704 additions
and
1,241 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,19 @@ | ||
use crate::AsFormat; | ||
use crate::builders::PyFormatterExtensions; | ||
use crate::context::NodeLevel; | ||
use crate::{FormatNodeRule, PyFormatter}; | ||
use ruff_formatter::prelude::hard_line_break; | ||
use ruff_formatter::{write, Buffer, FormatResult}; | ||
|
||
use ruff_formatter::{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()])?; | ||
} | ||
f.join_nodes(NodeLevel::TopLevel) | ||
.nodes(&item.body) | ||
.finish()?; | ||
hard_line_break().fmt(f)?; | ||
Ok(()) | ||
} | ||
} |
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
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
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.