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

Method fmt

crates/ruff_python_formatter/src/string/implicit.rs:43–65  ·  view source on GitHub ↗
(&self, f: &mut PyFormatter)

Source from the content-addressed store, hash-verified

41
42impl Format<PyFormatContext<'_>> for FormatImplicitConcatenatedString<'_> {
43 fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
44 let flat = FormatImplicitConcatenatedStringFlat::new(self.string, f.context());
45 let expanded = FormatImplicitConcatenatedStringExpanded::new(
46 self.string,
47 if flat.is_some() {
48 ImplicitConcatenatedLayout::MaybeFlat
49 } else {
50 ImplicitConcatenatedLayout::Multipart
51 },
52 );
53
54 // If the string can be joined, try joining the implicit concatenated string into a single string
55 // if it fits on the line. Otherwise, parenthesize the string parts and format each part on its
56 // own line.
57 if let Some(flat) = flat {
58 write!(
59 f,
60 [if_group_fits_on_line(&flat), if_group_breaks(&expanded)]
61 )
62 } else {
63 expanded.fmt(f)
64 }
65 }
66}
67
68/// Formats an implicit concatenated string where parts are separated by a space or line break.

Callers

nothing calls this directly

Calls 15

expand_parentFunction · 0.85
format_withFunction · 0.85
normalize_stringFunction · 0.85
source_text_sliceFunction · 0.85
textFunction · 0.85
needs_chaperone_spaceFunction · 0.85
OkClass · 0.85
join_withMethod · 0.80
trim_startMethod · 0.80
spaceFunction · 0.50
contextMethod · 0.45

Tested by

no test coverage detected