nicklockwood / SwiftFormat

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

`--ifdef no-indent` rule adds extra indent. #1448

Closed dollar2048 closed 1 year ago

dollar2048 commented 1 year ago

I have this piece of Swift code:

struct FontKit {
    var style: UIFont.TextStyle
    var size: CGFloat?
}

var title: FontKit {
    #if os(iOS)
    .init(style: .title2)
    #else
    .init(style: .title2, size: 40)
    #endif
}

When running SwiftFormat 0.51.9 with --ifdef no-indent I get:

struct FontKit {
    var style: UIFont.TextStyle
    var size: CGFloat?
}

var title: FontKit {
    #if os(iOS)
    .init(style: .title2)
    #else
        .init(style: .title2, size: 40)
    #endif
}

But I would expect no changes to be made.

Some interesting info: The following UnitTests (SwiftUI) are working fine: https://github.com/nicklockwood/SwiftFormat/blob/master/Tests/RulesTests%2BIndentation.swift#L2135

So in case of some code presence before #if it works as expected. Otherwise, not.

nicklockwood commented 1 year ago

@dollar2048 fixed in 0.51.10

dollar2048 commented 1 year ago

Thank you @nicklockwood. it works now perfectly!