diff --git a/Sources/ModelFileFinder/FileManagerProtocol.swift b/Sources/ModelFileFinder/FileManagerProtocol.swift index d3cc210..d1bb065 100644 --- a/Sources/ModelFileFinder/FileManagerProtocol.swift +++ b/Sources/ModelFileFinder/FileManagerProtocol.swift @@ -1,15 +1,15 @@ // FileManagerProtocol.swift -// Created by swiftanon on 7/22/24 +// Created by swiftanon on 8/27/24. import Foundation public protocol FileManagerProtocol { - /// abstract functionality of fileManager.contentsOfDirectory - func contentsOfDirectory( - at url: URL, - includingPropertiesForKeys keys: [URLResourceKey]?, - options mask: FileManager.DirectoryEnumerationOptions - ) throws -> [URL] + /// abstract functionality of fileManager.contentsOfDirectory + func contentsOfDirectory( + at url: URL, + includingPropertiesForKeys keys: [URLResourceKey]?, + options mask: FileManager.DirectoryEnumerationOptions + ) throws -> [URL] } /// Extend FileManager to conform to Protocol diff --git a/Sources/ModelFileFinder/ModelFileFinder.swift b/Sources/ModelFileFinder/ModelFileFinder.swift index 74e8573..0111062 100644 --- a/Sources/ModelFileFinder/ModelFileFinder.swift +++ b/Sources/ModelFileFinder/ModelFileFinder.swift @@ -1,61 +1,61 @@ // ModelFileFinder.swift -// Created by swiftanon on 7/22/24 +// Created by swiftanon on 8/27/24. import Foundation import os public struct ModelFileFinder { - private let fileManager: FileManagerProtocol + private let fileManager: FileManagerProtocol - private let logger = Logger( - subsystem: "io.swiftpackage.ListMaker", - category: "LibraryPackage" - ) + private let logger = Logger( + subsystem: "io.swiftpackage.ListMaker", + category: "LibraryPackage" + ) - public init(fileManager: FileManagerProtocol = FileManager.default) { - self.fileManager = fileManager - } + public init(fileManager: FileManagerProtocol = FileManager.default) { + self.fileManager = fileManager + } - public func makeList() throws -> [String] { - var fileNames = [String]() + public func makeList() throws -> [String] { + var fileNames = [String]() - let currentFilePath = #file - let currentFileURL = URL(filePath: currentFilePath, directoryHint: .inferFromPath) - let sourceDirectoryURL = currentFileURL.deletingLastPathComponent() + let currentFilePath = #file + let currentFileURL = URL(filePath: currentFilePath, directoryHint: .inferFromPath) + let sourceDirectoryURL = currentFileURL.deletingLastPathComponent() - do { - let contents = try fileManager.contentsOfDirectory( - at: sourceDirectoryURL, - includingPropertiesForKeys: nil, - options: [] - ) + do { + let contents = try fileManager.contentsOfDirectory( + at: sourceDirectoryURL, + includingPropertiesForKeys: nil, + options: [] + ) - fileNames = contents.map(\.lastPathComponent) + fileNames = contents.map(\.lastPathComponent) - } catch { - logger.error("Error occurred: \(error.localizedDescription)") - throw error - } + } catch { + logger.error("Error occurred: \(error.localizedDescription)") + throw error + } - let currentFileName = URL( - filePath: currentFilePath, - directoryHint: .inferFromPath - ).lastPathComponent + let currentFileName = URL( + filePath: currentFilePath, + directoryHint: .inferFromPath + ).lastPathComponent - let intermediateResult = fileNames.filter { $0 != currentFileName } - let filesBySuffix = filteredBySuffix(intermediateResult) - return stripFileNamesOfSuffix(filesBySuffix) - } + let intermediateResult = fileNames.filter { $0 != currentFileName } + let filesBySuffix = filteredBySuffix(intermediateResult) + return stripFileNamesOfSuffix(filesBySuffix) + } - private func filteredBySuffix(_ fileNamesList: [String]) -> [String] { - fileNamesList.filter { str in - str.hasSuffix("Model.swift") + private func filteredBySuffix(_ fileNamesList: [String]) -> [String] { + fileNamesList.filter { str in + str.hasSuffix("Model.swift") + } } - } - private func stripFileNamesOfSuffix(_ fileNamesList: [String]) -> [String] { - fileNamesList.map { str in - str.replacingOccurrences(of: ".swift", with: "", options: .regularExpression) + private func stripFileNamesOfSuffix(_ fileNamesList: [String]) -> [String] { + fileNamesList.map { str in + str.replacingOccurrences(of: ".swift", with: "", options: .regularExpression) + } } - } } diff --git a/Tests/ModelFileFinderests/MockFileManager.swift b/Tests/ModelFileFinderests/MockFileManager.swift index e475f5c..03957c6 100644 --- a/Tests/ModelFileFinderests/MockFileManager.swift +++ b/Tests/ModelFileFinderests/MockFileManager.swift @@ -1,5 +1,5 @@ // MockFileManager.swift -// Created by swiftanon on 7/22/24.. +// Created by swiftanon on 8/27/24. import Foundation import ModelFileFinder diff --git a/Tests/ModelFileFinderests/ModelFileFinderTests.swift b/Tests/ModelFileFinderests/ModelFileFinderTests.swift index 529965b..c4c3408 100644 --- a/Tests/ModelFileFinderests/ModelFileFinderTests.swift +++ b/Tests/ModelFileFinderests/ModelFileFinderTests.swift @@ -1,5 +1,5 @@ // ModelFileFinderTests.swift -// Created by swiftanon on 7/22/24. +// Created by swiftanon on 8/27/24. @testable import ModelFileFinder import os