Slice source code instead of generating it for EM fixes#7746
Merged
dhruvmanila merged 1 commit intomainfrom Nov 9, 2023
Merged
Slice source code instead of generating it for EM fixes#7746dhruvmanila merged 1 commit intomainfrom
EM fixes#7746dhruvmanila merged 1 commit intomainfrom
Conversation
Member
Author
|
Current dependencies on/for this PR: This stack of pull requests is managed by Graphite. |
crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs
Outdated
Show resolved
Hide resolved
This comment was marked as outdated.
This comment was marked as outdated.
b861379 to
346ee92
Compare
346ee92 to
a61a608
Compare
Contributor
|
ea28834 to
451acea
Compare
dhruvmanila
commented
Nov 9, 2023
Comment on lines
+280
to
+285
| format!( | ||
| "msg = ({line_ending}{stmt_indentation}{indentation}{}{line_ending}{stmt_indentation}){line_ending}{stmt_indentation}", | ||
| locator.slice(exc_arg.range()), | ||
| line_ending = stylist.line_ending().as_str(), | ||
| indentation = stylist.indentation().as_str(), | ||
| ) |
Member
Author
There was a problem hiding this comment.
Is this too much? 😅
We can just keep a simple format!("msg = ({}){}{}") instead.
charliermarsh
approved these changes
Nov 9, 2023
| 74 74 | | ||
| 75 75 | def f_multi_line_string2(): | ||
| 76 |- raise RuntimeError( | ||
| 76 |+ msg = ( |
Member
There was a problem hiding this comment.
So these probably should be omitted, right? But we don't have a general way to know if the inner expression needs parentheses, right?
451acea to
8f8a6c0
Compare
8f8a6c0 to
314c9ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR fixes the bug where the generated fix for
EM*rules would replace atriple-quoted (f-)string with a single-quoted (f-)string. This changes the
semantic of the string in case it contains a single-quoted string literal. This
is especially evident with f-strings where the expression could contain another
string within it. For example,
f"""normal {"another"} normal"""Test Plan
Add test case for triple-quoted string and update the snapshots.
fixes: #6988
fixes: #7736