-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[flake8-simplify] Fix raw string handling in SIM905 for embedded quotes
#19591
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
Conversation
|
dylwil3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thank you! A couple of nits and then a design point:
I think we should gate this fix behavior under preview, and when not in preview just skip the check in this situation.
The reason is that it's unclear to me if the best thing to do here is to offer your fix (which would change part of a raw string into a string with escapes), to skip the check here, or to offer the fix with the "ugly" triple quotes for the relevant list items (or some compromise - like offer your fix but make it Unsafe). On the other hand, we have to do something to fix the syntax error, and I think this arrangements allows us to consider the other options in the meantime without making a breaking change.
(But I could be overruled on this)
crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs
Show resolved
Hide resolved
At least in the example from #19577, there are no embedded single quote characters, so one should be able to cleanly convert it to a raw single quoted string without needing to add any additional escaping: test_email_addresses = [
r"[email protected]",
r"[email protected]",
r"[email protected]",
r"[email protected]",
r"[email protected]",
r"[email protected]",
r"name/[email protected]",
r"[email protected]",
r'" "@example.org',
r'"john..doe"@example.org',
r"[email protected]",
r'"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com',
r"user%[email protected]",
r"[email protected]",
r"I❤️[email protected]",
r"this\ still\"not\\[email protected]",
r"[email protected]",
r"[email protected]",
r"user+mailbox/[email protected]",
r"!#$%&'*+-/=?^_`.{|}[email protected]",
r'"Abc@def"@example.com',
r'"Fred\ Bloggs"@example.com',
r'"Joe.\\Blow"@example.com',
]In (rare) cases where a triple quoted string does include both single and double quote characters, I would argue that the keeping the triple quotes for those items would be better than adding escaping, which would make the resulting items very difficult to read, especially if they already include backslash characters. |
|
That's a good point @tdulcet , thank you! I think at that point it's maybe unobtrusive enough to fix the bug this way without gating behind preview. Let me know if the new snapshots look objectionable - otherwise I'll merge this in shortly |
dylwil3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @danparizher !
flake8_simplify] Fix raw string handling in SIM905 for embedded quotesflake8-simplify] Fix raw string handling in SIM905 for embedded quotes
Summary
Fixes #19577