mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-19 02:55:20 +00:00
Do not include newline for unterminated string range (#12017)
## Summary This PR updates the unterminated string error range to not include the final newline character. This is a follow-up to #12016 and required for #12019 This is not done for when the unterminated string goes till the end of file (not a newline character). The unterminated f-string range is correct. ### Why is this required for #12019 ? Because otherwise the token ranges will overlap. For example: ```py f"{" f"{foo!r" ``` Here, the re-lexing logic recovers from an unterminated f-string and thus emitting a `Newline` token for the one at the end of the first line. But, currently the `Unknown` and the `Newline` token would overlap because the `Unknown` token (unterminated string literal) range would include the newline character. ## Test Plan Update and validate the snapshot.
This commit is contained in:
parent
9c1b6ec411
commit
d930e97212
5 changed files with 53 additions and 65 deletions
|
@ -973,10 +973,10 @@ impl<'src> Lexer<'src> {
|
|||
}
|
||||
|
||||
match ch {
|
||||
Some('\r' | '\n') => {
|
||||
Some(newline @ ('\r' | '\n')) => {
|
||||
return self.push_error(LexicalError::new(
|
||||
LexicalErrorType::UnclosedStringError,
|
||||
self.token_range(),
|
||||
self.token_range().sub_end(newline.text_len()),
|
||||
));
|
||||
}
|
||||
Some(ch) if ch == quote => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue