Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider raw source code for W605 #10480

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@
value = rf'\{1}'
value = rf'{1:\}'
value = f"{rf"\{1}"}"

# Regression tests for https://github.com/astral-sh/ruff/issues/10434
f"{{}}+-\d"
f"\n{{}}+-\d+"
f"\n{{}}�+-\d+"
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ pub(crate) fn invalid_escape_sequence(
token_range: TextRange,
) {
let (token_source_code, string_start_location, kind) = match token {
Tok::FStringMiddle { value, kind } => {
Tok::FStringMiddle { kind, .. } => {
if kind.is_raw_string() {
return;
}
let Some(range) = indexer.fstring_ranges().innermost(token_range.start()) else {
let Some(f_string_range) = indexer.fstring_ranges().innermost(token_range.start())
else {
Comment on lines -74 to +75
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be explicit that this is the entire f-string range.

return;
};
(&**value, range.start(), kind)
(locator.slice(token_range), f_string_range.start(), kind)
}
Tok::String { kind, .. } => {
if kind.is_raw_string() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,55 @@ W605_1.py:48:15: W605 [*] Invalid escape sequence: `\{`
50 50 | # Okay
51 51 | value = rf'\{{1}}'

W605_1.py:57:9: W605 [*] Invalid escape sequence: `\d`
|
56 | # Regression tests for https://github.com/astral-sh/ruff/issues/10434
57 | f"{{}}+-\d"
| ^^ W605
58 | f"\n{{}}+-\d+"
59 | f"\n{{}}�+-\d+"
|
= help: Use a raw string literal

ℹ Safe fix
54 54 | value = f"{rf"\{1}"}"
55 55 |
56 56 | # Regression tests for https://github.com/astral-sh/ruff/issues/10434
57 |-f"{{}}+-\d"
57 |+rf"{{}}+-\d"
58 58 | f"\n{{}}+-\d+"
59 59 | f"\n{{}}�+-\d+"

W605_1.py:58:11: W605 [*] Invalid escape sequence: `\d`
|
56 | # Regression tests for https://github.com/astral-sh/ruff/issues/10434
57 | f"{{}}+-\d"
58 | f"\n{{}}+-\d+"
| ^^ W605
59 | f"\n{{}}�+-\d+"
|
= help: Add backslash to escape sequence

ℹ Safe fix
55 55 |
56 56 | # Regression tests for https://github.com/astral-sh/ruff/issues/10434
57 57 | f"{{}}+-\d"
58 |-f"\n{{}}+-\d+"
58 |+f"\n{{}}+-\\d+"
59 59 | f"\n{{}}�+-\d+"

W605_1.py:59:12: W605 [*] Invalid escape sequence: `\d`
|
57 | f"{{}}+-\d"
58 | f"\n{{}}+-\d+"
59 | f"\n{{}}�+-\d+"
| ^^ W605
|
= help: Add backslash to escape sequence

ℹ Safe fix
56 56 | # Regression tests for https://github.com/astral-sh/ruff/issues/10434
57 57 | f"{{}}+-\d"
58 58 | f"\n{{}}+-\d+"
59 |-f"\n{{}}�+-\d+"
59 |+f"\n{{}}�+-\\d+"
Loading