Skip to content

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

@omus

Description

@omus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions