(&self, item: &ModModule, f: &mut PyFormatter)
| 11 | |
| 12 | impl FormatNodeRule<ModModule> for FormatModModule { |
| 13 | fn fmt_fields(&self, item: &ModModule, f: &mut PyFormatter) -> FormatResult<()> { |
| 14 | let ModModule { |
| 15 | range, |
| 16 | body, |
| 17 | node_index: _, |
| 18 | } = item; |
| 19 | |
| 20 | if body.is_empty() { |
| 21 | // Only preserve an empty line if the source contains an empty line too. |
| 22 | if !f.context().comments().has_leading(item) |
| 23 | && lines_after(range.start(), f.context().source()) != 0 |
| 24 | { |
| 25 | empty_line().fmt(f) |
| 26 | } else { |
| 27 | Ok(()) |
| 28 | } |
| 29 | } else { |
| 30 | write!( |
| 31 | f, |
| 32 | [ |
| 33 | body.format().with_options(SuiteKind::TopLevel), |
| 34 | // Trailing newline at the end of the file |
| 35 | hard_line_break() |
| 36 | ] |
| 37 | ) |
| 38 | } |
| 39 | } |
| 40 | } |
nothing calls this directly
no test coverage detected