File tree 4 files changed +54
-6
lines changed
4 files changed +54
-6
lines changed Original file line number Diff line number Diff line change @@ -67,9 +67,9 @@ struct Comment {
67
67
68
68
switch kind {
69
69
case .line, .docLine:
70
+ self.length = text.count
70
71
self.text = [text]
71
72
self.text[0].removeFirst(kind.prefixLength)
72
- self.length = self.text.reduce(0, { $0 + $1.count + kind.prefixLength + 1 })
73
73
74
74
case .block, .docBlock:
75
75
var fulltext: String = text
Original file line number Diff line number Diff line change 12
12
13
13
import Foundation
14
14
15
+ #if os(Windows)
16
+ import WinSDK
17
+ #endif
18
+
15
19
extension URL {
20
+ /// Returns a `Bool` to indicate if the given `URL` leads to the root of a filesystem.
21
+ /// A non-filesystem type `URL` will always return false.
16
22
@_spi ( Testing) public var isRoot : Bool {
23
+ guard isFileURL else { return false }
24
+
25
+ #if compiler(>=6.1)
26
+ #if os(Windows)
27
+ let filePath = self . withUnsafeFileSystemRepresentation { pointer in
28
+ guard let pointer else {
29
+ return " "
30
+ }
31
+ return String ( cString: pointer)
32
+ }
33
+ return filePath. withCString ( encodedAs: UTF16 . self, PathCchIsRoot)
34
+ #else // os(Windows)
35
+ return self . path == " / "
36
+ #endif // os(Windows)
37
+ #else // compiler(>=6.1)
38
+
17
39
#if os(Windows)
18
- // FIXME: We should call into Windows' native check to check if this path is a root once https://github.com/swiftlang/swift-foundation/issues/976 is fixed .
40
+ // This is needed as the fixes from #844 aren't in the Swift 6.0 toolchain .
19
41
// https://github.com/swiftlang/swift-format/issues/844
20
42
var pathComponents = self . pathComponents
21
43
if pathComponents. first == " / " {
22
44
// Canonicalize `/C:/` to `C:/`.
23
45
pathComponents = Array ( pathComponents. dropFirst ( ) )
24
46
}
25
47
return pathComponents. count <= 1
26
- #else
48
+ #else // os(Windows)
27
49
// On Linux, we may end up with an string for the path due to https://github.com/swiftlang/swift-foundation/issues/980
28
- // TODO: Remove the check for "" once https://github.com/swiftlang/swift-foundation/issues/ 980 is fixed .
50
+ // This is needed as the fixes from # 980 aren't in the Swift 6.0 toolchain .
29
51
return self . path == " / " || self . path == " "
30
- #endif
52
+ #endif // os(Windows)
53
+ #endif // compiler(>=6.1)
31
54
}
32
55
}
Original file line number Diff line number Diff line change @@ -1009,6 +1009,29 @@ final class CommentTests: PrettyPrintTestCase {
1009
1009
)
1010
1010
}
1011
1011
1012
+ // Tests that "end of line" comments are flagged only when they exceed the configured line length.
1013
+ func testDiagnoseMoveEndOfLineCommentAroundBoundary( ) {
1014
+ assertPrettyPrintEqual (
1015
+ input: """
1016
+ x // 789
1017
+ x // 7890
1018
+ x 1️⃣// 78901
1019
+
1020
+ """ ,
1021
+ expected: """
1022
+ x // 789
1023
+ x // 7890
1024
+ x // 78901
1025
+
1026
+ """ ,
1027
+ linelength: 10 ,
1028
+ whitespaceOnly: true ,
1029
+ findings: [
1030
+ FindingSpec ( " 1️⃣ " , message: " move end-of-line comment that exceeds the line length " )
1031
+ ]
1032
+ )
1033
+ }
1034
+
1012
1035
func testLineWithDocLineComment( ) {
1013
1036
// none of these should be merged if/when there is comment formatting
1014
1037
let input =
Original file line number Diff line number Diff line change @@ -103,12 +103,14 @@ final class FileIteratorTests: XCTestCase {
103
103
while !root. isRoot {
104
104
root. deleteLastPathComponent ( )
105
105
}
106
- var rootPath = root. path
107
106
#if os(Windows) && compiler(<6.1)
107
+ var rootPath = root. path
108
108
if rootPath. hasPrefix ( " / " ) {
109
109
// Canonicalize /C: to C:
110
110
rootPath = String ( rootPath. dropFirst ( ) )
111
111
}
112
+ #else
113
+ let rootPath = root. path
112
114
#endif
113
115
// Make sure that we don't drop the beginning of the path if we are running in root.
114
116
// https://github.com/swiftlang/swift-format/issues/862
You can’t perform that action at this time.
0 commit comments