Skip to content

Commit a00d23c

Browse files
committed
gardening
1 parent 34f3a58 commit a00d23c

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

Sources/KeyValueDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
// SOFTWARE.
3030
//
3131

32-
import Foundation
3332
import CoreFoundation
33+
import Foundation
3434

3535
/// Top level encoder that converts `[String: Any]`, `[Any]` or `Any` into `Codable` types.
3636
public final class KeyValueDecoder {

Sources/KeyValueEncoder.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ extension KeyValueEncoder {
100100
}
101101
}
102102

103-
func encodeValue<T: Encodable>(_ value: T) throws -> EncodedValue{
103+
func encodeValue<T: Encodable>(_ value: T) throws -> EncodedValue {
104104
try Encoder(userInfo: userInfo, nilEncodingStrategy: nilEncodingStrategy).encodeToValue(value)
105105
}
106106
}
@@ -422,7 +422,11 @@ private extension KeyValueEncoder {
422422
return
423423
}
424424

425-
let encoder = Encoder(codingPath: codingPath.appending(index: count), userInfo: userInfo, nilEncodingStrategy: nilEncodingStrategy)
425+
let encoder = Encoder(
426+
codingPath: codingPath.appending(index: count),
427+
userInfo: userInfo,
428+
nilEncodingStrategy: nilEncodingStrategy
429+
)
426430
if let value = try encoder.encodeToValue(value).getValue(strategy: nilEncodingStrategy) {
427431
appendValue(value)
428432
} else {

Tests/KeyValueDecoderTests.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct KeyValueDecoderTests {
7878
"name": "root",
7979
"desc": [["id": 2], ["id": 3]],
8080
"rel": ["left": ["id": 4, "desc": [["id": 5]] as Any],
81-
"right": ["id": 6]],
81+
"right": ["id": 6]]
8282
]
8383

8484
#expect(
@@ -828,7 +828,8 @@ struct KeyValueDecoderTests {
828828
#expect(NSNumber(value: UInt8.max).getInt64Value() == Int64(UInt8.max))
829829
#expect(NSNumber(value: UInt16.max).getInt64Value() == Int64(UInt16.max))
830830
#expect(NSNumber(value: UInt32.max).getInt64Value() == Int64(UInt32.max))
831-
#expect(NSNumber(value: UInt64.max).getInt64Value() == -1) // NSNumber stores unsigned values with sign in the next largest size but 64bit is largest size.
831+
// NSNumber stores unsigned values with sign in the next largest size but 64bit is largest size.
832+
#expect(NSNumber(value: UInt64.max).getInt64Value() == -1)
832833
#expect(NSNumber(10.5).getInt64Value() == nil)
833834
#expect(NSNumber(true).getInt64Value() == nil)
834835
}
@@ -993,7 +994,11 @@ private extension KeyValueDecoder {
993994

994995
}
995996

996-
static func decodeValue<K: CodingKey, T>(from value: [String: Any], keyedBy: K.Type = K.self, with closure: @escaping (inout KeyedDecodingContainer<K>) throws -> T) throws -> T {
997+
static func decodeValue<K: CodingKey, T>(
998+
from value: [String: Any],
999+
keyedBy: K.Type = K.self,
1000+
with closure: @escaping (inout KeyedDecodingContainer<K>
1001+
) throws -> T) throws -> T {
9971002
let proxy = StubDecoder.Proxy { decoder in
9981003
var container = try decoder.container(keyedBy: K.self)
9991004
return try closure(&container)
@@ -1005,7 +1010,10 @@ private extension KeyValueDecoder {
10051010
return proxy.result!
10061011
}
10071012

1008-
static func decodeUnkeyedValue<T>(from value: [Any], with closure: @escaping (inout any UnkeyedDecodingContainer) throws -> T) throws -> T {
1013+
static func decodeUnkeyedValue<T>(
1014+
from value: [Any],
1015+
with closure: @escaping (inout any UnkeyedDecodingContainer) throws -> T
1016+
) throws -> T {
10091017
let proxy = StubDecoder.Proxy { decoder in
10101018
var container = try decoder.unkeyedContainer()
10111019
return try closure(&container)

Tests/KeyValueEncoderTests.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ struct KeyValueEncodedTests {
214214
"name": "root",
215215
"desc": [["id": 2], ["id": 3]],
216216
"rel": ["left": ["id": 4, "desc": [["id": 5]] as Any],
217-
"right": ["id": 6]],
217+
"right": ["id": 6]]
218218
]
219219
)
220220
}
@@ -231,7 +231,7 @@ struct KeyValueEncodedTests {
231231
"first": Optional<Any>.none as Any,
232232
"second": "fish",
233233
"third": Optional<Any>.none as Any,
234-
"fourth": NSDictionary(),
234+
"fourth": NSDictionary()
235235
]
236236
)
237237
}
@@ -299,7 +299,7 @@ struct KeyValueEncodedTests {
299299
"tInt32": -40,
300300
"tInt64": Int64.max,
301301
"tArray": [["tInt": -1], ["tInt": -2]],
302-
"tDictionary": ["rel": ["tInt": -3]],
302+
"tDictionary": ["rel": ["tInt": -3]]
303303
]
304304
)
305305
}
@@ -324,7 +324,7 @@ struct KeyValueEncodedTests {
324324
"tUInt32": 40,
325325
"tUInt64": UInt64.max,
326326
"tArray": [["tUInt": 50], ["tUInt": 60]],
327-
"tDictionary": ["rel": ["tUInt": 70]],
327+
"tDictionary": ["rel": ["tUInt": 70]]
328328
]
329329
)
330330
}
@@ -622,7 +622,7 @@ struct KeyValueEncodedTests {
622622
try $0.encode(Null(), forKey: "chips")
623623
}.getValue() as? NSDictionary == [
624624
"fish": "$null",
625-
"chips": "$null",
625+
"chips": "$null"
626626
]
627627
)
628628
#expect(
@@ -631,7 +631,7 @@ struct KeyValueEncodedTests {
631631
try $0.encode(Null(), forKey: "chips")
632632
}.getValue() as? NSDictionary == [
633633
"fish": NSNull(),
634-
"chips": NSNull(),
634+
"chips": NSNull()
635635
]
636636
)
637637
}
@@ -688,7 +688,8 @@ private extension KeyValueEncoder {
688688

689689
static func encodeKeyedValue<K: CodingKey>(keyedBy: K.Type = K.self,
690690
nilEncodingStrategy: NilEncodingStrategy = .default,
691-
with closure: @escaping (inout KeyedEncodingContainer<K>) throws -> Void) throws -> EncodedValue {
691+
with closure: @escaping (inout KeyedEncodingContainer<K>) throws -> Void) throws
692+
-> EncodedValue {
692693
let encoder = KeyValueEncoder()
693694
encoder.nilEncodingStrategy = nilEncodingStrategy
694695
return try encoder.encodeValue {
@@ -741,7 +742,7 @@ struct Node: Codable, Equatable {
741742

742743
extension KeyValueEncoder.EncodedValue: Swift.Equatable {
743744

744-
public static func ==(lhs: Self, rhs: Self) -> Bool {
745+
public static func == (lhs: Self, rhs: Self) -> Bool {
745746
do {
746747
let lhsValue = try lhs.getValue()
747748
let rhsValue = try rhs.getValue()

0 commit comments

Comments
 (0)