Skip to content

Commit

Permalink
fix format locally
Browse files Browse the repository at this point in the history
  • Loading branch information
swiftanon committed Aug 28, 2024
1 parent 7a0b9b5 commit 4be098b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 50 deletions.
14 changes: 7 additions & 7 deletions Sources/ModelFileFinder/FileManagerProtocol.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down
82 changes: 41 additions & 41 deletions Sources/ModelFileFinder/ModelFileFinder.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
2 changes: 1 addition & 1 deletion Tests/ModelFileFinderests/MockFileManager.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// MockFileManager.swift
// Created by swiftanon on 7/22/24..
// Created by swiftanon on 8/27/24.

import Foundation
import ModelFileFinder
Expand Down
2 changes: 1 addition & 1 deletion Tests/ModelFileFinderests/ModelFileFinderTests.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 4be098b

Please sign in to comment.