in Sources/swift-format/Utilities/FileIterator.swift [52:79]
mutating func next() -> URL? {
var output: URL? = nil
while output == nil {
// Check if we're recursing through a directory.
if dirIterator != nil {
output = nextInDirectory()
} else {
guard let next = urlIterator.next() else { return nil }
var isDir: ObjCBool = false
if FileManager.default.fileExists(atPath: next.path, isDirectory: &isDir), isDir.boolValue {
dirIterator = FileManager.default.enumerator(at: next, includingPropertiesForKeys: nil)
currentDirectory = next
} else {
// We'll get here if the path is a file, or if it doesn't exist. In the latter case,
// return the path anyway; we'll turn the error we get when we try to open the file into
// an appropriate diagnostic instead of trying to handle it here.
output = next
}
}
if let out = output, visited.contains(out.absoluteURL.standardized.path) {
output = nil
}
}
if let out = output {
visited.insert(out.absoluteURL.standardized.path)
}
return output
}