Swiftformat: Bug in sortedImports rule

Created on 25 Sep 2020  路  3Comments  路  Source: nicklockwood/SwiftFormat

I observed this behaviour in both 0.45.4 and 0.46.3.

Command:

$ SwiftFormat/CommandLineTool/swiftformat test.swift --rules sortedImports

Test file:

//
//  Code.swift
//  Module
//
//  Created by Someone on 4/30/20.
//
import AModuleUI
import AModule
import AModuleHelper
import SomeOtherModule

Expect output:

//
//  Code.swift
//  Module
//
//  Created by Someone on 4/30/20.
//
import AModule
import AModuleHelper
import AModuleUI
import SomeOtherModule

Actual output:

//
import AModule
import AModuleHelper
//  Code.swift
//  Module
//
//  Created by Someone on 4/30/20.
//
import AModuleUI
import SomeOtherModule
bug fixed in develop

All 3 comments

Ooh, that's a nasty one. Thanks for reporting.

FWIW, adding a blank line below the comment should fix it. SwiftFormat basically can't distinguish a comment header from a regular comment unless there's a blank line after.

Thanks Nick! That's exactly what we ended up doing to fix it.

@meherkasam fixed in 0.47.4

Was this page helpful?
0 / 5 - 0 ratings