Skip to content
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

Upgrade SwiftLint #60

Merged
merged 1 commit into from
Sep 19, 2024
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
2 changes: 1 addition & 1 deletion Mintfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
realm/SwiftLint@0.55.1
realm/SwiftLint@0.57.0
nicklockwood/SwiftFormat@0.54.3
4 changes: 2 additions & 2 deletions Sources/BuildTool/BuildTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct GenerateMatrices: ParsableCommand {
]

// I’m assuming the JSONSerialization output has no newlines
let keyValue = try "matrix=\(String(decoding: JSONSerialization.data(withJSONObject: matrix), as: UTF8.self))"
let keyValue = try "matrix=\(String(data: JSONSerialization.data(withJSONObject: matrix), encoding: .utf8))"
fputs("\(keyValue)\n", stderr)
print(keyValue)
}
Expand Down Expand Up @@ -173,6 +173,6 @@ struct Lint: AsyncParsableCommand {

private func loadUTF8StringFromFile(at path: String) async throws -> String {
let (data, _) = try await URLSession.shared.data(from: .init(filePath: path))
return String(decoding: data, as: UTF8.self)
return try String(data: data, encoding: .utf8)
}
}
16 changes: 16 additions & 0 deletions Sources/BuildTool/String+Decoding.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Foundation

extension String {
enum DecodingError: Swift.Error {
case decodingFailed
}

/// Like `init(data:encoding:)`, but indicates decoding failure by throwing an error instead of returning an optional.
init(data: Data, encoding: String.Encoding) throws {
guard let decoded = String(data: data, encoding: encoding) else {
throw DecodingError.decodingFailed
}

self = decoded
}
}