Skip to content

[SR-15167] Weird newline with optional chaining #305

Open
@karwa

Description

@karwa
Previous ID SR-15167
Radar None
Original Reporter @karwa
Type Bug
Environment

swift-format 0.50300.0

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee None
Priority Medium

md5: 2f04a8858227c6ebd6c94f80e9e6a07e

Issue Description:

Given this input:

func test() {
  let result = newValue.withContiguousStorageIfAvailable {
    setNewValue($0)
  } ?? setNewValue(newValue)
}

For some reason, swift-format decides it would be better with a newline and if everything was indented:

func test() {
  let result =
    newValue.withContiguousStorageIfAvailable {
      setNewValue($0)
    } ?? setNewValue(newValue)
}

But I think this looks quite a lot worse. The actual body, involving wCSIA and the optional chaining, seems to be kept intact... it's just a bit lower and to the side. I'm not sure how that helps anything.

I'm not sure which rule is causing this or how to disable it, but I'd really like if swift-format could stop doing it. It's not a line-length issue: my max length is set at 120 and the original doesn't get anywhere near that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions