Swiftformat: Linebreaks before ending parenthesis in function calls should be a rule

Created on 20 Aug 2018  路  4Comments  路  Source: nicklockwood/SwiftFormat

Let's take the call to the UIView initializer init(frame:) as an example.

UIView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: 0, height: 0)))

I have a strong preference for applying linebreaks to this call like so:

UIView(
  frame: CGRect(
    origin: CGPoint(
      x: 0,
      y: 0),
    size: CGSize(
      width: 0,
      height: 0)))

I think this is the more readable option, as it is visually reminiscent of a list of bullet points:

  • UIView

    • frame

    • origin



      • x


      • y



    • size



      • width


      • height



However, SwiftFormat currently dictates the following structure:

UIView(
  frame: CGRect(
    origin: CGPoint(
      x: 0,
      y: 0
    ),
    size: CGSize(
      width: 0,
      height: 0
    )
  )
)

Every line taken up by a single ) adds no extra visual information to the code and is therefore, in my opinion, a waste of space.

I propose exposing this behavior as a rule to allow for customization.

All 4 comments

@sebastianfrelle seems reasonable.

@sebastianfrelle (note: while there is currently no way to make SwiftFormat enforce your preferred style, if you wish to allow this style to pass through unmodified, use --disable wrapArguments)

@sebastianfrelle I鈥檝e added a new --closingparen option in 0.35.3 to control this.

@nicklockwood Never got around to saying thank you. I appreciate the work that went into this addition.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Cyberbeni picture Cyberbeni  路  4Comments

MaxDesiatov picture MaxDesiatov  路  4Comments

meherkasam picture meherkasam  路  3Comments

shripada picture shripada  路  3Comments

igorkulman picture igorkulman  路  3Comments