Skip to content
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

Ending trailing comma when splitting opening/closing bracket over multiple lines #100

Open
omus opened this issue Aug 30, 2021 · 0 comments

Comments

@omus
Copy link
Contributor

omus commented Aug 30, 2021

Based upon the discussion in domluna/JuliaFormatter.jl#455 I think there may be some clarification needed on the use of trailing comma when multiple arguments are on the same line. The intent of this section seems to imply that a trailing comma should always be used when an ending bracket does not immediately proceed the last argument:

Assignments using expanded notation for arrays or tuples, or function calls should have the first open bracket on the same line assignment operator and the closing bracket should match the indentation level of the assignment. Alternatively you can perform assignments on a single line when they are short:

arr = [
    1,
    2,
    3,
]
arr = [
    1, 2, 3,
]
result = Function(
    arg1,
    arg2,
)
arr = [1, 2, 3]

Some concrete examples of what this interpretation implies:

result = Function(
    arg1, arg2,
)
result = Function(arg1, arg2)

The original intent on having a trailing comma at all was to reduce the diff churn when additional arguments were added at the end of the list. This is definitely the most important when having an single argument on each line.

Related: we may also want to define some rules around when to switch between using:

# 1
f(a, b)

# 2
f(
    a, b,
)

#3 
f(
    a,
    b,
)

It appears that the JuliaFormatter often prefers #2 and only uses #3 when the argument list is so long that it extends beyond the line length. Personally, I'd prefer if the formatter left the call to use #2 or #3 up to discretion the writer and just enforces that one of the preferred styles is used.

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

No branches or pull requests

1 participant