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

Method push_format_action

crates/ruff_python_formatter/src/string/docstring.rs:1250–1273  ·  view source on GitHub ↗

Consume this block and add actions to the give queue for formatting. This may trim lines from the end of the block and add them to the queue for printing as-is. For example, this happens when there are trailing empty lines, as we would like to preserve those since they aren't generally treated as part of the code block.

(mut self, queue: &mut VecDeque<CodeExampleAddAction<'src>>)

Source from the content-addressed store, hash-verified

1248 /// empty lines, as we would like to preserve those since they aren't
1249 /// generally treated as part of the code block.
1250 fn push_format_action(mut self, queue: &mut VecDeque<CodeExampleAddAction<'src>>) {
1251 let has_non_whitespace = |line: &CodeExampleLine| {
1252 line.original
1253 .line
1254 .chars()
1255 .any(|ch| !is_python_whitespace(ch))
1256 };
1257 let first_trailing_empty_line = self
1258 .lines
1259 .iter()
1260 .rposition(has_non_whitespace)
1261 .map_or(0, |i| i + 1);
1262 let trailing_lines = self.lines.split_off(first_trailing_empty_line);
1263 queue.push_back(CodeExampleAddAction::Format {
1264 kind: CodeExampleKind::Rst(self),
1265 });
1266 queue.extend(
1267 trailing_lines
1268 .into_iter()
1269 .map(|line| CodeExampleAddAction::Print {
1270 original: line.original,
1271 }),
1272 );
1273 }
1274
1275 /// Consume this block and turn it into a reset action.
1276 ///

Callers 1

add_code_lineMethod · 0.80

Calls 7

is_python_whitespaceFunction · 0.85
anyMethod · 0.45
charsMethod · 0.45
iterMethod · 0.45
extendMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected