Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Commit 0a719fe

Browse files
committed
style: add swift-format for code formatting
1 parent c51c8c9 commit 0a719fe

File tree

45 files changed

+1150
-729
lines changed

Some content is hidden

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

45 files changed

+1150
-729
lines changed

.swift-format

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": 1,
3+
"lineLength": 80,
4+
"indentation": {
5+
"spaces": 4
6+
},
7+
"maximumBlankLines": 1,
8+
"respectsExistingLineBreaks": true,
9+
"indentConditionalCompilationBlocks": false,
10+
"rules": {
11+
"AllPublicDeclarationsHaveDocumentation": true,
12+
"NeverForceUnwrap": true,
13+
"NeverUseForceTry": true,
14+
"NoAccessLevelOnExtensionDeclaration": false,
15+
"ValidateDocumentationComments": true
16+
}
17+
}

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let package = Package(
1919
],
2020
dependencies: [
2121
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
22+
.package(url: "https://github.com/apple/swift-format", from: "0.50600.1"),
2223
],
2324
targets: [
2425
.target(

Sources/DynamicCodableKit/DynamicDecodable.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ public extension DynamicDecodable {
103103
}
104104
}
105105

106-
public extension DynamicDecodable where Self: Sequence,
107-
Element: DynamicDecodable {
106+
public extension DynamicDecodable
107+
where
108+
Self: Sequence,
109+
Element: DynamicDecodable
110+
{
108111
/// Cast self as collection type `T`.
109112
///
110113
/// First tries dynamically casting `self` to collection type `T`,
@@ -135,19 +138,20 @@ public extension DynamicDecodable where Self: Sequence,
135138
}
136139
}
137140

138-
extension Optional: DynamicDecodable where Wrapped: DynamicDecodable { }
139-
extension Array: DynamicDecodable where Element: DynamicDecodable { }
141+
extension Optional: DynamicDecodable where Wrapped: DynamicDecodable {}
142+
extension Array: DynamicDecodable where Element: DynamicDecodable {}
140143
extension ClosedRange: DynamicDecodable where Bound: Decodable {}
141144
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
142145
extension CollectionDifference: DynamicDecodable where ChangeElement: Codable {}
143146
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
144-
extension CollectionDifference.Change: DynamicDecodable where ChangeElement: Codable {}
147+
extension CollectionDifference.Change: DynamicDecodable
148+
where ChangeElement: Codable {}
145149
extension ContiguousArray: DynamicDecodable where Element: Decodable {}
146150
extension PartialRangeFrom: DynamicDecodable where Bound: Decodable {}
147151
extension PartialRangeThrough: DynamicDecodable where Bound: Decodable {}
148152
extension PartialRangeUpTo: DynamicDecodable where Bound: Decodable {}
149153
extension Range: DynamicDecodable where Bound: Decodable {}
150-
extension Set: DynamicDecodable where Element: DynamicDecodable { }
154+
extension Set: DynamicDecodable where Element: DynamicDecodable {}
151155

152156
#if canImport(TabularData)
153157
import TabularData
@@ -158,17 +162,20 @@ extension Column: DynamicDecodable where WrappedElement: Decodable {}
158162
#if canImport(MusicKit)
159163
import MusicKit
160164
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8, *)
161-
extension MusicCatalogResourceResponse: DynamicDecodable where MusicItemType: Decodable {}
165+
extension MusicCatalogResourceResponse: DynamicDecodable
166+
where MusicItemType: Decodable {}
162167
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8, *)
163-
extension MusicItemCollection: DynamicDecodable where MusicItemType: Decodable {}
168+
extension MusicItemCollection: DynamicDecodable
169+
where MusicItemType: Decodable {}
164170
#endif
165171

166172
#if canImport(Combine)
167173
import Combine
168174
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
169175
extension Record: DynamicDecodable where Output: Codable, Failure: Codable {}
170176
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
171-
extension Record.Recording: DynamicDecodable where Output: Codable, Failure: Codable {}
177+
extension Record.Recording: DynamicDecodable
178+
where Output: Codable, Failure: Codable {}
172179
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
173180
extension Subscribers.Completion: DynamicDecodable where Failure: Decodable {}
174181
#endif

