mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-11 14:18:04 +00:00
Fix ''' ""'''
formatting (#7485)
## Summary `''' ""'''` is an edge case that was previously incorrectly formatted as `""" """""`. Fixes #7460 ## Test Plan Added regression test
This commit is contained in:
parent
70ea49bf72
commit
c4d85d6fb6
3 changed files with 28 additions and 4 deletions
|
@ -543,10 +543,21 @@ fn preferred_quotes(
|
|||
// `""` or `''`
|
||||
chars.next();
|
||||
|
||||
if chars.peek().copied() == Some(configured_quote_char) {
|
||||
// `"""` or `'''`
|
||||
chars.next();
|
||||
uses_triple_quotes = true;
|
||||
match chars.peek().copied() {
|
||||
Some(c) if c == configured_quote_char => {
|
||||
// `"""` or `'''`
|
||||
chars.next();
|
||||
uses_triple_quotes = true;
|
||||
break;
|
||||
}
|
||||
Some(_) => {}
|
||||
None => {
|
||||
// Handle `''' ""'''`. At this point we have consumed both
|
||||
// double quotes, so on the next iteration the iterator is empty
|
||||
// and we'd miss the string ending with a preferred quote
|
||||
uses_triple_quotes = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(_) => {
|
||||
|
@ -555,6 +566,7 @@ fn preferred_quotes(
|
|||
None => {
|
||||
// Trailing quote at the end of the comment
|
||||
uses_triple_quotes = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue