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

Method is_end

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

Returns true when given line ends this fenced code block.

(&self, original: InputDocstringLine<'src>)

Source from the content-addressed store, hash-verified

1409
1410 /// Returns true when given line ends this fenced code block.
1411 fn is_end(&self, original: InputDocstringLine<'src>) -> bool {
1412 let (_, rest) = indent_with_suffix(original.line);
1413 // We can bail early if we don't have at least three backticks or
1414 // tildes.
1415 if !rest.starts_with("```") && !rest.starts_with("~~~") {
1416 return false;
1417 }
1418 // We do need to check that we have the right number of
1419 // backticks/tildes...
1420 let fence_len = rest
1421 .chars()
1422 .take_while(|&ch| ch == self.fence_kind.to_char())
1423 .count();
1424 // A closing fence only needs *at least* the number of ticks/tildes
1425 // that are in the opening fence.
1426 if fence_len < self.fence_len {
1427 return false;
1428 }
1429 // And, also, there can only be trailing whitespace. Nothing else.
1430 assert!(
1431 self.fence_kind.to_char().is_ascii(),
1432 "fence char should be ASCII",
1433 );
1434 if !rest[fence_len..].chars().all(is_python_whitespace) {
1435 return false;
1436 }
1437 true
1438 }
1439
1440 /// Pushes the given line as part of this code example.
1441 fn push(&mut self, original: InputDocstringLine<'src>) {

Callers 1

add_code_lineMethod · 0.45

Calls 6

indent_with_suffixFunction · 0.85
starts_withMethod · 0.45
countMethod · 0.45
charsMethod · 0.45
to_charMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected