Skip to content

Commit

Permalink
Move the Path helper into a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyarnold committed Nov 24, 2022
1 parent a3ed7ec commit ff0708f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
18 changes: 18 additions & 0 deletions Plugins/SwiftLintPlugin/Path+Helpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation
import PackagePlugin

extension Path {
/// Scans the receiver, then all of it's parents looking for a configuration file with the name ".swiftlint.yml".
/// - Returns: Path to the configuration file, or nil if one cannot be found.
func firstConfigurationFileInParentDirectories() -> Path? {
// TODO: Consider linking to the framework to get the default configuration file name
let defaultConfigurationFileName = ".swiftlint.yml"
let proposedDirectory = sequence(first: self, next: { $0.removingLastComponent() })
.first { path in
let potentialConfigurationFile = path.appending(subpath: defaultConfigurationFileName)
return FileManager.default.isReadableFile(atPath: potentialConfigurationFile.string)
}

return proposedDirectory?.appending(subpath: defaultConfigurationFileName)
}
}
16 changes: 0 additions & 16 deletions Plugins/SwiftLintPlugin/SwiftLintPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,3 @@ extension SwiftLintPlugin: XcodeBuildToolPlugin {
}
}
#endif

private extension Path {
/// Scans the receiver, then all of it's parents looking for a configuration file with the name ".swiftlint.yml".
/// - Returns: Path to the configuration file, or nil if one cannot be found.
func firstConfigurationFileInParentDirectories() -> Path? {
// TODO: Consider linking to the framework to get the default configuration file name
let defaultConfigurationFileName = ".swiftlint.yml"
let proposedDirectory = sequence(first: self, next: { $0.removingLastComponent() })
.first { path in
let potentialConfigurationFile = path.appending(subpath: defaultConfigurationFileName)
return FileManager.default.isReadableFile(atPath: potentialConfigurationFile.string)
}

return proposedDirectory?.appending(subpath: defaultConfigurationFileName)
}
}

0 comments on commit ff0708f

Please sign in to comment.