-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
python312Related to Python 3.12Related to Python 3.12ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
W605 checks for invalid escape sequences in a string.
For f-strings, we'll be looking for the same in a FStringMiddle token which is the non-expression part of the f-string. The rule extracts the body part which excludes the quotes and also skips the validation if it's a raw string:
| let text = locator.slice(range); | |
| // Determine whether the string is single- or triple-quoted. | |
| let Some(leading_quote) = leading_quote(text) else { | |
| return; | |
| }; | |
| let Some(trailing_quote) = trailing_quote(text) else { | |
| return; | |
| }; | |
| let body = &text[leading_quote.len()..text.len() - trailing_quote.len()]; | |
| if leading_quote.contains(['r', 'R']) { | |
| return; | |
| } |
The FStringMiddle token contains both the above information for free. We just need to check if the token is a FStringMiddle or a String.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
python312Related to Python 3.12Related to Python 3.12ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule