Skip to content

[SwiftSyntax] Remove force unwrapping for source location #513

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
Apr 20, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 2 additions & 13 deletions Sources/SwiftFormatCore/Finding+Convenience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,7 @@ import SwiftSyntax

extension Finding.Location {
/// Creates a new `Finding.Location` by converting the given `SourceLocation` from `SwiftSyntax`.
///
/// If the source location is invalid (i.e., any of its fields are nil), then the initializer will
/// return nil.
public init?(_ sourceLocation: SourceLocation) {
guard
let file = sourceLocation.file,
let line = sourceLocation.line,
let column = sourceLocation.column
else {
return nil
}

self.init(file: file, line: line, column: column)
public init(_ sourceLocation: SourceLocation) {
self.init(file: sourceLocation.file, line: sourceLocation.line, column: sourceLocation.column)
}
}
6 changes: 3 additions & 3 deletions Sources/swift-format/Utilities/Diagnostic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ struct Diagnostic {

/// Creates a new diagnostic location from the given source location.
init(_ sourceLocation: SourceLocation) {
self.file = sourceLocation.file!
self.line = sourceLocation.line!
self.column = sourceLocation.column!
self.file = sourceLocation.file
self.line = sourceLocation.line
self.column = sourceLocation.column
}

/// Creates a new diagnostic location with the given finding location.
Expand Down