Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed for @testable import sorts. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Core/RunnableItems/SortGenerate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ final class SortGenerate: Runnable {
// Implement your command here, invoking the completion handler when done. Pass it nil on success, and an NSError on failure.
guard let lines = lines else { return }
let bridgedLines = lines.compactMap { $0 as? String }

let importFrameworks = bridgedLines.enumerated().compactMap({
$0.element.isImportLine ? $0.element.removeImportPrefix.removeNewLine : nil
}).sorted()


let sortedImports = importFrameworks.map { "import \($0)" }.sorted()

let importIndex = bridgedLines.enumerated().compactMap({
$0.element.isImportLine ? $0.offset : nil
}).sorted()

guard importIndex.count == importFrameworks.count && lines.count > importIndex.count else {
guard importIndex.count == sortedImports.count && lines.count > importIndex.count else {
return
}
importFrameworks.enumerated().forEach({ lines[importIndex[$0]] = "import \($1)" })
sortedImports.enumerated().forEach({ lines[importIndex[$0]] = $1 })
}
}

Expand Down