-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Hug multiline-strings preview style #9243
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
43 changes: 43 additions & 0 deletions
43
crates/ruff_python_formatter/resources/test/fixtures/ruff/multiline_string_deviations.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# This file documents the deviations for formatting multiline strings with black. | ||
|
||
# Black hugs the parentheses for `%` usages -> convert to fstring. | ||
# Can get unreadable if the arguments split | ||
# This could be solved by using `best_fitting` to try to format the arguments on a single | ||
# line. Let's consider adding this later. | ||
# ```python | ||
# call( | ||
# 3, | ||
# "dogsay", | ||
# textwrap.dedent( | ||
# """dove | ||
# coo""" % "cowabunga", | ||
# more, | ||
# and_more, | ||
# "aaaaaaa", | ||
# "bbbbbbbbb", | ||
# "cccccccc", | ||
# ), | ||
# ) | ||
# ``` | ||
call(3, "dogsay", textwrap.dedent("""dove | ||
coo""" % "cowabunga")) | ||
|
||
# Black applies the hugging recursively. We don't (consistent with the hugging style). | ||
path.write_text(textwrap.dedent("""\ | ||
A triple-quoted string | ||
actually leveraging the textwrap.dedent functionality | ||
that ends in a trailing newline, | ||
representing e.g. file contents. | ||
""")) | ||
|
||
|
||
|
||
# Black avoids parenthesizing the following lambda. We could potentially support | ||
# this by changing `Lambda::needs_parentheses` to return `BestFit` but it causes | ||
# issues when the lambda has comments. | ||
# Let's keep this as a known deviation for now. | ||
generated_readme = lambda project_name: """ | ||
{} | ||
|
||
<Add content here!> | ||
""".strip().format(project_name) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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 is a bug fix in the printer. So far, it always returned
Fits::Yes
if a text contained a newline character regardless if the text before the newline exceeded the line width. This was incorrect.