[flynt] Use triple quotes for joined raw strings with newlines (FLY002)#20197
Conversation
|
ntBre
left a comment
There was a problem hiding this comment.
Thanks! I think we can simplify a bit, and there are also some edge cases we still need to handle.
crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs
Outdated
Show resolved
Hide resolved
ntBre
left a comment
There was a problem hiding this comment.
Thank you!
I'm a bit surprised that we don't offer a diagnostic at all if constructing the fix fails, but we can leave that as a separate issue too. I couldn't tell for sure from my brief read of the code, but maybe build_fstring is actually necessary to validate that the diagnostic applies too, not just the fix.
crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs
Outdated
Show resolved
Hide resolved
| // Prefer a delimiter that doesn't occur in the content; if both occur, bail. | ||
| if content.contains(flags.quote_str()) { | ||
| flags = flags.with_quote_style(flags.quote_style().opposite()); | ||
| if content.contains(flags.quote_str()) { | ||
| // Both "'''" and "\"\"\"" are present in content; avoid emitting | ||
| // an invalid raw triple-quoted literal (or escaping). Bail on the fix. | ||
| return None; | ||
| } | ||
| } |
There was a problem hiding this comment.
I think something like this would help with #19837 too, but it looks sufficiently different that we should leave it for a separate PR. I think we'd need this kind of check in one of the helpers below.
There was a problem hiding this comment.
Ok. I will try it in a different pull request:)
flynt] Use raw triple quotes for joined raw strings with newlinesflynt] Use triple quotes for joined raw strings with newlines (FLY002)
Summary
Fixes #19887
content contains a newline.
content.
\n'.join([r'line1','line2'])case.Test Plan
I've added one test case to FLY002.py.