JuliaDiff / JuliaDiff/BlueStyle

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

Open
#100 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
519
Forks
34
PR merge metrics
No merged PRs in 30d

Description

Based upon the discussion in https://github.com/domluna/JuliaFormatter.jl/issues/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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the discussion in JuliaFormatter.jl issue 455 and the quoted BlueStyle guidance, then compare the examples for trailing commas and multiline calls. Done means the style guide clearly defines when trailing commas are required and how the preferred multiline argument styles should be selected.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.