mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 10:00:42 +00:00
Raise syntax error when \
is at end of file (#17409)
## Summary This PR fixes a bug in the lexer specifically around line continuation character at end of file. The reason this was occurring is because the lexer wouldn't check for EOL _after_ consuming the escaped newline but only if the EOL was right after the line continuation character. fixes: #17398 ## Test Plan Add tests for the scenarios where this should occur mainly (a) when the state is `AfterNewline` and (b) when the state is `Other`.
This commit is contained in:
parent
942cb9e3ad
commit
bfc17fecaa
7 changed files with 223 additions and 7 deletions
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: line_continuation_at_eof_after_newline(MAC_EOL)
|
||||
---
|
||||
## Tokens
|
||||
```
|
||||
[
|
||||
(
|
||||
Unknown,
|
||||
0..2,
|
||||
),
|
||||
]
|
||||
```
|
||||
## Errors
|
||||
```
|
||||
[
|
||||
LexicalError {
|
||||
error: Eof,
|
||||
location: 0..2,
|
||||
},
|
||||
]
|
||||
```
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: line_continuation_at_eof_after_newline(UNIX_EOL)
|
||||
---
|
||||
## Tokens
|
||||
```
|
||||
[
|
||||
(
|
||||
Unknown,
|
||||
0..2,
|
||||
),
|
||||
]
|
||||
```
|
||||
## Errors
|
||||
```
|
||||
[
|
||||
LexicalError {
|
||||
error: Eof,
|
||||
location: 0..2,
|
||||
},
|
||||
]
|
||||
```
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: line_continuation_at_eof_after_newline(WINDOWS_EOL)
|
||||
---
|
||||
## Tokens
|
||||
```
|
||||
[
|
||||
(
|
||||
Unknown,
|
||||
0..3,
|
||||
),
|
||||
]
|
||||
```
|
||||
## Errors
|
||||
```
|
||||
[
|
||||
LexicalError {
|
||||
error: Eof,
|
||||
location: 0..3,
|
||||
},
|
||||
]
|
||||
```
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: line_continuation_at_eof(MAC_EOL)
|
||||
---
|
||||
## Tokens
|
||||
```
|
||||
[
|
||||
(
|
||||
Int(
|
||||
1,
|
||||
),
|
||||
0..1,
|
||||
),
|
||||
(
|
||||
Comma,
|
||||
1..2,
|
||||
),
|
||||
(
|
||||
Unknown,
|
||||
2..5,
|
||||
),
|
||||
(
|
||||
Newline,
|
||||
5..5,
|
||||
),
|
||||
]
|
||||
```
|
||||
## Errors
|
||||
```
|
||||
[
|
||||
LexicalError {
|
||||
error: Eof,
|
||||
location: 2..5,
|
||||
},
|
||||
]
|
||||
```
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: line_continuation_at_eof(UNIX_EOL)
|
||||
---
|
||||
## Tokens
|
||||
```
|
||||
[
|
||||
(
|
||||
Int(
|
||||
1,
|
||||
),
|
||||
0..1,
|
||||
),
|
||||
(
|
||||
Comma,
|
||||
1..2,
|
||||
),
|
||||
(
|
||||
Unknown,
|
||||
2..5,
|
||||
),
|
||||
(
|
||||
Newline,
|
||||
5..5,
|
||||
),
|
||||
]
|
||||
```
|
||||
## Errors
|
||||
```
|
||||
[
|
||||
LexicalError {
|
||||
error: Eof,
|
||||
location: 2..5,
|
||||
},
|
||||
]
|
||||
```
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: line_continuation_at_eof(WINDOWS_EOL)
|
||||
---
|
||||
## Tokens
|
||||
```
|
||||
[
|
||||
(
|
||||
Int(
|
||||
1,
|
||||
),
|
||||
0..1,
|
||||
),
|
||||
(
|
||||
Comma,
|
||||
1..2,
|
||||
),
|
||||
(
|
||||
Unknown,
|
||||
2..6,
|
||||
),
|
||||
(
|
||||
Newline,
|
||||
6..6,
|
||||
),
|
||||
]
|
||||
```
|
||||
## Errors
|
||||
```
|
||||
[
|
||||
LexicalError {
|
||||
error: Eof,
|
||||
location: 2..6,
|
||||
},
|
||||
]
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue