nicklockwood / SwiftFormat

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

sortedImports borkage #698

Closed gurgeous closed 4 years ago

gurgeous commented 4 years ago

Hey Nick, thanks for SwiftFormat and your many contributions to #ioslife... We couldn't build apps without you!

There's a wee bug in sortedImports, triggered by one of our SwifterSwift files. I narrowed it down with a small test case. Something to do with the header comment, the nested canImports, and `sortedImports. If I remove the comment the bug no longer occurs.

before

// evil comment

#if canImport(Foundation)
    import Foundation
    #if canImport(UIKit) && canImport(AVFoundation)
        import UIKit
        import AVFoundation
    #endif
#endif

$ swiftformat . --swiftversion 5

after

import AVFoundation
// evil comment

#if canImport(Foundation)
    import Foundation
    #if canImport(UIKit) && canImport(AVFoundation)
        import UIKit
    #endif
#endif
nicklockwood commented 4 years ago

@gurgeous thanks for reporting, I'll try to fix it asap

nicklockwood commented 4 years ago

@gurgeous fixed in 0.45.5.