Sources/DynamicCodableKit/DynamicDecodingConfiguration.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,19 @@ public protocol DynamicDecodingCollectionConfigurationProvider {
5656
/// Provides strict configuration for dynamic array decoding,
5757
/// throw error if decoding fails.
5858
@frozen
59-
public struct StrictCollectionConfiguration: DynamicDecodingCollectionConfigurationProvider {
59+
public struct StrictCollectionConfiguration:
60+
DynamicDecodingCollectionConfigurationProvider
61+
{
6062
/// Use ``CollectionDecodeFailConfiguration/throw`` configuration to throw error if decoding fails.
6163
public static var failConfig: CollectionDecodeFailConfiguration { .throw }
6264
}
6365

6466
/// Provides default configuration for dynamic array decoding,
6567
/// use default value if decoding fails.
6668
@frozen
67-
public struct DefaultValueCollectionConfiguration: DynamicDecodingCollectionConfigurationProvider {
69+
public struct DefaultValueCollectionConfiguration:
70+
DynamicDecodingCollectionConfigurationProvider
71+
{
6872
/// Use ``CollectionDecodeFailConfiguration/deafult`` configuration
6973
/// to use default empty collection value if decoding fails.
7074
public static var failConfig: CollectionDecodeFailConfiguration { .deafult }
@@ -73,7 +77,9 @@ public struct DefaultValueCollectionConfiguration: DynamicDecodingCollectionConf
7377
/// Provides lossy configuration for dynamic array decoding,
7478
/// ignore elements with invalid or corrupt data.
7579
@frozen
76-
public struct LossyCollectionConfiguration: DynamicDecodingCollectionConfigurationProvider {
80+
public struct LossyCollectionConfiguration:
81+
DynamicDecodingCollectionConfigurationProvider
82+
{
7783
/// Use ``CollectionDecodeFailConfiguration/lossy`` configuration
7884
/// to only decode items with valid data while ignoring the rest.
7985
public static var failConfig: CollectionDecodeFailConfiguration { .lossy }

Sources/DynamicCodableKit/DynamicDecodingContext.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ public extension DynamicDecodingContext {
116116
type: B.self,
117117
codingPath: decoder.codingPath
118118
)
119-
}
120-
catch {
119+
} catch {
121120
return try fallbackType.init(from: decoder).castAs(
122121
type: B.self,
123122
codingPath: decoder.codingPath
@@ -131,8 +130,7 @@ public extension DynamicDecodingContext {
131130
type: [B].self,
132131
codingPath: decoder.codingPath
133132
)
134-
}
135-
catch {
133+
} catch {
136134
return try array(for: fallbackType).init(from: decoder).castAs(
137135
type: [B].self,
138136
codingPath: decoder.codingPath

Sources/DynamicCodableKit/DynamicDecodingContextCodingKey/DynamicDecodingCollectionWrapper.swift

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public struct DynamicDecodingCollectionWrapper<
77
DynamicCollection: SequenceInitializable,
88
Config: DynamicDecodingCollectionConfigurationProvider
99
>: PropertyWrapperCodable
10-
where DynamicCollection.Element == ContextCodingKey.Identified {
10+
where DynamicCollection.Element == ContextCodingKey.Identified {
1111
/// The underlying dynamic value collection referenced.
1212
public var wrappedValue: DynamicCollection
1313

@@ -49,7 +49,7 @@ public struct DynamicDecodingCollectionWrapper<
4949
}
5050

5151
public extension KeyedDecodingContainer
52-
where K: DynamicDecodingContextCodingKey {
52+
where K: DynamicDecodingContextCodingKey {
5353
/// Decodes a value of dynamic ``DynamicDecodingCollectionWrapper``
5454
/// type for the given coding key.
5555
///
@@ -62,7 +62,9 @@ public extension KeyedDecodingContainer
6262
/// - Throws: `DecodingError` if ``DynamicDecodingCollectionConfigurationProvider/failConfig``
6363
/// is ``CollectionDecodeFailConfiguration/throw`` and data is invalid or corrupt.
6464
func decode<DynamicCollection, Config>(
65-
_ type: DynamicDecodingCollectionWrapper<K, DynamicCollection, Config>.Type,
65+
_ type: DynamicDecodingCollectionWrapper<
66+
K, DynamicCollection, Config
67+
>.Type,
6668
forKey key: K
6769
) throws -> DynamicDecodingCollectionWrapper<K, DynamicCollection, Config> {
6870
switch Config.failConfig {
@@ -85,19 +87,17 @@ public extension KeyedDecodingContainer
8587
}
8688
return DynamicDecodingCollectionWrapper(
8789
wrappedValue: .init(
88-
(
89-
try? K.context(
90-
forContainer: self
91-
).decodeLossyArrayFrom(decoder)
92-
) ?? .init()
90+
(try? K.context(
91+
forContainer: self
92+
).decodeLossyArrayFrom(decoder)) ?? .init()
9393
)
9494
)
9595
}
9696
}
9797
}
9898

9999
public extension KeyedDecodingContainerProtocol
100-
where Key: DynamicDecodingContextCodingKey {
100+
where Key: DynamicDecodingContextCodingKey {
101101
/// Decodes a value of dynamic ``DynamicDecodingCollectionWrapper``
102102
/// type for the given coding key.
103103
///
@@ -110,9 +110,12 @@ public extension KeyedDecodingContainerProtocol
110110
/// - Throws: `DecodingError` if ``DynamicDecodingCollectionConfigurationProvider/failConfig``
111111
/// is ``CollectionDecodeFailConfiguration/throw`` and data is invalid or corrupt.
112112
func decode<DynamicCollection, Config>(
113-
_ type: DynamicDecodingCollectionWrapper<Key, DynamicCollection, Config>.Type,
113+
_ type: DynamicDecodingCollectionWrapper<
114+
Key, DynamicCollection, Config
115+
>.Type,
114116
forKey key: Key
115-
) throws -> DynamicDecodingCollectionWrapper<Key, DynamicCollection, Config> {
117+
) throws -> DynamicDecodingCollectionWrapper<Key, DynamicCollection, Config>
118+
{
116119
switch Config.failConfig {
117120
case .throw, .deafult:
118121
do {
@@ -133,11 +136,9 @@ public extension KeyedDecodingContainerProtocol
133136
}
134137
return DynamicDecodingCollectionWrapper(
135138
wrappedValue: .init(
136-
(
137-
try? Key.context(
138-
forContainer: self
139-
).decodeLossyArrayFrom(decoder)
140-
) ?? .init()
139+
(try? Key.context(
140+
forContainer: self
141+
).decodeLossyArrayFrom(decoder)) ?? .init()
141142
)
142143
)
143144
}

Sources/DynamicCodableKit/DynamicDecodingContextCodingKey/DynamicDecodingContextCodingKey.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ public protocol DynamicDecodingContextCodingKey: CodingKey {
2323

2424
/// A ``DynamicDecodingContextCodingKey`` type that decides dynamic decoding context based on its associated
2525
/// ``DynamicDecodingContextIdentifierKey`` contained by ``identifierCodingKey``.
26-
public protocol DynamicDecodingContextIdentifierCodingKey: DynamicDecodingContextCodingKey {
26+
public protocol DynamicDecodingContextIdentifierCodingKey:
27+
DynamicDecodingContextCodingKey
28+
{
2729
/// The ``DynamicDecodingContextIdentifierKey`` type that ``identifierCodingKey`` contains.
2830
associatedtype Identifier: DynamicDecodingContextIdentifierKey
29-
where Identifier.Identified == Identified
31+
where Identifier.Identified == Identified
3032

3133
/// The coding key value that contains ``DynamicDecodingContextIdentifierKey``.
3234
static var identifierCodingKey: Self { get }

Sources/DynamicCodableKit/DynamicDecodingContextCodingKey/DynamicDecodingDefaultValueWrapper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct DynamicDecodingDefaultValueWrapper<
4444
}
4545

4646
public extension KeyedDecodingContainer
47-
where K: DynamicDecodingContextCodingKey {
47+
where K: DynamicDecodingContextCodingKey {
4848
/// Decodes a value of dynamic ``DynamicDecodingDefaultValueWrapper``
4949
/// type for the given coding key.
5050
///
@@ -71,7 +71,7 @@ public extension KeyedDecodingContainer
7171
}
7272

7373
public extension KeyedDecodingContainerProtocol
74-
where Key: DynamicDecodingContextCodingKey {
74+
where Key: DynamicDecodingContextCodingKey {
7575
/// Decodes a value of dynamic ``DynamicDecodingDefaultValueWrapper``
7676
/// type for the given coding key.
7777
///

Sources/DynamicCodableKit/DynamicDecodingContextCodingKey/DynamicDecodingWrapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public struct DynamicDecodingWrapper<
3030
}
3131

3232
public extension KeyedDecodingContainerProtocol
33-
where Key: DynamicDecodingContextCodingKey {
33+
where Key: DynamicDecodingContextCodingKey {
3434
/// Decodes a value of dynamic ``DynamicDecodingWrapper``
3535
/// type for the given coding key.
3636
///

Sources/DynamicCodableKit/DynamicDecodingContextContainerCodingKey/DynamicDecodingCollectionDictionaryWrapper.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ public struct DynamicDecodingCollectionDictionaryWrapper<
77
DynamicCollection: SequenceInitializable,
88
Config: DynamicDecodingCollectionConfigurationProvider
99
>: PropertyWrapperCodable
10-
where ContainerCodingKey: Hashable,
11-
DynamicCollection.Element == ContainerCodingKey.Contained {
10+
where
11+
ContainerCodingKey: Hashable,
12+
DynamicCollection.Element == ContainerCodingKey.Contained
13+
{
1214
/// The underlying dictionary of ``DynamicDecodingContextContainerCodingKey`` key and
1315
/// dynamic ``DynamicDecodingContextContainerCodingKey/Contained`` collection value.
1416
public var wrappedValue: [ContainerCodingKey: DynamicCollection]
@@ -31,10 +33,14 @@ public struct DynamicDecodingCollectionDictionaryWrapper<
3133
public init(from decoder: Decoder) throws {
3234
switch Config.failConfig {
3335
case .throw:
34-
let container = try decoder.container(keyedBy: ContainerCodingKey.self)
36+
let container = try decoder.container(
37+
keyedBy: ContainerCodingKey.self
38+
)
3539
self.wrappedValue = try container.decode()
3640
case .deafult:
37-
let container = try? decoder.container(keyedBy: ContainerCodingKey.self)
41+
let container = try? decoder.container(
42+
keyedBy: ContainerCodingKey.self
43+
)
3844
self.wrappedValue = container?.decodeValidContainers() ?? .init()
3945
default:
4046
guard
@@ -114,8 +120,10 @@ public typealias StrictDynamicDecodingCollectionDictionaryWrapper<
114120
ContainerCodingKey,
115121
DynamicCollection,
116122
StrictCollectionConfiguration
117-
> where ContainerCodingKey: Hashable,
118-
DynamicCollection.Element == ContainerCodingKey.Contained
123+
>
124+
where
125+
ContainerCodingKey: Hashable,
126+
DynamicCollection.Element == ContainerCodingKey.Contained
119127

120128
/// A property wrapper type that decodes valid data associated to key into a dictionary value of
121129
/// ``DynamicDecodingContextContainerCodingKey`` coding key and their dynamic
@@ -133,8 +141,10 @@ public typealias DefaultValueDynamicDecodingCollectionDictionaryWrapper<
133141
ContainerCodingKey,
134142
DynamicCollection,
135143
DefaultValueCollectionConfiguration
136-
> where ContainerCodingKey: Hashable,
137-
DynamicCollection.Element == ContainerCodingKey.Contained
144+
>
145+
where
146+
ContainerCodingKey: Hashable,
147+
DynamicCollection.Element == ContainerCodingKey.Contained
138148

139149
/// A property wrapper type that decodes valid data into a dictionary value of
140150
/// ``DynamicDecodingContextContainerCodingKey`` coding key and
@@ -152,5 +162,7 @@ public typealias LossyDynamicDecodingCollectionDictionaryWrapper<
152162
ContainerCodingKey,
153163
DynamicCollection,
154164
LossyCollectionConfiguration
155-
> where ContainerCodingKey: Hashable,
156-
DynamicCollection.Element == ContainerCodingKey.Contained
165+
>
166+
where
167+
ContainerCodingKey: Hashable,
168+
DynamicCollection.Element == ContainerCodingKey.Contained

0 commit comments

Comments
 (0)