Fix various swiftlint and swiftformat warnings

This commit is contained in:
Stefan Ceriu
2024-06-11 16:38:33 +03:00
committed by Stefan Ceriu
parent 2079bf40c6
commit 9f6fc1d42f
6 changed files with 9 additions and 8 deletions
+1
View File
@@ -5,6 +5,7 @@
--disable wrapMultiLineStatementBraces --disable wrapMultiLineStatementBraces
--disable hoistPatternLet --disable hoistPatternLet
--disable preferForLoop --disable preferForLoop
--disable consistentSwitchCaseSpacing
--commas inline --commas inline
--ifdef no-indent --ifdef no-indent
@@ -22,7 +22,7 @@ extension Dictionary {
options: [.fragmentsAllowed, .sortedKeys]) else { options: [.fragmentsAllowed, .sortedKeys]) else {
return nil return nil
} }
return String(data: data, encoding: .utf8) return String(decoding: data, as: UTF8.self)
} }
/// Returns a dictionary containing the original values keyed by the results of mapping the given closure over its keys. /// Returns a dictionary containing the original values keyed by the results of mapping the given closure over its keys.
@@ -474,6 +474,7 @@ class RoomScreenInteractionHandler {
// MARK: Audio Playback // MARK: Audio Playback
// swiftlint:disable:next cyclomatic_complexity
func playPauseAudio(for itemID: TimelineItemIdentifier) async { func playPauseAudio(for itemID: TimelineItemIdentifier) async {
MXLog.info("Toggle play/pause audio for itemID \(itemID)") MXLog.info("Toggle play/pause audio for itemID \(itemID)")
guard let timelineItem = timelineController.timelineItems.firstUsingStableID(itemID) else { guard let timelineItem = timelineController.timelineItems.firstUsingStableID(itemID) else {
@@ -175,14 +175,14 @@ class BugReportService: NSObject, BugReportServiceProtocol {
let (data, response) = try await session.dataWithRetry(for: request, delegate: self) let (data, response) = try await session.dataWithRetry(for: request, delegate: self)
guard let httpResponse = response as? HTTPURLResponse else { guard let httpResponse = response as? HTTPURLResponse else {
let errorDescription = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "Unknown" let errorDescription = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
MXLog.error("Failed to submit bug report: \(errorDescription)") MXLog.error("Failed to submit bug report: \(errorDescription)")
MXLog.error("Response: \(response)") MXLog.error("Response: \(response)")
return .failure(.serverError(response, errorDescription)) return .failure(.serverError(response, errorDescription))
} }
guard httpResponse.statusCode == 200 else { guard httpResponse.statusCode == 200 else {
let errorDescription = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "Unknown" let errorDescription = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
MXLog.error("Failed to submit bug report: \(errorDescription) (\(httpResponse.statusCode))") MXLog.error("Failed to submit bug report: \(errorDescription) (\(httpResponse.statusCode))")
MXLog.error("Response: \(httpResponse)") MXLog.error("Response: \(httpResponse)")
return .failure(.httpError(httpResponse, errorDescription)) return .failure(.httpError(httpResponse, errorDescription))
@@ -159,7 +159,7 @@ struct TimelineItemDebugInfo: Identifiable, CustomStringConvertible {
return nil return nil
} }
return String(data: jsonData, encoding: .utf8) return String(decoding: jsonData, as: UTF8.self)
} }
} }
@@ -146,11 +146,10 @@ enum UITestsSignalling {
let encoder = JSONEncoder() let encoder = JSONEncoder()
encoder.outputFormatting = .sortedKeys encoder.outputFormatting = .sortedKeys
guard let data = try? encoder.encode(self), guard let data = try? encoder.encode(self) else {
let string = String(data: data, encoding: .utf8) else {
return "unknown" return "unknown"
} }
return string return String(decoding: data, as: UTF8.self)
} }
init?(rawValue: String) { init?(rawValue: String) {
@@ -175,7 +174,7 @@ enum UITestsSignalling {
/// Processes string data from the file and publishes its signal. /// Processes string data from the file and publishes its signal.
private func processFileData(_ data: Data) { private func processFileData(_ data: Data) {
guard let rawMessage = String(data: data, encoding: .utf8) else { return } let rawMessage = String(decoding: data, as: UTF8.self)
guard let message = Message(rawValue: rawMessage), guard let message = Message(rawValue: rawMessage),
message.mode != mode // Filter out messages sent by this client. message.mode != mode // Filter out messages sent by this client.