mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Treat escaped newline as valid sequence (#11465)
## Summary We weren't treating the escaped newline as a valid condition to trigger the safer fix (add an extra backslash before each invalid escape sequence). Closes https://github.com/astral-sh/ruff/issues/11461.
This commit is contained in:
parent
48b0660228
commit
cfceb437a8
3 changed files with 71 additions and 0 deletions
|
@ -46,3 +46,15 @@ regex = '\\\_'
|
|||
|
||||
#: W605:1:7
|
||||
u'foo\ bar'
|
||||
|
||||
#: W605:1:13
|
||||
(
|
||||
"foo \
|
||||
bar \. baz"
|
||||
)
|
||||
|
||||
#: W605:1:6
|
||||
"foo \. bar \t"
|
||||
|
||||
#: W605:1:13
|
||||
"foo \t bar \."
|
||||
|
|
|
@ -181,6 +181,7 @@ fn check(
|
|||
|
||||
// If we're at the end of line, skip.
|
||||
if matches!(next_char, '\n' | '\r') {
|
||||
contains_valid_escape_sequence = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -145,6 +145,8 @@ W605_0.py:48:6: W605 [*] Invalid escape sequence: `\ `
|
|||
47 | #: W605:1:7
|
||||
48 | u'foo\ bar'
|
||||
| ^^ W605
|
||||
49 |
|
||||
50 | #: W605:1:13
|
||||
|
|
||||
= help: Use a raw string literal
|
||||
|
||||
|
@ -154,5 +156,61 @@ W605_0.py:48:6: W605 [*] Invalid escape sequence: `\ `
|
|||
47 47 | #: W605:1:7
|
||||
48 |-u'foo\ bar'
|
||||
48 |+r'foo\ bar'
|
||||
49 49 |
|
||||
50 50 | #: W605:1:13
|
||||
51 51 | (
|
||||
|
||||
W605_0.py:53:9: W605 [*] Invalid escape sequence: `\.`
|
||||
|
|
||||
51 | (
|
||||
52 | "foo \
|
||||
53 | bar \. baz"
|
||||
| ^^ W605
|
||||
54 | )
|
||||
|
|
||||
= help: Add backslash to escape sequence
|
||||
|
||||
ℹ Safe fix
|
||||
50 50 | #: W605:1:13
|
||||
51 51 | (
|
||||
52 52 | "foo \
|
||||
53 |- bar \. baz"
|
||||
53 |+ bar \\. baz"
|
||||
54 54 | )
|
||||
55 55 |
|
||||
56 56 | #: W605:1:6
|
||||
|
||||
W605_0.py:57:6: W605 [*] Invalid escape sequence: `\.`
|
||||
|
|
||||
56 | #: W605:1:6
|
||||
57 | "foo \. bar \t"
|
||||
| ^^ W605
|
||||
58 |
|
||||
59 | #: W605:1:13
|
||||
|
|
||||
= help: Add backslash to escape sequence
|
||||
|
||||
ℹ Safe fix
|
||||
54 54 | )
|
||||
55 55 |
|
||||
56 56 | #: W605:1:6
|
||||
57 |-"foo \. bar \t"
|
||||
57 |+"foo \\. bar \t"
|
||||
58 58 |
|
||||
59 59 | #: W605:1:13
|
||||
60 60 | "foo \t bar \."
|
||||
|
||||
W605_0.py:60:13: W605 [*] Invalid escape sequence: `\.`
|
||||
|
|
||||
59 | #: W605:1:13
|
||||
60 | "foo \t bar \."
|
||||
| ^^ W605
|
||||
|
|
||||
= help: Add backslash to escape sequence
|
||||
|
||||
ℹ Safe fix
|
||||
57 57 | "foo \. bar \t"
|
||||
58 58 |
|
||||
59 59 | #: W605:1:13
|
||||
60 |-"foo \t bar \."
|
||||
60 |+"foo \t bar \\."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue