Skip to content

Commit baa3388

Browse files
committed
chore: Format code using swiftformat
1 parent a191895 commit baa3388

13 files changed

+223
-215
lines changed

.swiftformat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--indent 2
2+
--indentcase true
3+
--patternlet inline
4+
--disable unusedArguments

Sources/Saga/Atom.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Foundation
88

99
#if canImport(FoundationXML)
10-
import FoundationXML
10+
import FoundationXML
1111
#endif
1212

1313
/// A rendered which creates an Atom feed for Items
@@ -20,64 +20,64 @@ import FoundationXML
2020
/// - Returns: A function which takes a rendering context, and returns a string.
2121
public func atomFeed<Context: AtomContext, M>(title: String, author: String? = nil, baseURL: URL, summary: ((Item<M>) -> String?)? = nil) -> (_ context: Context) -> String where Context.M == M {
2222
let RFC3339_DF = ISO8601DateFormatter()
23-
23+
2424
return { context in
2525
let feedPath = context.outputPath.string
26-
26+
2727
// Create the root element
2828
let rootElement = XMLElement(name: "feed")
2929
rootElement.setAttributesWith(["xmlns": "http://www.w3.org/2005/Atom"])
30-
30+
3131
// Create the XML document
3232
let XML = XMLDocument(rootElement: rootElement)
33-
33+
3434
let idElement = XMLElement(name: "id")
3535
idElement.stringValue = baseURL.appendingPathComponent(feedPath).absoluteString
3636
rootElement.addChild(idElement)
37-
37+
3838
rootElement.addChild(XMLElement(name: "title", stringValue: title))
39-
39+
4040
if let author = author {
4141
let authorElement = XMLElement(name: "author")
4242
authorElement.addChild(XMLElement(name: "name", stringValue: author))
4343
rootElement.addChild(authorElement)
4444
}
45-
45+
4646
let linkElement = XMLElement(name: "link")
4747
linkElement.setAttributesWith(["rel": "self", "href": baseURL.absoluteString])
4848
rootElement.addChild(linkElement)
49-
49+
5050
let updatedElement = XMLElement(name: "updated", stringValue: RFC3339_DF.string(from: Date()))
5151
rootElement.addChild(updatedElement)
52-
52+
5353
// add entries to feed
5454
for item in context.items {
5555
// create entry element
5656
let entryElement = XMLElement(name: "entry")
57-
57+
5858
let idElement = XMLElement(name: "id")
5959
idElement.stringValue = baseURL.appendingPathComponent(item.url).absoluteString
60-
60+
6161
entryElement.addChild(idElement)
6262
entryElement.addChild(XMLElement(name: "title", stringValue: item.title))
6363
entryElement.addChild(XMLElement(name: "updated", stringValue: RFC3339_DF.string(from: item.lastModified)))
64-
64+
6565
if let summary, let summaryString = summary(item) {
6666
let summaryElement = XMLElement(name: "summary", stringValue: summaryString)
6767
entryElement.addChild(summaryElement)
6868
}
69-
69+
7070
let contentElement = XMLElement(name: "content", stringValue: item.body)
7171
contentElement.setAttributesWith(["type": "html"])
7272
entryElement.addChild(contentElement)
7373

7474
let alternateElement = XMLElement(name: "link")
7575
alternateElement.setAttributesWith(["rel": "alternate", "href": baseURL.appendingPathComponent(item.url).absoluteString])
7676
entryElement.addChild(alternateElement)
77-
77+
7878
rootElement.addChild(entryElement)
7979
}
80-
80+
8181
return String(data: XML.xmlData(options: [.nodePrettyPrint]), encoding: .utf8) ?? ""
8282
}
8383
}

