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
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