nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.93k stars 640 forks source link

`blankLinesBetweenScopes` inserts newline between properties with multiline initializers. #1050

Open lhunath opened 3 years ago

lhunath commented 3 years ago

Given the following code:

class A {
    var a = 1
    var b = 2
    lazy var c = 3
    lazy var d = 4
    lazy var e = {
        5
    }()
    lazy var f = {
        6
    }()
}

The blankLinesBetweenScopes rule appears to insert a newline before the f member. This is unexpected.

Practical example:

    private let router:         TaskDetailsRouter
    private let task:           Task
    private var detailsMonitor: AnyCancellable?
    private lazy var dateFormatter = using(DateFormatter()) {
        $0.dateStyle = .medium
        $0.timeStyle = .none
    }

    private lazy var timeFormatter = using(DateFormatter()) {
        $0.dateStyle = .none
        $0.timeStyle = .short
    }

    private lazy var durationFormatter = using(DateComponentsFormatter()) {
        $0.unitsStyle = .brief
    }
nicklockwood commented 3 years ago

This is by design (although the design may be flawed). blankLinesBetweenScopes basically just inserts a new line after every closing }.

lhunath commented 3 years ago

I would argue that it is by implementation, not by design. :–)

The design is "Insert blank line before class, struct, enum, extension, protocol or function declarations."