Skip to content

Commit

Permalink
ruff_python_formatter: make code snippet elision more explicit
Browse files Browse the repository at this point in the history
If a test failure occurs, this at least makes it a little clearer that a
code snippet has been removed.

Ref: #8811 (comment)
  • Loading branch information
BurntSushi committed Nov 28, 2023
1 parent f585e3e commit 0f604fa
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions crates/ruff_python_formatter/tests/normalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ impl Transformer for Normalizer {
static STRIP_CODE_SNIPPETS: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r#"(?mx)
# strip doctest PS1 prompt lines
^\s*>>>\s.*(\n|$)
|
# strip doctest PS2 prompt lines
# Also handles the case of an empty ... line.
^\s*\.\.\.((\n|$)|\s.*(\n|$))
(
# strip doctest PS1 prompt lines
^\s*>>>\s.*(\n|$)
|
# strip doctest PS2 prompt lines
# Also handles the case of an empty ... line.
^\s*\.\.\.((\n|$)|\s.*(\n|$))
)+
"#,
)
.unwrap()
Expand All @@ -78,7 +80,10 @@ impl Transformer for Normalizer {
// snippet, since code snippets may be completely reformatted if
// they are Python code.
string_literal.value = STRIP_CODE_SNIPPETS
.replace_all(&string_literal.value, "")
.replace_all(
&string_literal.value,
"<CODE-SNIPPET: Removed by normalizer>\n",
)
.into_owned();
// Normalize a string by (2) stripping any leading and trailing space from each
// line, and (3) removing any blank lines from the start and end of the string.
Expand Down

0 comments on commit 0f604fa

Please sign in to comment.