mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Fix continuation detection following multi-line strings (#9332)
## Summary The logic that detects continuations assumed that tokens themselves cannot span multiple lines. However, strings _can_ -- even single-quoted strings. Closes https://github.com/astral-sh/ruff/issues/9323.
This commit is contained in:
parent
003851c41d
commit
b3789cd9e9
4 changed files with 91 additions and 2 deletions
|
@ -62,13 +62,22 @@ impl Indexer {
|
|||
comment_ranges_builder.visit_token(tok, *range);
|
||||
fstring_ranges_builder.visit_token(tok, *range);
|
||||
|
||||
if matches!(tok, Tok::Newline | Tok::NonLogicalNewline) {
|
||||
line_start = range.end();
|
||||
match tok {
|
||||
Tok::Newline | Tok::NonLogicalNewline => {
|
||||
line_start = range.end();
|
||||
}
|
||||
Tok::String { .. } => {
|
||||
// If the previous token was a string, find the start of the line that contains
|
||||
// the closing delimiter, since the token itself can span multiple lines.
|
||||
line_start = locator.line_start(range.end());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
prev_token = Some(tok);
|
||||
prev_end = range.end();
|
||||
}
|
||||
|
||||
Self {
|
||||
comment_ranges: comment_ranges_builder.finish(),
|
||||
continuation_lines,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue