Skip to content

Commit 23dbcef

Browse files
committed
style: apply swiftformat across the codebase
Run swiftformat with the new project configuration. Notable mechanical changes include import sorting, attribute placement, multiline string indentation, trailing commas in multi-element lists, and Swift Testing test names converted to raw identifiers by swiftTestingTestCaseNames. Two manual accompaniments keep the build green: - CodingUserInfoKey.resilientDecodingErrorReporter is written as `: CodingUserInfoKey = .init(...)!` because the propertyTypes rule miscompiles the multiline `= CodingUserInfoKey(...)!` form into a tuple. - The @DefaultCodable test doubles are wrapped in `swiftformat:disable propertyTypes` regions, since an explicit type annotation breaks the wrapper's generic parameter inference. swift test passes in both debug (303) and release (295) configurations. Claude-Session: https://claude.ai/code/session_017kn3Hf2khxiFy1TqimTGx9
1 parent b337468 commit 23dbcef

151 files changed

Lines changed: 2177 additions & 2048 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Package.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,36 @@ let package = Package(
1010
products: [
1111
.library(
1212
name: "KarrotCodableKit",
13-
targets: ["KarrotCodableKit"]
14-
),
13+
targets: ["KarrotCodableKit"],
14+
)
1515
],
1616
dependencies: [
17-
.package(url: "https://github.com/swiftlang/swift-syntax.git", "509.0.0"..<"604.0.0"),
17+
.package(url: "https://github.com/swiftlang/swift-syntax.git", "509.0.0"..<"604.0.0")
1818
],
1919
targets: [
2020
.target(
2121
name: "KarrotCodableKit",
22-
dependencies: ["KarrotCodableKitMacros"]
22+
dependencies: ["KarrotCodableKitMacros"],
2323
),
2424
.macro(
2525
name: "KarrotCodableKitMacros",
2626
dependencies: [
2727
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
2828
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
29-
]
29+
],
3030
),
3131
.testTarget(
3232
name: "KarrotCodableKitTests",
3333
dependencies: [
34-
"KarrotCodableKit",
35-
]
34+
"KarrotCodableKit"
35+
],
3636
),
3737
.testTarget(
3838
name: "KarrotCodableMacrosTests",
3939
dependencies: [
4040
"KarrotCodableKitMacros",
4141
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
42-
]
42+
],
4343
),
44-
]
44+
],
4545
)

Sources/KarrotCodableKit/AnyCodable/AnyCodable.swift

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@
77

88
import Foundation
99

10-
/**
11-
A type-erased `Codable` value.
12-
13-
The `AnyCodable` type forwards encoding and decoding responsibilities
14-
to an underlying value, hiding its specific underlying type.
15-
16-
You can encode or decode mixed-type values in dictionaries
17-
and other collections that require `Encodable` or `Decodable` conformance
18-
by declaring their contained type to be `AnyCodable`.
19-
20-
- SeeAlso: `AnyEncodable`
21-
- SeeAlso: `AnyDecodable`
22-
*/
10+
/// A type-erased `Codable` value.
11+
///
12+
/// The `AnyCodable` type forwards encoding and decoding responsibilities
13+
/// to an underlying value, hiding its specific underlying type.
14+
///
15+
/// You can encode or decode mixed-type values in dictionaries
16+
/// and other collections that require `Encodable` or `Decodable` conformance
17+
/// by declaring their contained type to be `AnyCodable`.
18+
///
19+
/// - SeeAlso: `AnyEncodable`
20+
/// - SeeAlso: `AnyDecodable`
2321
@frozen
2422
public struct AnyCodable: Codable {
2523
public let value: Any
@@ -35,47 +33,47 @@ extension AnyCodable: Equatable {
3533
public static func == (lhs: AnyCodable, rhs: AnyCodable) -> Bool {
3634
switch (lhs.value, rhs.value) {
3735
case is (Void, Void):
38-
return true
36+
true
3937
case (let lhs as Bool, let rhs as Bool):
40-
return lhs == rhs
38+
lhs == rhs
4139
case (let lhs as Int, let rhs as Int):
42-
return lhs == rhs
40+
lhs == rhs
4341
case (let lhs as Int8, let rhs as Int8):
44-
return lhs == rhs
42+
lhs == rhs
4543
case (let lhs as Int16, let rhs as Int16):
46-
return lhs == rhs
44+
lhs == rhs
4745
case (let lhs as Int32, let rhs as Int32):
48-
return lhs == rhs
46+
lhs == rhs
4947
case (let lhs as Int64, let rhs as Int64):
50-
return lhs == rhs
48+
lhs == rhs
5149
case (let lhs as UInt, let rhs as UInt):
52-
return lhs == rhs
50+
lhs == rhs
5351
case (let lhs as UInt8, let rhs as UInt8):
54-
return lhs == rhs
52+
lhs == rhs
5553
case (let lhs as UInt16, let rhs as UInt16):
56-
return lhs == rhs
54+
lhs == rhs
5755
case (let lhs as UInt32, let rhs as UInt32):
58-
return lhs == rhs
56+
lhs == rhs
5957
case (let lhs as UInt64, let rhs as UInt64):
60-
return lhs == rhs
58+
lhs == rhs
6159
case (let lhs as Float, let rhs as Float):
62-
return lhs == rhs
60+
lhs == rhs
6361
case (let lhs as Double, let rhs as Double):
64-
return lhs == rhs
62+
lhs == rhs
6563
case (let lhs as String, let rhs as String):
66-
return lhs == rhs
64+
lhs == rhs
6765
case (let lhs as [String: AnyCodable], let rhs as [String: AnyCodable]):
68-
return lhs == rhs
66+
lhs == rhs
6967
case (let lhs as [AnyCodable], let rhs as [AnyCodable]):
70-
return lhs == rhs
68+
lhs == rhs
7169
case (let lhs as [String: Any], let rhs as [String: Any]):
72-
return NSDictionary(dictionary: lhs) == NSDictionary(dictionary: rhs)
70+
NSDictionary(dictionary: lhs) == NSDictionary(dictionary: rhs)
7371
case (let lhs as [Any], let rhs as [Any]):
74-
return NSArray(array: lhs) == NSArray(array: rhs)
72+
NSArray(array: lhs) == NSArray(array: rhs)
7573
case is (NSNull, NSNull):
76-
return true
74+
true
7775
default:
78-
return false
76+
false
7977
}
8078
}
8179
}
@@ -84,11 +82,11 @@ extension AnyCodable: CustomStringConvertible {
8482
public var description: String {
8583
switch value {
8684
case is Void:
87-
return String(describing: nil as Any?)
85+
String(describing: nil as Any?)
8886
case let value as CustomStringConvertible:
89-
return value.description
87+
value.description
9088
default:
91-
return String(describing: value)
89+
String(describing: value)
9290
}
9391
}
9492
}
@@ -97,9 +95,9 @@ extension AnyCodable: CustomDebugStringConvertible {
9795
public var debugDescription: String {
9896
switch value {
9997
case let value as CustomDebugStringConvertible:
100-
return "AnyCodable(\(value.debugDescription))"
98+
"AnyCodable(\(value.debugDescription))"
10199
default:
102-
return "AnyCodable(\(description))"
100+
"AnyCodable(\(description))"
103101
}
104102
}
105103
}
@@ -113,7 +111,6 @@ extension AnyCodable: ExpressibleByStringInterpolation {}
113111
extension AnyCodable: ExpressibleByArrayLiteral {}
114112
extension AnyCodable: ExpressibleByDictionaryLiteral {}
115113

116-
117114
extension AnyCodable: Hashable {
118115
public func hash(into hasher: inout Hasher) {
119116
switch value {

Sources/KarrotCodableKit/AnyCodable/AnyDecodable.swift

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,33 @@
77

88
import Foundation
99

10-
/**
11-
A type-erased `Decodable` value.
12-
13-
The `AnyDecodable` type forwards decoding responsibilities
14-
to an underlying value, hiding its specific underlying type.
15-
16-
You can decode mixed-type values in dictionaries
17-
and other collections that require `Decodable` conformance
18-
by declaring their contained type to be `AnyDecodable`:
19-
20-
let json = """
21-
{
22-
"boolean": true,
23-
"integer": 42,
24-
"double": 3.141592653589793,
25-
"string": "string",
26-
"array": [1, 2, 3],
27-
"nested": {
28-
"a": "alpha",
29-
"b": "bravo",
30-
"c": "charlie"
31-
},
32-
"null": null
33-
}
34-
""".data(using: .utf8)!
35-
36-
let decoder = JSONDecoder()
37-
let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json)
38-
*/
10+
/// A type-erased `Decodable` value.
11+
///
12+
/// The `AnyDecodable` type forwards decoding responsibilities
13+
/// to an underlying value, hiding its specific underlying type.
14+
///
15+
/// You can decode mixed-type values in dictionaries
16+
/// and other collections that require `Decodable` conformance
17+
/// by declaring their contained type to be `AnyDecodable`:
18+
///
19+
/// let json = """
20+
/// {
21+
/// "boolean": true,
22+
/// "integer": 42,
23+
/// "double": 3.141592653589793,
24+
/// "string": "string",
25+
/// "array": [1, 2, 3],
26+
/// "nested": {
27+
/// "a": "alpha",
28+
/// "b": "bravo",
29+
/// "c": "charlie"
30+
/// },
31+
/// "null": null
32+
/// }
33+
/// """.data(using: .utf8)!
34+
///
35+
/// let decoder = JSONDecoder()
36+
/// let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json)
3937
@frozen
4038
public struct AnyDecodable: Decodable {
4139
public let value: Any
@@ -80,7 +78,7 @@ extension _AnyDecodable {
8078
} else {
8179
throw DecodingError.dataCorruptedError(
8280
in: container,
83-
debugDescription: "AnyDecodable value cannot be decoded"
81+
debugDescription: "AnyDecodable value cannot be decoded",
8482
)
8583
}
8684
}
@@ -135,11 +133,11 @@ extension AnyDecodable: CustomStringConvertible {
135133
public var description: String {
136134
switch value {
137135
case is Void:
138-
return String(describing: nil as Any?)
136+
String(describing: nil as Any?)
139137
case let value as CustomStringConvertible:
140-
return value.description
138+
value.description
141139
default:
142-
return String(describing: value)
140+
String(describing: value)
143141
}
144142
}
145143
}
@@ -148,9 +146,9 @@ extension AnyDecodable: CustomDebugStringConvertible {
148146
public var debugDescription: String {
149147
switch value {
150148
case let value as CustomDebugStringConvertible:
151-
return "AnyDecodable(\(value.debugDescription))"
149+
"AnyDecodable(\(value.debugDescription))"
152150
default:
153-
return "AnyDecodable(\(description))"
151+
"AnyDecodable(\(description))"
154152
}
155153
}
156154
}

0 commit comments

Comments
 (0)