mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:49:50 +00:00
Avoid detecting continuations at non-start-of-line (#6219)
## Summary Previously, given: ```python a = \ 5; ``` When detecting continuations starting at the offset of the `;`, we'd flag the previous line as a continuation. We should only flag a continuation if there isn't leading content prior to the offset. Closes https://github.com/astral-sh/ruff/issues/6214
This commit is contained in:
parent
bf584c6d74
commit
88b984e885
3 changed files with 36 additions and 2 deletions
|
@ -228,8 +228,18 @@ impl Indexer {
|
|||
offset: TextSize,
|
||||
locator: &Locator,
|
||||
) -> Option<TextSize> {
|
||||
// Find the first preceding continuation.
|
||||
let mut continuation = self.find_continuation(locator.line_start(offset), locator)?;
|
||||
// Find the first preceding continuation. If the offset isn't the first non-whitespace
|
||||
// character on the line, then we can't have a continuation.
|
||||
let previous_line_end = locator.line_start(offset);
|
||||
if !locator
|
||||
.slice(TextRange::new(previous_line_end, offset))
|
||||
.chars()
|
||||
.all(is_python_whitespace)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut continuation = self.find_continuation(previous_line_end, locator)?;
|
||||
|
||||
// Continue searching for continuations, in the unlikely event that we have multiple
|
||||
// continuations in a row.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue