-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Format assert
statement
#5168
Merged
Merged
Format assert
statement
#5168
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
239daa7
Format assert statement
cnpryer 55b21cb
Use black fixture
cnpryer 7739dd2
Move new assert fixture into ruff fixtures
cnpryer 9a87a00
Revert "Format assert statement"
cnpryer 5c48fb3
Merge branch 'main' into stmt-assert
cnpryer 919b3d5
Update tests
cnpryer b25e3f7
Accept some new snapshots
cnpryer 99b84a2
Update ruff fixture snapshot
cnpryer 3b57d8b
Accept more snapshots
cnpryer aaffdac
Small chore
cnpryer 19e646e
Merge branch 'main' into stmt-assert
cnpryer 41bfabf
Merge branch 'main' into stmt-assert
cnpryer 411f5ce
Use group if msg
cnpryer 1f9ea21
Accept some snapshots
cnpryer e3d1f1d
Small chore
cnpryer 4dfcb31
Use parenthesize_if_expands
cnpryer dc67b81
Accept more snapshots
cnpryer 8a79266
Update ruff fixture
cnpryer 26163d5
Merge branch 'main' into stmt-assert
cnpryer 5c4cf3d
Merge branch 'main' into stmt-assert
cnpryer e1bfaa8
Don't handle extra comments and all long strings
cnpryer 709c4a7
Don't use group
cnpryer 84a040b
Remove old snapshot
cnpryer 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
23 changes: 23 additions & 0 deletions
23
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/assert.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,23 @@ | ||
assert ( | ||
# Asserted | ||
) | ||
|
||
# Some assert | ||
assert ( | ||
# Let's go inside | ||
True # Go around this | ||
# Below that | ||
), "Some string" # Outside this way | ||
# Passed all that | ||
|
||
# Dangle this here | ||
|
||
# Some assert | ||
assert ( | ||
# Let's go inside | ||
True # Go around this | ||
# Below that | ||
|
||
# Dangle that there | ||
), "Some string" # Outside this way | ||
# Passed all that |
60 changes: 60 additions & 0 deletions
60
...ormatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__assert_py.snap
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,60 @@ | ||
--- | ||
source: crates/ruff_python_formatter/src/lib.rs | ||
expression: snapshot | ||
--- | ||
## Input | ||
```py | ||
assert ( | ||
# Asserted | ||
) | ||
|
||
# Some assert | ||
assert ( | ||
# Let's go inside | ||
True # Go around this | ||
# Below that | ||
), "Some string" # Outside this way | ||
# Passed all that | ||
|
||
# Dangle this here | ||
|
||
# Some assert | ||
assert ( | ||
# Let's go inside | ||
True # Go around this | ||
# Below that | ||
|
||
# Dangle that there | ||
), "Some string" # Outside this way | ||
# Passed all that | ||
``` | ||
|
||
|
||
|
||
## Output | ||
```py | ||
assert ( | ||
# Asserted | ||
) | ||
|
||
# Some assert | ||
assert ( | ||
# Let's go inside | ||
True # Go around this | ||
# Below that | ||
), "Some string" # Outside this way | ||
# Passed all that | ||
|
||
# Dangle this here | ||
|
||
# Some assert | ||
assert ( | ||
# Let's go inside | ||
True # Go around this | ||
# Below that | ||
# Dangle that there | ||
), "Some string" # Outside this way | ||
# Passed all that | ||
``` | ||
|
||
|
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.
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.
Nit: I prefer to keep the shared logic outside of the
if..else
branches. It avoids that the reader has to parse both branches of the if statement to identify what's difference between themThere 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.
For sure!
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.
aaffdac
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.
Tbh I don't even see this as a nit lol.
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.
I ended up adding a
group
, so I've deviated from your suggestion. I'm still finding my feet with some of this stuff, so feel free to tell me to stop over-implementing this.I'd want to format this next
And then finally figure out comment placement, but I can rip out the fixture I've added for that and follow up after this is merged.
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.
🎉 709c4a7
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.
Nice. Yeah, it can sometimes be very subtle.