SwiftLint
SwiftLint copied to clipboard
`opening_brace` on separate line should be permissible
New Issue Checklist
- [x] Updated SwiftLint to the latest version
- [x] I searched for existing GitHub issues
Describe the bug
opening_brace
does not permit the brace to open on a separate line. However, this restriction can be excessive.
Some examples of cases where it might be very reasonable to open a block on its own line:
When a block takes another block as a return value:
destination: self.model.member.flatMap { member in
{ self.presenter?.detailsPresenter(for: member).view }
}
When a block is an option in a ternary:
destination: !slot.screens.isEmpty ?
{ self.router.screenshots(for: slot.screens, metrics: segment.metrics).featurePresenter } :
{ self.router.members(with: self.members.eraseToAnyChoice()).featurePresenter }
@lhunath Did you consider formatting the ternary differently?
destination: !slot.screens.isEmpty
? { self.router.screenshots(for: slot.screens, metrics: segment.metrics).featurePresenter }
: { self.router.members(with: self.members.eraseToAnyChoice()).featurePresenter }
perhaps, but I don't think forcing a different code style onto a project can be a solution.
Adding another example to this, I made an array of closures formatted like this:
let predicates: [(SearchToken, SearchToken) -> Bool] = [
{ $0.searchText.starts(with: search) && !$1.searchText.starts(with: search) },
{ $0.scope != .bar && $1.scope == .bar },
{ $0.searchText.levenshteinDistance(to: search) < $1.searchText.levenshteinDistance(to: search) }
]
SwiftLint autofix puts everything on a single line, and then fails because the line length is too long.