From 398a88ddb83c361ab064ba29316bd4df60dc7291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fancan=20Mavideniz?= Date: Thu, 28 Dec 2023 15:15:16 +0300 Subject: [PATCH] Fixed for @testable import sorts. --- Core/RunnableItems/SortGenerate.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Core/RunnableItems/SortGenerate.swift b/Core/RunnableItems/SortGenerate.swift index 1847cd1..37276f5 100644 --- a/Core/RunnableItems/SortGenerate.swift +++ b/Core/RunnableItems/SortGenerate.swift @@ -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 }) } }