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

Function format_node

crates/ruff_python_formatter/src/lib.rs:156–178  ·  view source on GitHub ↗
(
    parsed: &'a Parsed<N>,
    trivia: &'a TriviaRanges,
    source: &'a str,
    options: PyFormatOptions,
)

Source from the content-addressed store, hash-verified

154}
155
156fn format_node<'a, N>(
157 parsed: &'a Parsed<N>,
158 trivia: &'a TriviaRanges,
159 source: &'a str,
160 options: PyFormatOptions,
161) -> FormatResult<Formatted<PyFormatContext<'a>>>
162where
163 N: AsFormat<PyFormatContext<'a>>,
164 &'a N: Into<AnyNodeRef<'a>>,
165{
166 let source_code = SourceCode::new(source);
167 let comments = Comments::from_ast(parsed.syntax(), source_code, trivia);
168
169 let formatted = format!(
170 PyFormatContext::new(options, source, comments, trivia, parsed.tokens()),
171 [parsed.syntax().format()]
172 )?;
173 formatted
174 .context()
175 .comments()
176 .assert_all_formatted(source_code);
177 Ok(formatted)
178}
179
180pub fn formatted_file(db: &dyn Db, file: File) -> Result<Option<String>, FormatModuleError> {
181 let options = db.format_options(file);

Callers 4

format_module_astFunction · 0.85
formatted_fileFunction · 0.85
format_nodeMethod · 0.85
fmtMethod · 0.85

Calls 5

OkClass · 0.85
syntaxMethod · 0.80
assert_all_formattedMethod · 0.80
commentsMethod · 0.45
contextMethod · 0.45

Tested by

no test coverage detected