Skip to content

Commit

Permalink
Fix SwiftLint violations
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenviewer committed Oct 28, 2024
1 parent 20f2583 commit 16eef01
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Sources/API/Converter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ enum Converter {
let result = Double(bitPattern: UInt64(littleEndian: data.withUnsafeBytes { $0.load(as: UInt64.self) }))
return .double(result)
case .string:
return .string(String(decoding: data, as: UTF8.self))
guard let stringValue = String(data: data, encoding: .utf8) else {
throw YorkieError.unimplemented(message: String(describing: valueType))
}
return .string(stringValue)
case .long:
let result = Int64(littleEndian: data.withUnsafeBytes { $0.load(as: Int64.self) })
return .long(result)
Expand Down
6 changes: 4 additions & 2 deletions Sources/Document/CRDT/CRDTTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,10 @@ final class CRDTTreeNode: IndexTreeNode {
}

var toJSONString: String {
if let data = try? JSONSerialization.data(withJSONObject: toDictionary, options: [.sortedKeys]) {
return String(decoding: data, as: UTF8.self)
if let data = try? JSONSerialization.data(withJSONObject: toDictionary, options: [.sortedKeys]),
let jsonString = String(data: data, encoding: .utf8)
{
return jsonString
}

return "{}"
Expand Down
2 changes: 1 addition & 1 deletion Sources/Util/Codable+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension Encodable {
return nil
}

return String(decoding: data, as: UTF8.self)
return String(data: data, encoding: .utf8)
}
}

Expand Down
6 changes: 4 additions & 2 deletions Sources/Util/Dictionary+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ extension StringValueTypeDictionary {
}

return jsonObject.mapValues {
if let result = try? JSONSerialization.data(withJSONObject: $0, options: [.fragmentsAllowed, .withoutEscapingSlashes, .sortedKeys]) {
return String(decoding: result, as: UTF8.self)
if let result = try? JSONSerialization.data(withJSONObject: $0, options: [.fragmentsAllowed, .withoutEscapingSlashes, .sortedKeys]),
let stringValue = String(data: result, encoding: .utf8)
{
return stringValue
} else {
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Document/CRDT/PrimitiveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class PrimitiveTests: XCTestCase {
let valueFromData = try Converter.valueFrom(.bytes, data: primitiveValue.toBytes())
switch valueFromData {
case .bytes(let value):
XCTAssertEqual(String(decoding: value, as: UTF8.self), "abcdefg")
XCTAssertEqual(String(data: value, encoding: .utf8), "abcdefg")
default:
XCTFail("Type error.")
}
Expand Down

0 comments on commit 16eef01

Please sign in to comment.