Skip to content

Commit a0c13d4

Browse files
committed
Remove force unwrapping for source location
Companion of swiftlang/swift-syntax#1532
1 parent 414b216 commit a0c13d4

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

Sources/SwiftFormatCore/Finding+Convenience.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,7 @@ import SwiftSyntax
1414

1515
extension Finding.Location {
1616
/// Creates a new `Finding.Location` by converting the given `SourceLocation` from `SwiftSyntax`.
17-
///
18-
/// If the source location is invalid (i.e., any of its fields are nil), then the initializer will
19-
/// return nil.
20-
public init?(_ sourceLocation: SourceLocation) {
21-
guard
22-
let file = sourceLocation.file,
23-
let line = sourceLocation.line,
24-
let column = sourceLocation.column
25-
else {
26-
return nil
27-
}
28-
29-
self.init(file: file, line: line, column: column)
17+
public init(_ sourceLocation: SourceLocation) {
18+
self.init(file: sourceLocation.file, line: sourceLocation.line, column: sourceLocation.column)
3019
}
3120
}

Sources/swift-format/Utilities/Diagnostic.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ struct Diagnostic {
3636

3737
/// Creates a new diagnostic location from the given source location.
3838
init(_ sourceLocation: SourceLocation) {
39-
self.file = sourceLocation.file!
40-
self.line = sourceLocation.line!
41-
self.column = sourceLocation.column!
39+
self.file = sourceLocation.file
40+
self.line = sourceLocation.line
41+
self.column = sourceLocation.column
4242
}
4343

4444
/// Creates a new diagnostic location with the given finding location.

0 commit comments

Comments
 (0)