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

Method fmt

crates/ruff_python_formatter/src/comments/format.rs:37–62  ·  view source on GitHub ↗
(&self, f: &mut PyFormatter)

Source from the content-addressed store, hash-verified

35
36impl Format<PyFormatContext<'_>> for FormatLeadingComments<'_> {
37 fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
38 fn write_leading_comments(
39 comments: &[SourceComment],
40 f: &mut PyFormatter,
41 ) -> FormatResult<()> {
42 for comment in comments.iter().filter(|comment| comment.is_unformatted()) {
43 let lines_after_comment = lines_after(comment.end(), f.context().source());
44 write!(
45 f,
46 [format_comment(comment), empty_lines(lines_after_comment)]
47 )?;
48
49 comment.mark_formatted();
50 }
51
52 Ok(())
53 }
54
55 match self {
56 FormatLeadingComments::Node(node) => {
57 let comments = f.context().comments().clone();
58 write_leading_comments(comments.leading(*node), f)
59 }
60 FormatLeadingComments::Comments(comments) => write_leading_comments(comments, f),
61 }
62 }
63}
64
65/// Formats the leading `comments` of an alternate branch and ensures that it preserves the right

Callers

nothing calls this directly

Calls 15

OkClass · 0.85
lines_beforeFunction · 0.85
normalize_commentFunction · 0.85
is_pragma_commentFunction · 0.85
source_positionFunction · 0.85
source_text_sliceFunction · 0.85
textFunction · 0.85

Tested by

no test coverage detected