Skip to content

Avoid nesting LHS if not over margin and if RHS can be nested#1012

Draft
penelopeysm wants to merge 2 commits into
masterfrom
py/prefer-nest-rhs
Draft

Avoid nesting LHS if not over margin and if RHS can be nested#1012
penelopeysm wants to merge 2 commits into
masterfrom
py/prefer-nest-rhs

Conversation

@penelopeysm
Copy link
Copy Markdown
Member

@penelopeysm penelopeysm commented May 30, 2026

This is an alternative solution for #998. Note: This PR is a bit too far-reaching to be really merged right now. It essentially does what the comments say. If we have a binary expression LHS op RHS, we try to avoid nesting the LHS if there is any point in the op RHS segment where we can nest it.

This leads to much improved output in some cases, for example, that in #998. However, it also causes some regressions. For example this causes

julia> str = "foo(a, b, c)::Rtype where {A,B} = 10"
"foo(a, b, c)::Rtype where {A,B} = 10"

julia> JuliaFormatter.format_text(str; indent=4, margin=32) |> println
foo(a, b, c)::Rtype where {
    A,
    B,
} = 10

when previously it would be formatted instead to

foo(
    a,
    b,
    c,
)::Rtype where {A,B} = 10

I still think that the solution in this PR is the correct way to deal with the nesting preference, but it needs to be more tightly scoped to avoid causing regressions in other cases that we aren't trying to improve.

@penelopeysm penelopeysm marked this pull request as draft May 30, 2026 17:54
@github-actions
Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant