MCPcopy Create free account
hub / github.com/astral-sh/ruff / fmt_fields

Method fmt_fields

crates/ruff_python_formatter/src/module/mod_module.rs:13–39  ·  view source on GitHub ↗
(&self, item: &ModModule, f: &mut PyFormatter)

Source from the content-addressed store, hash-verified

11
12impl 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}

Callers

nothing calls this directly

Calls 10

lines_afterFunction · 0.85
OkClass · 0.85
has_leadingMethod · 0.80
empty_lineFunction · 0.50
is_emptyMethod · 0.45
commentsMethod · 0.45
contextMethod · 0.45
startMethod · 0.45
sourceMethod · 0.45
fmtMethod · 0.45

Tested by

no test coverage detected