domluna / JuliaFormatter.jl

An opinionated code formatter for Julia. Plot twist - the opinion is your own.

Home Page:https://domluna.github.io/JuliaFormatter.jl/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

request: Line break before binary operators

stephen-huan opened this issue · comments

Currently

using JuliaFormatter: format_text

text = """
income = gross_wages +
          taxable_interest +
          (dividends - qualified_dividends) -
          ira_deduction -
          student_loan_interest
y = true && true && true && false && false
"""
println(format_text(text; margin=30))

formats to

income =
    gross_wages +
    taxable_interest +
    (dividends - qualified_dividends) -
    ira_deduction -
    student_loan_interest
y =
    true &&
    true &&
    true &&
    false &&
    false

Is it possible to instead break the line before the binary operator as

income =
    gross_wages
    + taxable_interest
    + (dividends - qualified_dividends)
    - ira_deduction
    - student_loan_interest
y = (
    true
    && true
    && true
    && false
    && false
)

as black and PEP 8 recommend for readability?

The documentation says

Binary operations and conditionals are nested back-to-front.

so I'm not sure how difficult this would be to implement.

Note that without the parentheses

y =
    true
    && true
    && true
    && false
    && false

is not valid Julia syntax so I'd also recommend an option to also add parentheses (#709) to

income = (
    gross_wages
    + taxable_interest
    + (dividends - qualified_dividends)
    - ira_deduction
    - student_loan_interest
)

for consistency.

Thanks!