Skip to content

Commit 3f73125

Browse files
committed
Apply formatting
1 parent 89ef2cf commit 3f73125

28 files changed

+198
-184
lines changed

.swiftformat

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# file options
2+
3+
--swiftversion 5.2
4+
--exclude .build
5+
6+
# format options
7+
8+
--self insert
9+
--patternlet inline
10+
--stripunusedargs unnamed-only
11+
--ifdef no-indent
12+
13+
# rules

Package.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,29 @@ let package = Package(
1919
products: [
2020
.library(
2121
name: "StructuredHeaders",
22-
targets: ["StructuredHeaders"]),
22+
targets: ["StructuredHeaders"]
23+
),
2324
.library(
2425
name: "CodableStructuredHeaders",
25-
targets: ["CodableStructuredHeaders"]),
26+
targets: ["CodableStructuredHeaders"]
27+
),
2628
],
2729
targets: [
2830
.target(
2931
name: "StructuredHeaders",
30-
dependencies: []),
32+
dependencies: []
33+
),
3134
.target(
3235
name: "CodableStructuredHeaders",
33-
dependencies: ["StructuredHeaders"]),
36+
dependencies: ["StructuredHeaders"]
37+
),
3438
.target(
3539
name: "sh-parser",
36-
dependencies: ["StructuredHeaders"]),
40+
dependencies: ["StructuredHeaders"]
41+
),
3742
.testTarget(
3843
name: "StructuredHeadersTests",
39-
dependencies: ["StructuredHeaders", "CodableStructuredHeaders"]),
44+
dependencies: ["StructuredHeaders", "CodableStructuredHeaders"]
45+
),
4046
]
4147
)

Sources/CodableStructuredHeaders/Decoder/BareInnerListDecoder.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@ struct BareInnerListDecoder<BaseData: RandomAccessCollection> where BaseData.Ele
3030

3131
extension BareInnerListDecoder: UnkeyedDecodingContainer {
3232
var codingPath: [CodingKey] {
33-
return self.decoder.codingPath
33+
self.decoder.codingPath
3434
}
3535

3636
var count: Int? {
37-
return self.list.count
37+
self.list.count
3838
}
3939

4040
var isAtEnd: Bool {
41-
return self.currentOffset == self.list.count
41+
self.currentOffset == self.list.count
4242
}
4343

4444
var currentIndex: Int {
45-
return self.currentOffset
45+
self.currentOffset
4646
}
4747

4848
mutating func decodeNil() throws -> Bool {
4949
// We never decode nil.
50-
return false
50+
false
5151
}
5252

53-
mutating func decode<T>(_ type: T.Type) throws -> T where T : Decodable {
53+
mutating func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
5454
// This is a request to decode a scalar. We decode the next entry and increment the index.
5555
guard !self.isAtEnd else {
5656
throw StructuredHeaderError.indexOutOfRange
@@ -77,7 +77,7 @@ extension BareInnerListDecoder: UnkeyedDecodingContainer {
7777
}
7878
}
7979

80-
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey> where NestedKey : CodingKey {
80+
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws -> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey {
8181
// This is a request to decode a full item. We decode the next entry and increment the index.
8282
guard !self.isAtEnd else {
8383
throw StructuredHeaderError.indexOutOfRange
@@ -116,5 +116,4 @@ extension BareInnerListDecoder: UnkeyedDecodingContainer {
116116
// No inheritance here folks
117117
throw StructuredHeaderError.invalidTypeForItem
118118
}
119-
120119
}

Sources/CodableStructuredHeaders/Decoder/BareItemDecoder.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,59 +27,59 @@ struct BareItemDecoder<BaseData: RandomAccessCollection> where BaseData.Element
2727

2828
extension BareItemDecoder: SingleValueDecodingContainer {
2929
var codingPath: [CodingKey] {
30-
return self._codingPath as [CodingKey]
30+
self._codingPath as [CodingKey]
3131
}
3232

3333
func decode(_ type: UInt8.Type) throws -> UInt8 {
34-
return try self._decodeFixedWidthInteger(type)
34+
try self._decodeFixedWidthInteger(type)
3535
}
3636

3737
func decode(_ type: Int8.Type) throws -> Int8 {
38-
return try self._decodeFixedWidthInteger(type)
38+
try self._decodeFixedWidthInteger(type)
3939
}
4040

4141
func decode(_ type: UInt16.Type) throws -> UInt16 {
42-
return try self._decodeFixedWidthInteger(type)
42+
try self._decodeFixedWidthInteger(type)
4343
}
4444

4545
func decode(_ type: Int16.Type) throws -> Int16 {
46-
return try self._decodeFixedWidthInteger(type)
46+
try self._decodeFixedWidthInteger(type)
4747
}
4848

4949
func decode(_ type: UInt32.Type) throws -> UInt32 {
50-
return try self._decodeFixedWidthInteger(type)
50+
try self._decodeFixedWidthInteger(type)
5151
}
5252

5353
func decode(_ type: Int32.Type) throws -> Int32 {
54-
return try self._decodeFixedWidthInteger(type)
54+
try self._decodeFixedWidthInteger(type)
5555
}
5656

5757
func decode(_ type: UInt64.Type) throws -> UInt64 {
58-
return try self._decodeFixedWidthInteger(type)
58+
try self._decodeFixedWidthInteger(type)
5959
}
6060

6161
func decode(_ type: Int64.Type) throws -> Int64 {
62-
return try self._decodeFixedWidthInteger(type)
62+
try self._decodeFixedWidthInteger(type)
6363
}
6464

6565
func decode(_ type: UInt.Type) throws -> UInt {
66-
return try self._decodeFixedWidthInteger(type)
66+
try self._decodeFixedWidthInteger(type)
6767
}
6868

6969
func decode(_ type: Int.Type) throws -> Int {
70-
return try self._decodeFixedWidthInteger(type)
70+
try self._decodeFixedWidthInteger(type)
7171
}
7272

7373
func decode(_ type: Float.Type) throws -> Float {
74-
return try self._decodeBinaryFloatingPoint(type)
74+
try self._decodeBinaryFloatingPoint(type)
7575
}
7676

7777
func decode(_ type: Double.Type) throws -> Double {
78-
return try self._decodeBinaryFloatingPoint(type)
78+
try self._decodeBinaryFloatingPoint(type)
7979
}
8080

81-
func decode(_ type: String.Type) throws -> String {
82-
switch item {
81+
func decode(_: String.Type) throws -> String {
82+
switch self.item {
8383
case .string(let string):
8484
return string
8585
case .token(let token):
@@ -89,15 +89,15 @@ extension BareItemDecoder: SingleValueDecodingContainer {
8989
}
9090
}
9191

92-
func decode(_ type: Bool.Type) throws -> Bool {
92+
func decode(_: Bool.Type) throws -> Bool {
9393
guard case .bool(let bool) = self.item else {
9494
throw StructuredHeaderError.invalidTypeForItem
9595
}
9696

9797
return bool
9898
}
9999

100-
func decode(_ type: Data.Type) throws -> Data {
100+
func decode(_: Data.Type) throws -> Data {
101101
guard case .undecodedByteSequence(let data) = self.item else {
102102
throw StructuredHeaderError.invalidTypeForItem
103103
}
@@ -109,7 +109,7 @@ extension BareItemDecoder: SingleValueDecodingContainer {
109109
return decoded
110110
}
111111

112-
func decode(_ type: Decimal.Type) throws -> Decimal {
112+
func decode(_: Decimal.Type) throws -> Decimal {
113113
guard case .decimal(let pseudoDecimal) = self.item else {
114114
throw StructuredHeaderError.invalidTypeForItem
115115
}
@@ -121,7 +121,7 @@ extension BareItemDecoder: SingleValueDecodingContainer {
121121

122122
func decodeNil() -> Bool {
123123
// Items are never nil.
124-
return false
124+
false
125125
}
126126

127127
func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
@@ -163,7 +163,7 @@ extension BareItemDecoder: SingleValueDecodingContainer {
163163
}
164164
}
165165

166-
private func _decodeBinaryFloatingPoint<T: BinaryFloatingPoint>(_ type: T.Type) throws -> T {
166+
private func _decodeBinaryFloatingPoint<T: BinaryFloatingPoint>(_: T.Type) throws -> T {
167167
guard case .decimal(let decimal) = self.item else {
168168
throw StructuredHeaderError.invalidTypeForItem
169169
}
@@ -172,7 +172,7 @@ extension BareItemDecoder: SingleValueDecodingContainer {
172172
return T(Double(decimal))
173173
}
174174

175-
private func _decodeFixedWidthInteger<T: FixedWidthInteger>(_ type: T.Type) throws -> T {
175+
private func _decodeFixedWidthInteger<T: FixedWidthInteger>(_: T.Type) throws -> T {
176176
guard case .integer(let int) = self.item else {
177177
throw StructuredHeaderError.invalidTypeForItem
178178
}

Sources/CodableStructuredHeaders/Decoder/DictionaryKeyedContainer.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ struct DictionaryKeyedContainer<Key: CodingKey, BaseData: RandomAccessCollection
2727

2828
extension DictionaryKeyedContainer: KeyedDecodingContainerProtocol {
2929
var codingPath: [CodingKey] {
30-
return self.decoder.codingPath
30+
self.decoder.codingPath
3131
}
3232

3333
var allKeys: [Key] {
34-
return self.dictionary.compactMap { Key(stringValue: $0.0) }
34+
self.dictionary.compactMap { Key(stringValue: $0.0) }
3535
}
3636

3737
func contains(_ key: Key) -> Bool {
38-
return self.dictionary.contains(where: { $0.0 == key.stringValue })
38+
self.dictionary.contains(where: { $0.0 == key.stringValue })
3939
}
4040

4141
func decodeNil(forKey key: Key) throws -> Bool {
4242
// We will decode nil if the key is not present.
43-
return !self.contains(key)
43+
!self.contains(key)
4444
}
4545

46-
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T : Decodable {
46+
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
4747
try self.decoder.push(_StructuredHeaderCodingKey(key, keyDecodingStrategy: self.decoder.keyDecodingStrategy))
4848
defer {
4949
self.decoder.pop()

Sources/CodableStructuredHeaders/Decoder/KeyedInnerListDecoder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ struct KeyedInnerListDecoder<Key: CodingKey, BaseData: RandomAccessCollection> w
3232

3333
extension KeyedInnerListDecoder: KeyedDecodingContainerProtocol {
3434
var codingPath: [CodingKey] {
35-
return self.decoder.codingPath
35+
self.decoder.codingPath
3636
}
3737

3838
var allKeys: [Key] {
39-
return keyedInnerListDecoderSupportedKeys.compactMap { Key(stringValue: $0) }
39+
keyedInnerListDecoderSupportedKeys.compactMap { Key(stringValue: $0) }
4040
}
4141

4242
func contains(_ key: Key) -> Bool {
43-
return keyedInnerListDecoderSupportedKeys.contains(key.stringValue)
43+
keyedInnerListDecoderSupportedKeys.contains(key.stringValue)
4444
}
4545

4646
func decodeNil(forKey key: Key) throws -> Bool {
4747
// Keys are never nil for this type.
48-
return false
48+
false
4949
}
5050

5151
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {

Sources/CodableStructuredHeaders/Decoder/KeyedItemDecoder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ struct KeyedItemDecoder<Key: CodingKey, BaseData: RandomAccessCollection> where
3232

3333
extension KeyedItemDecoder: KeyedDecodingContainerProtocol {
3434
var codingPath: [CodingKey] {
35-
return self.decoder.codingPath
35+
self.decoder.codingPath
3636
}
3737

3838
var allKeys: [Key] {
39-
return keyedItemDecoderSupportedKeys.compactMap { Key(stringValue: $0) }
39+
keyedItemDecoderSupportedKeys.compactMap { Key(stringValue: $0) }
4040
}
4141

4242
func contains(_ key: Key) -> Bool {
43-
return keyedItemDecoderSupportedKeys.contains(key.stringValue)
43+
keyedItemDecoderSupportedKeys.contains(key.stringValue)
4444
}
4545

4646
func decodeNil(forKey key: Key) throws -> Bool {
4747
// Keys are never nil for this type.
48-
return false
48+
false
4949
}
5050

5151
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {

Sources/CodableStructuredHeaders/Decoder/ParametersDecoder.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ struct ParametersDecoder<Key: CodingKey, BaseData: RandomAccessCollection> where
2727

2828
extension ParametersDecoder: KeyedDecodingContainerProtocol {
2929
var codingPath: [CodingKey] {
30-
return self.decoder.codingPath
30+
self.decoder.codingPath
3131
}
3232

3333
var allKeys: [Key] {
34-
return self.parameters.compactMap { Key(stringValue: $0.0) }
34+
self.parameters.compactMap { Key(stringValue: $0.0) }
3535
}
3636

3737
func contains(_ key: Key) -> Bool {
38-
return self.parameters.contains(where: { $0.0 == key.stringValue })
38+
self.parameters.contains(where: { $0.0 == key.stringValue })
3939
}
4040

4141
func decodeNil(forKey key: Key) throws -> Bool {
4242
// We will decode nil if the key is not present.
43-
return !self.contains(key)
43+
!self.contains(key)
4444
}
4545

46-
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T : Decodable {
46+
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
4747
try self.decoder.push(_StructuredHeaderCodingKey(key, keyDecodingStrategy: self.decoder.keyDecodingStrategy))
4848
defer {
4949
self.decoder.pop()

Sources/CodableStructuredHeaders/Decoder/StructuredFieldDecoder.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public struct StructuredFieldDecoder {
2020
/// A strategy that should be used to map coding keys to wire format keys.
2121
public var keyDecodingStrategy: KeyDecodingStrategy?
2222

23-
public init() { }
23+
public init() {}
2424
}
2525

2626
extension StructuredFieldDecoder {
@@ -129,10 +129,10 @@ class _StructuredFieldDecoder<BaseData: RandomAccessCollection> where BaseData.E
129129

130130
extension _StructuredFieldDecoder: Decoder {
131131
var codingPath: [CodingKey] {
132-
return self._codingStack.map { $0.key as CodingKey }
132+
self._codingStack.map { $0.key as CodingKey }
133133
}
134134

135-
var userInfo: [CodingUserInfoKey : Any] {
135+
var userInfo: [CodingUserInfoKey: Any] {
136136
[:]
137137
}
138138

@@ -147,7 +147,7 @@ extension _StructuredFieldDecoder: Decoder {
147147
self._codingStack.removeLast()
148148
}
149149

150-
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> where Key : CodingKey {
150+
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> where Key: CodingKey {
151151
if self.currentElement == nil {
152152
// First parse. This may be a dictionary, but depending on the keys this may also be list or item.
153153
// We can't really detect this (Key isn't caseiterable) so we just kinda have to hope. Users can tell
@@ -321,6 +321,6 @@ extension _StructuredFieldDecoder {
321321

322322
/// The element at the current head of the coding stack.
323323
private var currentElement: Element? {
324-
return self._codingStack.last.map { $0.element }
324+
self._codingStack.last.map { $0.element }
325325
}
326326
}

Sources/CodableStructuredHeaders/Decoder/StructuredHeaderCodingKey.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414
import StructuredHeaders
1515

16-
struct _StructuredHeaderCodingKey : CodingKey {
16+
struct _StructuredHeaderCodingKey: CodingKey {
1717
var stringValue: String
1818
var intValue: Int?
1919

0 commit comments

Comments
 (0)