-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fluent formatting of method chains #21369
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
27 commits
Select commit
Hold shift + click to select a range
73a6f47
refactor: stable logic for applying fluent layout
dylwil3 6cc18dd
implement preview layout
dylwil3 8ba316d
snapshots
dylwil3 2a5d66b
implement preview: use fluent more often
dylwil3 b924cd6
snapshots
dylwil3 0791678
add some doc-comments
dylwil3 295f5a5
add user-facing documentation
dylwil3 4a1054c
add links to preview.rs
dylwil3 43d9566
simplify from_expression for CallChainLayout
dylwil3 cb73474
revert using fluent more often for now
dylwil3 5ad1591
reword doc comment
dylwil3 f247c39
doc comments for AttributeState
dylwil3 d9d9416
clippy
dylwil3 a991e00
more tests
dylwil3 c1f748d
clarify attribute state changes in comment
dylwil3 9781d28
add fixture with parenthesized root
dylwil3 bb90d55
attempt to better name and document things
dylwil3 7cfaa1f
update snapshot with parenthesized example
dylwil3 b0e879d
resolve conflicts and update snapshot
dylwil3 6fdb35a
re-add pr link dropped in merge
dylwil3 20579c3
typo in comment
dylwil3 f9780ed
link to preview function
dylwil3 b2fc41d
add dedicated small fixtures for fluent formatting
dylwil3 02535ae
comment clarifying break after np pl pd etc.
dylwil3 003632b
chage names to use CallLike
dylwil3 e372e92
is_fluent helper
dylwil3 fd3405b
clippy
dylwil3 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
1 change: 1 addition & 0 deletions
1
crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.options.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| [{"line_width":8}] |
35 changes: 35 additions & 0 deletions
35
crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Fixtures for fluent formatting of call chains | ||
| # Note that `fluent.options.json` sets line width to 8 | ||
|
|
||
|
|
||
| x = a.b() | ||
|
|
||
| x = a.b().c() | ||
|
|
||
| x = a.b().c().d | ||
|
|
||
| x = a.b.c.d().e() | ||
|
|
||
| x = a.b.c().d.e().f.g() | ||
|
|
||
| # Consecutive calls/subscripts are grouped together | ||
| # for the purposes of fluent formatting (though, as 2025.12.15, | ||
| # there may be a break inside of one of these | ||
| # calls/subscripts, but that is unrelated to the fluent format.) | ||
|
|
||
| x = a()[0]().b().c() | ||
|
|
||
| x = a.b()[0].c.d()[1]().e | ||
|
|
||
| # Parentheses affect both where the root of the call | ||
| # chain is and how many calls we require before applying | ||
| # fluent formatting (just 1, in the presence of a parenthesized | ||
| # root, as of 2025.12.15.) | ||
|
|
||
| x = (a).b() | ||
|
|
||
| x = (a()).b() | ||
|
|
||
| x = (a.b()).d.e() | ||
|
|
||
| x = (a.b().d).e() |
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
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
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
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
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.