Skip to content

Commit

Permalink
Upgrade SwiftLint
Browse files Browse the repository at this point in the history
To support Swift 6 syntax such as typed throws.

The changes are to address the violation of the
optional_data_string_conversion rule.
  • Loading branch information
lawrence-forooghian committed Sep 19, 2024
1 parent d01a78f commit 66ed42e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
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/[email protected]
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
}
}

0 comments on commit 66ed42e

Please sign in to comment.