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

Method from_code

crates/ruff_python_formatter/src/comments/mod.rs:564–576  ·  view source on GitHub ↗
(source: &'a str)

Source from the content-addressed store, hash-verified

562
563 impl<'a> CommentsTestCase<'a> {
564 fn from_code(source: &'a str) -> Self {
565 let source_code = SourceCode::new(source);
566 let source_type = PySourceType::Python;
567 let parsed = parse(source, ParseOptions::from(source_type))
568 .expect("Expect source to be valid Python");
569 let trivia = TriviaRanges::from(parsed.tokens());
570
571 CommentsTestCase {
572 parsed,
573 trivia,
574 source_code,
575 }
576 }
577
578 fn to_comments(&self) -> Comments<'_> {
579 Comments::from_ast(self.parsed.syntax(), self.source_code, &self.trivia)

Callers

nothing calls this directly

Calls 3

expectMethod · 0.80
parseFunction · 0.50
tokensMethod · 0.45

Tested by

no test coverage detected