mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Revert "Use correct range to highlight line continuation error" (#12089)
This PR reverts https://github.com/astral-sh/ruff/pull/12016 with a small change where the error location points to the continuation character only. Earlier, it would also highlight the whitespace that came before it. The motivation for this change is to avoid panic in https://github.com/astral-sh/ruff/pull/11950. For example: ```py \) ``` Playground: https://play.ruff.rs/87711071-1b54-45a3-b45a-81a336a1ea61 The range of `Unknown` token and `Rpar` is the same. Once #11950 is enabled, the indexer would panic. It won't panic in the stable version because we stop at the first `Unknown` token.
This commit is contained in:
parent
6a37d7a1e6
commit
434ce307a7
3 changed files with 8 additions and 8 deletions
|
@ -404,7 +404,7 @@ impl std::fmt::Display for LexicalErrorType {
|
|||
write!(f, "Got unexpected token {tok}")
|
||||
}
|
||||
LexicalErrorType::LineContinuationError => {
|
||||
write!(f, "unexpected character after line continuation character")
|
||||
write!(f, "Expected a newline after line continuation character")
|
||||
}
|
||||
LexicalErrorType::Eof => write!(f, "unexpected EOF while parsing"),
|
||||
LexicalErrorType::OtherError(msg) => write!(f, "{msg}"),
|
||||
|
|
|
@ -247,7 +247,7 @@ impl<'src> Lexer<'src> {
|
|||
} else if !self.cursor.eat_char('\n') {
|
||||
return Some(self.push_error(LexicalError::new(
|
||||
LexicalErrorType::LineContinuationError,
|
||||
TextRange::at(self.offset(), self.cursor.first().text_len()),
|
||||
TextRange::at(self.offset() - '\\'.text_len(), '\\'.text_len()),
|
||||
)));
|
||||
}
|
||||
indentation = Indentation::root();
|
||||
|
@ -339,7 +339,7 @@ impl<'src> Lexer<'src> {
|
|||
} else if !self.cursor.eat_char('\n') {
|
||||
return Err(LexicalError::new(
|
||||
LexicalErrorType::LineContinuationError,
|
||||
TextRange::at(self.offset(), self.cursor.first().text_len()),
|
||||
TextRange::at(self.offset() - '\\'.text_len(), '\\'.text_len()),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue