Skip to content

Use built-in URL modifying methods instead of string concat when crea… #196

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

Merged
merged 1 commit into from
Jun 4, 2020
Merged
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
17 changes: 9 additions & 8 deletions Sources/swift-format/Utilities/FileIterator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct FileIterator: Sequence, IteratorProtocol {
var dirIterator: FileManager.DirectoryEnumerator? = nil

/// Keep track of the current directory we're recursing through.
var currentDirectory: String = ""
var currentDirectory = URL(fileURLWithPath: "")

/// Keep track of paths we have visited to prevent duplicates.
var visited: Set<String> = []
Expand Down Expand Up @@ -54,7 +54,7 @@ struct FileIterator: Sequence, IteratorProtocol {
if FileManager.default.fileExists(atPath: next, isDirectory: &isDir) {
if isDir.boolValue {
dirIterator = FileManager.default.enumerator(atPath: next)
currentDirectory = next
currentDirectory = URL(fileURLWithPath: next, isDirectory: true)
} else { output = next }
} else {
// If a path doesn't exist, allow it pass down into the SwiftFormat API so it can throw
Expand All @@ -74,12 +74,13 @@ struct FileIterator: Sequence, IteratorProtocol {
while output == nil {
var isDir: ObjCBool = false
if let item = dirIterator?.nextObject() as? String {
if item.hasSuffix(fileSuffix)
&& FileManager.default.fileExists(
atPath: currentDirectory + "/" + item, isDirectory: &isDir)
&& !isDir.boolValue
{
output = currentDirectory + "/" + item
if item.hasSuffix(fileSuffix) {
let absoluteItemPath = currentDirectory.appendingPathComponent(item).path
if FileManager.default.fileExists(atPath: absoluteItemPath, isDirectory: &isDir)
&& !isDir.boolValue
{
output = absoluteItemPath
}
}
} else { break }
}
Expand Down