Skip to content

Commit efeed28

Browse files
committed
Add support for swiftlint and update formatting
1 parent f66b107 commit efeed28

39 files changed

+1582
-1250
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/.swiftpm
22
/PotentCodables.xcodeproj
33
/Project
4+
/.build

Diff for: .swiftformat

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--swiftversion 5.1
2+
--indent 2
3+
--elseposition next-line
4+
--patternlet inline
5+
--stripunusedargs closure-only
6+
--wraparguments after-first
7+
--binarygrouping none
8+
--decimalgrouping none
9+
--hexgrouping none
10+
--octalgrouping none
11+
--header "//\n// {file}\n// PotentCodables\n//\n// Copyright © {created.year} Outfox, inc.\n//\n//\n// Distributed under the MIT License, See LICENSE for details.\n//"
12+
--enable blankLinesBetweenScopes
13+
--disable consecutiveBlankLines,blankLinesAtStartOfScope,blankLinesAtEndOfScope

Diff for: LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Outfox, inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

Diff for: Package.resolved

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"object": {
3+
"pins": [
4+
{
5+
"package": "SwiftFormat",
6+
"repositoryURL": "https://github.com/nicklockwood/SwiftFormat.git",
7+
"state": {
8+
"branch": null,
9+
"revision": "0708f1eefe0a2ce2aa42fc3ff86125cdb751e63c",
10+
"version": "0.40.10"
11+
}
12+
}
13+
]
14+
},
15+
"version": 1
16+
}

Diff for: Package.swift

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ let package = Package(
1616
targets: ["PotentCodables"]
1717
),
1818
],
19+
dependencies: [
20+
.package(url: "https://github.com/nicklockwood/SwiftFormat.git", .upToNextMinor(from: "0.40.10"))
21+
],
1922
targets: [
2023
.target(
2124
name: "PotentCodables",

Diff for: Sources/AnyCodingKey.swift

+27-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1+
//
2+
// AnyCodingKey.swift
3+
// PotentCodables
4+
//
5+
// Copyright © 2019 Outfox, inc.
6+
//
7+
//
8+
// Distributed under the MIT License, See LICENSE for details.
9+
//
110

211
struct AnyCodingKey: CodingKey, Equatable, Hashable {
312
var stringValue: String
413
var intValue: Int?
514

615
init?(stringValue: String) {
716
self.stringValue = stringValue
8-
self.intValue = nil
17+
intValue = nil
918
}
10-
19+
1120
init(intValue: Int) {
12-
self.stringValue = "\(intValue)"
21+
stringValue = "\(intValue)"
1322
self.intValue = intValue
1423
}
1524

@@ -19,23 +28,25 @@ struct AnyCodingKey: CodingKey, Equatable, Hashable {
1928
}
2029

2130
init(index: Int) {
22-
self.stringValue = "Index \(index)"
23-
self.intValue = index
31+
stringValue = "Index \(index)"
32+
intValue = index
2433
}
2534

2635
init<Key: CodingKey>(_ base: Key) {
2736
if let index = base.intValue {
2837
self.init(intValue: index)
29-
} else {
38+
}
39+
else {
3040
self.init(stringValue: base.stringValue)!
3141
}
3242
}
3343

3444
func key<K: CodingKey>() -> K {
3545
if let intValue = self.intValue {
3646
return K(intValue: intValue)!
37-
} else {
38-
return K(stringValue: self.stringValue)!
47+
}
48+
else {
49+
return K(stringValue: stringValue)!
3950
}
4051
}
4152

@@ -48,8 +59,9 @@ extension AnyCodingKey: Encodable {
4859
var container = encoder.singleValueContainer()
4960
if let intValue = self.intValue {
5061
try container.encode(intValue)
51-
} else {
52-
try container.encode(self.stringValue)
62+
}
63+
else {
64+
try container.encode(stringValue)
5365
}
5466
}
5567
}
@@ -58,11 +70,12 @@ extension AnyCodingKey: Decodable {
5870
init(from decoder: Decoder) throws {
5971
let value = try decoder.singleValueContainer()
6072
if let intValue = try? value.decode(Int.self) {
61-
self.stringValue = "\(intValue)"
73+
stringValue = "\(intValue)"
6274
self.intValue = intValue
63-
} else {
64-
self.stringValue = try! value.decode(String.self)
65-
self.intValue = nil
75+
}
76+
else {
77+
stringValue = try! value.decode(String.self)
78+
intValue = nil
6679
}
6780
}
6881
}

Diff for: Sources/AnyValue/AnyValue.swift

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
// AnyValue.swift
33
// PotentCodables
44
//
5-
// Created by Kevin Wooten on 6/15/19.
5+
// Copyright © 2019 Outfox, inc.
6+
//
7+
//
8+
// Distributed under the MIT License, See LICENSE for details.
69
//
710

811
import Foundation
912

1013

11-
public enum AnyValue : Hashable {
14+
public enum AnyValue: Hashable {
1215

13-
public enum Error : Swift.Error {
16+
public enum Error: Swift.Error {
1417
case unsupportedType
1518
case unsupportedValue(Any)
1619
}
@@ -75,7 +78,7 @@ public enum AnyValue : Hashable {
7578
}
7679

7780

78-
extension AnyValue : Value {
81+
extension AnyValue: Value {
7982

8083
public var isNull: Bool {
8184
guard case .nil = self else { return false }
@@ -140,7 +143,7 @@ extension AnyValue : Value {
140143
* Decodable support
141144
**/
142145

143-
extension AnyValue : Decodable {
146+
extension AnyValue: Decodable {
144147

145148
public init(from decoder: Decoder) throws {
146149

@@ -160,7 +163,7 @@ extension AnyValue : Decodable {
160163
if var container = try? decoder.unkeyedContainer() {
161164

162165
var array = [AnyValue]()
163-
for _ in 0..<(container.count ?? 0) {
166+
for _ in 0 ..< (container.count ?? 0) {
164167
array.append(try container.decode(AnyValue.self))
165168
}
166169

@@ -288,7 +291,7 @@ extension AnyValue : Decodable {
288291
* `Encodable` support
289292
**/
290293

291-
extension AnyValue : Encodable {
294+
extension AnyValue: Encodable {
292295

293296
public func encode(to encoder: Encoder) throws {
294297
var container = encoder.singleValueContainer()

Diff for: Sources/AnyValue/AnyValueDecoder.swift

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
// AnyValueDecoder.swift
33
// PotentCodables
44
//
5-
// Created by Kevin Wooten on 6/15/19.
5+
// Copyright © 2019 Outfox, inc.
6+
//
7+
//
8+
// Distributed under the MIT License, See LICENSE for details.
69
//
710

811
import Foundation
912

1013

11-
public class AnyValueDecoder : ValueDecoder<AnyValue, AnyValueDecoderTransform> {
14+
public class AnyValueDecoder: ValueDecoder<AnyValue, AnyValueDecoderTransform> {
1215

1316
public static let `default` = AnyValueDecoder()
1417

1518
/// The options set on the top-level decoder.
1619
public override var options: AnyValueDecoderTransform.Options {
17-
return AnyValueDecoderTransform.Options(
18-
keyDecodingStrategy: keyDecodingStrategy,
19-
userInfo: userInfo
20-
)
20+
return AnyValueDecoderTransform.Options(keyDecodingStrategy: keyDecodingStrategy,
21+
userInfo: userInfo)
2122
}
2223

2324
public override init() {
@@ -26,13 +27,13 @@ public class AnyValueDecoder : ValueDecoder<AnyValue, AnyValueDecoderTransform>
2627

2728
}
2829

29-
public struct AnyValueDecoderTransform : InternalDecoderTransform {
30+
public struct AnyValueDecoderTransform: InternalDecoderTransform {
3031

3132
public typealias Value = AnyValue
3233

33-
public struct Options : InternalDecoderOptions {
34+
public struct Options: InternalDecoderOptions {
3435
public let keyDecodingStrategy: KeyDecodingStrategy
35-
public let userInfo: [CodingUserInfoKey : Any]
36+
public let userInfo: [CodingUserInfoKey: Any]
3637
}
3738

3839

@@ -147,7 +148,7 @@ public struct AnyValueDecoderTransform : InternalDecoderTransform {
147148
return array
148149
}
149150

150-
public static func valueToKeyedValues(_ value: AnyValue, decoder: InternalValueDecoder<AnyValue, AnyValueDecoderTransform>) throws -> [String : AnyValue]? {
151+
public static func valueToKeyedValues(_ value: AnyValue, decoder: InternalValueDecoder<AnyValue, AnyValueDecoderTransform>) throws -> [String: AnyValue]? {
151152
guard case .dictionary(let dictionary) = value else { return nil }
152153
return dictionary
153154
}

Diff for: Sources/AnyValue/AnyValueEncoder.swift

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
// AnyValueEncoder.swift
33
// PotentCodables
44
//
5-
// Created by Kevin Wooten on 6/15/19.
5+
// Copyright © 2019 Outfox, inc.
6+
//
7+
//
8+
// Distributed under the MIT License, See LICENSE for details.
69
//
710

811
import Foundation
912

1013

11-
public class AnyValueEncoder : ValueEncoder<AnyValue, AnyValueEncoderTransform> {
14+
public class AnyValueEncoder: ValueEncoder<AnyValue, AnyValueEncoderTransform> {
1215

1316
public static let `default` = AnyValueEncoder()
1417

1518
/// The options set on the top-level decoder.
1619
public override var options: AnyValueEncoderTransform.Options {
17-
return AnyValueEncoderTransform.Options(
18-
keyEncodingStrategy: keyEncodingStrategy,
19-
userInfo: userInfo
20-
)
20+
return AnyValueEncoderTransform.Options(keyEncodingStrategy: keyEncodingStrategy,
21+
userInfo: userInfo)
2122
}
2223

2324
public override init() {
@@ -26,13 +27,13 @@ public class AnyValueEncoder : ValueEncoder<AnyValue, AnyValueEncoderTransform>
2627

2728
}
2829

29-
public struct AnyValueEncoderTransform : InternalEncoderTransform {
30+
public struct AnyValueEncoderTransform: InternalEncoderTransform {
3031

3132
public typealias Value = AnyValue
3233

33-
public struct Options : InternalEncoderOptions {
34+
public struct Options: InternalEncoderOptions {
3435
public let keyEncodingStrategy: KeyEncodingStrategy
35-
public let userInfo: [CodingUserInfoKey : Any]
36+
public let userInfo: [CodingUserInfoKey: Any]
3637
}
3738

3839
public static var nilValue: AnyValue {
@@ -137,7 +138,7 @@ public struct AnyValueEncoderTransform : InternalEncoderTransform {
137138
return .array(values)
138139
}
139140

140-
public static func keyedValuesToValue(_ values: [String : AnyValue]) -> AnyValue {
141+
public static func keyedValuesToValue(_ values: [String: AnyValue]) -> AnyValue {
141142
return .dictionary(values)
142143
}
143144

0 commit comments

Comments
 (0)