Problem
swift-format (with OrderedImports enabled) turns the following code
import A
// Comment
import B
into this
Removing the comment in between.
Expected Behavior
I expect it to output the following code preserving the comment.
import A
import B
// Comment
Potential Solution
After looking into this issue, it happens in convertToCodeBlockItems(lines:) where the comment is added pendingLeadingTrivia but never added to the final output.
One way to fix this is to append the remaining pendingLeadingTrivia to the last item's trailingTrivia (probably trimming lines surrounding comments as well).