Skip to content

Commit

Permalink
Do it without the regex
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Feb 9, 2024
1 parent eb19a92 commit 6fa2c43
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,10 +902,13 @@ fn multiline_string_sequence_postlude<'a>(
// and so that the final item has a trailing comma.
// This produces formatting more similar
// to that which the formatter would produce.
let parenthesis_re = regex::Regex::new(r"^,?([\])}])$").unwrap();
if let Some(captures) = parenthesis_re.captures(postlude) {
let closing_paren = &captures[1];
return Cow::Owned(format!(",{newline}{leading_indent}{closing_paren}"));
if postlude.len() <= 2 {
let mut reversed_postlude_chars = postlude.chars().rev();
if let Some(closing_paren @ (')' | '}' | ']')) = reversed_postlude_chars.next() {
if reversed_postlude_chars.next().map_or(true, |c| c == ',') {
return Cow::Owned(format!(",{newline}{leading_indent}{closing_paren}"));
}
}
}

let newline_chars = ['\r', '\n'];
Expand Down

0 comments on commit 6fa2c43

Please sign in to comment.