Sources/Saga/FileContainer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ public class FileContainer {
77
public internal(set) var item: AnyItem?
88
public var handled: Bool
99

10-
internal init(path: Path, relativePath: Path) {
10+
init(path: Path, relativePath: Path) {
1111
self.path = path
1212
self.relativePath = relativePath
13-
self.item = nil
14-
self.handled = false
13+
item = nil
14+
handled = false
1515
}
1616
}

Sources/Saga/FileIO.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import PathKit
21
import Foundation
2+
import PathKit
33

44
/// A wrapper around file operations used by Saga, to abstract away the PathKit dependency.
55
public struct FileIO {

Sources/Saga/MetadataDecoder.swift

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66

77
import Foundation
88

9-
internal final class MetadataDecoder: Decoder {
10-
public var userInfo: [CodingUserInfoKey : Any] { [:] }
9+
final class MetadataDecoder: Decoder {
10+
public var userInfo: [CodingUserInfoKey: Any] { [:] }
1111
public let codingPath: [CodingKey]
1212

13-
private let metadata: [String : String]
13+
private let metadata: [String: String]
1414
private let dateFormatter: DateFormatter
15-
private lazy var keyedContainers = [ObjectIdentifier : Any]()
15+
private lazy var keyedContainers = [ObjectIdentifier: Any]()
1616

17-
public init(metadata: [String : String],
18-
codingPath: [CodingKey] = [],
19-
dateFormatter: DateFormatter) {
17+
public init(metadata: [String: String],
18+
codingPath: [CodingKey] = [],
19+
dateFormatter: DateFormatter)
20+
{
2021
self.metadata = metadata
2122
self.codingPath = codingPath
2223
self.dateFormatter = dateFormatter
@@ -69,19 +70,20 @@ private extension MetadataDecoder {
6970
struct KeyedContainer<Key: CodingKey>: KeyedDecodingContainerProtocol {
7071
var allKeys: [Key] { keys.all() }
7172

72-
let metadata: [String : String]
73+
let metadata: [String: String]
7374
let keys: KeyMap<Key>
7475
let codingPath: [CodingKey]
7576
let prefix: String
7677
let dateFormatter: DateFormatter
7778

78-
init(metadata: [String : String],
79+
init(metadata: [String: String],
7980
codingPath: [CodingKey],
80-
dateFormatter: DateFormatter) {
81+
dateFormatter: DateFormatter)
82+
{
8183
self.metadata = metadata
82-
self.keys = KeyMap(raw: metadata.keys, codingPath: codingPath)
84+
keys = KeyMap(raw: metadata.keys, codingPath: codingPath)
8385
self.codingPath = codingPath
84-
self.prefix = codingPath.asPrefix()
86+
prefix = codingPath.asPrefix()
8587
self.dateFormatter = dateFormatter
8688
}
8789

@@ -204,8 +206,8 @@ private extension MetadataDecoder {
204206
throw DecodingError.keyNotFound(key, DecodingError.Context(
205207
codingPath: codingPath.appending(key),
206208
debugDescription: """
207-
No value found for key '\(key.stringValue)'.
208-
"""
209+
No value found for key '\(key.stringValue)'.
210+
"""
209211
))
210212
}
211213

@@ -220,9 +222,9 @@ private extension MetadataDecoder {
220222
forKey: key,
221223
in: self,
222224
debugDescription: """
223-
Could not convert '\(string)' into a value\
224-
of type '\(String(describing: T.self))'.
225-
"""
225+
Could not convert '\(string)' into a value\
226+
of type '\(String(describing: T.self))'.
227+
"""
226228
)
227229
}
228230

@@ -330,9 +332,9 @@ private extension MetadataDecoder {
330332
DecodingError.Context(
331333
codingPath: codingPath,
332334
debugDescription: """
333-
Cannot obtain a keyed container while decoding\
334-
using an unkeyed metadata container.
335-
"""
335+
Cannot obtain a keyed container while decoding\
336+
using an unkeyed metadata container.
337+
"""
336338
)
337339
)
338340
}
@@ -359,10 +361,9 @@ private extension MetadataDecoder {
359361
DecodingError.Context(
360362
codingPath: codingPath,
361363
debugDescription: """
362-
Index \(currentIndex) is out of bounds.
363-
"""
364-
)
365-
)
364+
Index \(currentIndex) is out of bounds.
365+
"""
366+
))
366367
}
367368

368369
let next = components[currentIndex]
@@ -381,9 +382,9 @@ private extension MetadataDecoder {
381382
throw DecodingError.dataCorruptedError(
382383
in: self,
383384
debugDescription: """
384-
Could not convert '\(string)' into a value\
385-
of type '\(String(describing: T.self))'.
386-
"""
385+
Could not convert '\(string)' into a value\
386+
of type '\(String(describing: T.self))'.
387+
"""
387388
)
388389
}
389390

@@ -392,7 +393,7 @@ private extension MetadataDecoder {
392393
}
393394

394395
struct UnkeyedDecoder: Decoder {
395-
var userInfo: [CodingUserInfoKey : Any] { [:] }
396+
var userInfo: [CodingUserInfoKey: Any] { [:] }
396397

397398
let components: [Substring]
398399
var codingPath: [CodingKey]
@@ -491,9 +492,9 @@ private extension MetadataDecoder {
491492
throw DecodingError.dataCorruptedError(
492493
in: self,
493494
debugDescription: """
494-
Could not convert '\(value)' into a value\
495-
of type '\(String(describing: T.self))'.
496-
"""
495+
Could not convert '\(value)' into a value\
496+
of type '\(String(describing: T.self))'.
497+
"""
497498
)
498499
}
499500

@@ -502,7 +503,7 @@ private extension MetadataDecoder {
502503
}
503504

504505
struct SingleValueDecoder: Decoder {
505-
var userInfo: [CodingUserInfoKey : Any] { [:] }
506+
var userInfo: [CodingUserInfoKey: Any] { [:] }
506507

507508
let value: String
508509
let codingPath: [CodingKey]
@@ -536,7 +537,8 @@ private extension MetadataDecoder {
536537
private var evaluated: Evaluated?
537538

538539
init(raw: Dictionary<String, String>.Keys,
539-
codingPath: [CodingKey]) {
540+
codingPath: [CodingKey])
541+
{
540542
self.raw = raw
541543
self.codingPath = codingPath
542544
}
@@ -604,7 +606,8 @@ private extension Array where Element == CodingKey {
604606
private extension URL {
605607
static func decode(from string: String,
606608
forKey key: CodingKey?,
607-
at codingPath: [CodingKey]) throws -> Self {
609+
at codingPath: [CodingKey]) throws -> Self
610+
{
608611
guard let url = URL(string: string) else {
609612
throw DecodingError.dataCorrupted(
610613
DecodingError.Context(
@@ -622,7 +625,8 @@ private extension Date {
622625
static func decode(from string: String,
623626
forKey key: CodingKey?,
624627
at codingPath: [CodingKey],
625-
formatter: DateFormatter) throws -> Self {
628+
formatter: DateFormatter) throws -> Self
629+
{
626630
guard let date = formatter.date(from: string) else {
627631
let formatDescription = formatter.dateFormat.map {
628632
" Expected format: \($0)."
@@ -632,8 +636,8 @@ private extension Date {
632636
DecodingError.Context(
633637
codingPath: key.map(codingPath.appending) ?? codingPath,
634638
debugDescription: """
635-
Invalid date string.\(formatDescription ?? "")
636-
"""
639+
Invalid date string.\(formatDescription ?? "")
640+
"""
637641
)
638642
)
639643
}
@@ -652,8 +656,8 @@ private extension DecodingError {
652656
DecodingError.Context(
653657
codingPath: path,
654658
debugDescription: """
655-
Cannot obtain a keyed decoding container within this context.
656-
"""
659+
Cannot obtain a keyed decoding container within this context.
660+
"""
657661
)
658662
)
659663
}
@@ -664,8 +668,8 @@ private extension DecodingError {
664668
DecodingError.Context(
665669
codingPath: path,
666670
debugDescription: """
667-
Cannot obtain an unkeyed decoding container within this context.
668-
"""
671+
Cannot obtain an unkeyed decoding container within this context.
672+
"""
669673
)
670674
)
671675
}
@@ -676,8 +680,8 @@ private extension DecodingError {
676680
DecodingError.Context(
677681
codingPath: path,
678682
debugDescription: """
679-
Cannot obtain a single value decoding container within this context.
680-
"""
683+
Cannot obtain a single value decoding container within this context.
684+
"""
681685
)
682686
)
683687
}
@@ -691,36 +695,36 @@ private extension Array {
691695
}
692696
}
693697

694-
internal func makeMetadataDecoder(for metadata: [String: String]) -> MetadataDecoder {
698+
func makeMetadataDecoder(for metadata: [String: String]) -> MetadataDecoder {
695699
let dateFormatter = DateFormatter()
696700
dateFormatter.dateFormat = "yyyy-MM-dd"
697701
dateFormatter.timeZone = .current
698-
702+
699703
return MetadataDecoder(
700704
metadata: metadata,
701705
dateFormatter: dateFormatter
702706
)
703707
}
704708

705-
internal func resolveDate(from decoder: MetadataDecoder) throws -> Date? {
709+
func resolveDate(from decoder: MetadataDecoder) throws -> Date? {
706710
return try decoder.decodeIfPresent("date", as: Date.self)
707711
}
708712

709713
private struct AnyCodingKey: CodingKey {
710714
var stringValue: String
711715
var intValue: Int?
712-
716+
713717
init(_ string: String) {
714718
stringValue = string
715719
}
716-
720+
717721
init?(stringValue: String) {
718722
self.stringValue = stringValue
719723
}
720-
724+
721725
init?(intValue: Int) {
722726
self.intValue = intValue
723-
self.stringValue = String(intValue)
727+
stringValue = String(intValue)
724728
}
725729
}
726730

@@ -730,7 +734,7 @@ private extension Decoder {
730734
func decodeIfPresent<T: Decodable>(_ key: String, as type: T.Type = T.self) throws -> T? {
731735
return try decodeIfPresent(AnyCodingKey(key), as: type)
732736
}
733-
737+
734738
/// Decode an optional value for a given key, specified as a `CodingKey`. Throws an error if the
735739
/// specified key exists but is not able to be decoded as the inferred type.
736740
func decodeIfPresent<T: Decodable, K: CodingKey>(_ key: K, as type: T.Type = T.self) throws -> T? {

0 commit comments

Comments
 (0)