Skip to content

Commit 9df5622

Browse files
authored
Merge pull request swiftlang#848 from ahoppen/infinite-searching-linux
Fix infinite searching for `.swift-format` file on Linux
2 parents 1699d87 + ba8f585 commit 9df5622

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Sources/SwiftFormat/API/Configuration.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,9 @@ fileprivate extension URL {
480480
// https://github.com/swiftlang/swift-format/issues/844
481481
return self.pathComponents.count == 1
482482
#else
483-
return self.path == "/"
483+
// On Linux, we may end up with an string for the path due to https://github.com/swiftlang/swift-foundation/issues/980
484+
// TODO: Remove the check for "" once https://github.com/swiftlang/swift-foundation/issues/980 is fixed.
485+
return self.path == "/" || self.path == ""
484486
#endif
485487
}
486488
}

Tests/SwiftFormatTests/API/ConfigurationTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,21 @@ final class ConfigurationTests: XCTestCase {
2626
#endif
2727
XCTAssertNil(Configuration.url(forConfigurationFileApplyingTo: URL(fileURLWithPath: path)))
2828
}
29+
30+
func testMissingConfigurationFileInSubdirectory() {
31+
#if os(Windows)
32+
let path = #"C:\whatever\test.swift"#
33+
#else
34+
let path = "/whatever/test.swift"
35+
#endif
36+
XCTAssertNil(Configuration.url(forConfigurationFileApplyingTo: URL(fileURLWithPath: path)))
37+
}
38+
39+
func testMissingConfigurationFileMountedDirectory() throws {
40+
#if !os(Windows)
41+
try XCTSkipIf(true, #"\\ file mounts are only a concept on Windows"#)
42+
#endif
43+
let path = #"\\mount\test.swift"#
44+
XCTAssertNil(Configuration.url(forConfigurationFileApplyingTo: URL(fileURLWithPath: path)))
45+
}
2946
}

0 commit comments

Comments
 (0)