-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Keep lambda parameters on one line and parenthesize the body if it expands #21385
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
Merged
Merged
Changes from all commits
Commits
Show all changes
103 commits
Select commit
Hold shift + click to select a range
1e70c99
baseline test cases
ntBre 8cc8844
keep lambda parameters on a single line
ntBre 1b58643
wip: parenthesize long lambda bodies
ntBre 74093bd
add a poorly formatted case from the ecosystem report
ntBre a5e13cf
add an unstable test case from ecosystem report
ntBre 62c968c
rough draft of ExprLambdaLayout::Assignment
ntBre d68a03a
add another bad case from the ecosystem check
ntBre 07bcf41
fix binary expression in lambda in return
ntBre 6b47664
add another bad test case from the ecosystem report
ntBre f634bb5
propagate lambda layout for annotated assignments
ntBre ad31477
another bad test for long bodies with their own parens
ntBre 9db5d43
possibly bad test for triple-quoted f-strings
ntBre 24e15bf
exclude call and subscript expressions from has_own_parentheses
ntBre 0a41abe
avoid lambda special-casing in maybe_parenthesize_expression
ntBre e9f9507
add some assignment tests with parentheses and comments
ntBre 89dc1ad
add a couple more test cases
ntBre 18a3d59
use write!
ntBre 972129c
create id only in indented case, update group name
ntBre 2e95002
avoid nesting groups
ntBre 9785066
add too-eagerly parenthesized case from ecosystem
ntBre efa372b
apply Micha's patch, fixing everything?
ntBre 6f6c09c
fix snapshot changes for cases with comments
ntBre 9ef9d03
fix another ecosystem call expansion
ntBre a3400a0
use parenthesize_if_expands for fluent call chains
ntBre 258b1fd
add wrapping case from the ecosystem check
ntBre 04963a6
expand parent if the lambda body breaks
ntBre 7dddcc8
remove comment
ntBre afb01ce
combine preview checks
ntBre 2e84402
add comments and some supporting tests
ntBre 3a20c6f
copy mapper test case from can_omit_optional_parentheses
ntBre bdd5ba5
gate optional_parentheses branches behind stable
ntBre 1a3e385
Merge branch 'main' into brent/indent-lambda-params
ntBre 08b1da3
mirror comment handling from `maybe_parenthesize_expression`
ntBre dfd3460
add some more tests
ntBre 219bbd1
check comment case first
ntBre a4b4a82
add another dangling eol case
ntBre 43b53ed
improve dangling header comment placement
ntBre dc240a1
clippy
ntBre 5605387
add another dangling case between lambda and parameters
ntBre 25d70b4
more tests
ntBre c766642
block indent and trailing comments
ntBre fe255d1
leading_comments in block
ntBre 8cbe03b
add more cases without parameters
ntBre c62390d
try parenthesizing the body without parameters
ntBre 4585a0b
Revert "try parenthesizing the body without parameters"
ntBre 3c481ba
factor out preview variable
ntBre 4d76cd7
factor out parameters_have_comments
ntBre 80852c1
pairing
ntBre 86406c0
wip
ntBre 1531c94
revert the last two commits, back to a stable formatting
ntBre 0710e0b
fix assignment instability with dangling comments
ntBre df42aa2
Reapply "try parenthesizing the body without parameters"
ntBre f20f3e0
fix assignment instability without parameters too
ntBre 8ede14a
move comments within lambda parameters to dangling lambda comments
ntBre e8540d9
format new dangling comments
ntBre c7b1089
apply patch
ntBre ea30464
clippy
ntBre 21b442a
accept snapshots
ntBre 711dd6e
pass preview to handle_lambda_comment
ntBre 4ffbd49
Merge branch 'main' into brent/indent-lambda-params
ntBre 90f43bd
add broken test cases
ntBre b0a8298
avoid breaking when the first parameter has leading comments
ntBre 65c9435
Merge branch 'brent/fix-kwargs' into brent/indent-lambda-params
ntBre fd34cd6
update snaps
ntBre b823866
revert preview and comment placement changes
ntBre 2bd6409
revert FormatParameters changes
ntBre d722155
make comments leading on parameter_s_
ntBre f639389
simplify check with parameters.start() == parameter.start()
ntBre 9d683da
simplify a bit further
ntBre 2da4798
update comments
ntBre acc49ac
remove redundant parameters check
ntBre 2e0ee2e
update lambda comment
ntBre 829f105
Merge branch 'brent/fix-kwargs' into brent/indent-lambda-params
ntBre 54c7689
clean up deref
ntBre 05ff8f5
Merge branch 'main' into brent/indent-lambda-params
ntBre bb053f8
fix lambda formatting in assignments
ntBre 6e9e42d
factor out maybe_parenthesize_lambda
ntBre 33fcca9
re-apply 'pass preview to handle_lambda_comment'
ntBre 9f9b76b
move preview comment handling mostly into placement.rs
ntBre a8bebaa
add preview function taking a PreviewMode
ntBre f999da0
move tokenizer checks into the stable branch
ntBre 7c94e10
update lambda placement docs
ntBre 8022343
maybe_parenthesize_lambda -> maybe_parenthesize_value
ntBre b96cf96
add a few more call tests with comments
ntBre 553b45e
move dangling comment handling back out of placement.rs
ntBre 9d7d94c
factor out FormatBody
ntBre 2cb98d4
working for Micha's exact example
ntBre 8711b1a
Revert leading comment changes
ntBre 0f1ea90
reposition dangling comments
ntBre 5fee753
save f.context.comments() to comments
ntBre d1b79f5
share common code
ntBre 854062f
inline format_body
ntBre 6f25547
delete outdated preview comments
ntBre 0074515
consolidate preview checks
ntBre 3dfda9f
unwrap format_body
ntBre a48dc8e
inline current FormatBody
ntBre b80fdfa
move all body formatting to FormatBody
ntBre 4a66edf
inline parameters_have_comments
ntBre 93a958a
share dangling comment logic
ntBre 17a1065
consolidate layout and preview checks
ntBre d24895d
comment on leading_body_comments
ntBre 3011190
improve dangling name and docs
ntBre 95301b3
improve after_parameters_end_of_line name and docs
ntBre 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
533 changes: 533 additions & 0 deletions
533
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/lambda.py
Large diffs are not rendered by default.
Oops, something went wrong.
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
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.
Uh oh!
There was an error while loading. Please reload this page.