Skip to content

Commit

Permalink
working on linting
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Jan 3, 2024
1 parent 7683701 commit ca03f5f
Show file tree
Hide file tree
Showing 65 changed files with 430 additions and 415 deletions.
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
--header strip
--commas inline
--disable wrapMultilineStatementBraces
--extensionacl on-extension
--extensionacl on-declarations
--decimalgrouping 3,4
--exclude .build, DerivedData
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// swift-tools-version:5.5
// swiftlint:disable explicit_top_level_acl
// swiftlint:disable explicit_top_level_acl explicit_acl
import PackageDescription

let package = Package(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Character.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

extension Character {
func asOsmType() -> PodcastLocation.OsmQuery.OsmType? {
internal func asOsmType() -> PodcastLocation.OsmQuery.OsmType? {
.init(rawValue: String(self))
}
}
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Collection.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

extension Collection {
subscript(safe index: Index) -> Element? {
internal subscript(safe index: Index) -> Element? {
indices.contains(index) ? self[index] : nil
}
}
12 changes: 6 additions & 6 deletions Sources/SyndiKit/Common/Author.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import Foundation

/// a person, corporation, or similar entity.
public struct Author: Codable, Equatable {
init(name: String) {
self.name = name
email = nil
uri = nil
}

/// Conveys a human-readable name for the person.
public let name: String

Expand All @@ -16,4 +10,10 @@ public struct Author: Codable, Equatable {

/// Contains a home page for the person.
public let uri: URL?

internal init(name: String) {
self.name = name
email = nil
uri = nil
}
}
11 changes: 5 additions & 6 deletions Sources/SyndiKit/Common/Primitives/CData.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/// #CDATA XML element.
public typealias StringLiteralType = String
public struct CData: Codable, ExpressibleByStringLiteral, Equatable {
public typealias StringLiteralType = String

public init(stringLiteral value: String) {
self.value = value
public enum CodingKeys: String, CodingKey {
case value = "#CDATA"
}

public var description: String {
Expand All @@ -13,8 +12,8 @@ public struct CData: Codable, ExpressibleByStringLiteral, Equatable {
/// String value of the #CDATA element.
public let value: String

enum CodingKeys: String, CodingKey {
case value = "#CDATA"
public init(stringLiteral value: String) {
self.value = value
}

public init(from decoder: Decoder) throws {
Expand Down
8 changes: 4 additions & 4 deletions Sources/SyndiKit/Common/Primitives/XMLStringInt.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/// XML Element which contains a `String` parsable into a `Integer`.
public struct XMLStringInt: Codable, ExpressibleByIntegerLiteral {
public init(integerLiteral value: Int) {
self.value = value
}

public typealias IntegerLiteralType = Int

/// The underlying `Int` value.
public let value: Int

public init(integerLiteral value: Int) {
self.value = value
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let stringValue = try container.decode(String.self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Decoding/AnyDecoding.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

protocol AnyDecoding {
internal protocol AnyDecoding {
static var label: String { get }
func decodeFeed(data: Data) throws -> Feedable
}
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Decoding/CustomDecoderSetup.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation

protocol CustomDecoderSetup {
internal protocol CustomDecoderSetup {
func setup(decoder: TypeDecoder)
}
20 changes: 10 additions & 10 deletions Sources/SyndiKit/Decoding/DateFormatterDecoder.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import Foundation

struct DateFormatterDecoder {
let formatters: [DateFormatter]

public enum RSS {
static let dateFormatStrings = [
internal struct DateFormatterDecoder {
internal enum RSS {
private static let dateFormatStrings = [
"yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX",
"yyyy-MM-dd'T'HH:mm:ssXXXXX",
"E, d MMM yyyy HH:mm:ss zzz",
"yyyy-MM-dd HH:mm:ss"
]

public static let decoder = DateFormatterDecoder(
internal static let decoder = DateFormatterDecoder(
basedOnFormats: Self.dateFormatStrings
)
}

private let formatters: [DateFormatter]

internal init(formatters: [DateFormatter]) {
self.formatters = formatters
}

static func isoPOSIX(withFormat dateFormat: String) -> DateFormatter {
private static func isoPOSIX(withFormat dateFormat: String) -> DateFormatter {
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .iso8601)
formatter.locale = Locale(identifier: "en_US_POSIX")
Expand All @@ -29,11 +29,11 @@ struct DateFormatterDecoder {
return formatter
}

init(basedOnFormats formats: [String]) {
internal init(basedOnFormats formats: [String]) {
formatters = formats.map(Self.isoPOSIX(withFormat:))
}

public func decodeString(_ dateStr: String) -> Date? {
internal func decodeString(_ dateStr: String) -> Date? {
for formatter in formatters {
if let date = formatter.date(from: dateStr) {
return date
Expand All @@ -42,7 +42,7 @@ struct DateFormatterDecoder {
return nil
}

func decode(from decoder: Decoder) throws -> Date {
internal func decode(from decoder: Decoder) throws -> Date {
let container = try decoder.singleValueContainer()
let dateStr = try container.decode(String.self)

Expand Down
6 changes: 3 additions & 3 deletions Sources/SyndiKit/Decoding/DecodableFeed.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Foundation

protocol DecodableFeed: Decodable, Feedable {
internal protocol DecodableFeed: Decodable, Feedable {
static var source: DecoderSetup { get }
static var label: String { get }
}

extension DecodableFeed {
static func decoding(using decoder: TypeDecoder) -> Decoding<Self> {
internal static func decoding(using decoder: TypeDecoder) -> Decoding<Self> {
Decoding(for: Self.self, using: decoder)
}

static func anyDecoding(using decoder: TypeDecoder) -> AnyDecoding {
internal static func anyDecoding(using decoder: TypeDecoder) -> AnyDecoding {
Self.decoding(using: decoder)
}
}
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Decoding/DecoderSetup.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation

protocol DecoderSetup {
internal protocol DecoderSetup {
var source: DecoderSource { get }
}
4 changes: 2 additions & 2 deletions Sources/SyndiKit/Decoding/DecoderSource.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

enum DecoderSource: UInt8, DecoderSetup {
internal enum DecoderSource: UInt8, DecoderSetup {
case json = 0x007B
case xml = 0x003C

public var source: DecoderSource {
internal var source: DecoderSource {
self
}
}
18 changes: 9 additions & 9 deletions Sources/SyndiKit/Decoding/Decoding.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import Foundation

struct Decoding<DecodingType: DecodableFeed>: AnyDecoding {
func decodeFeed(data: Data) throws -> Feedable {
try decode(data: data)
internal struct Decoding<DecodingType: DecodableFeed>: AnyDecoding {
internal static var label: String {
DecodingType.label
}

let decoder: TypeDecoder
internal let decoder: TypeDecoder

init(for _: DecodingType.Type, using decoder: TypeDecoder) {
internal init(for _: DecodingType.Type, using decoder: TypeDecoder) {
self.decoder = decoder
}

func decode(data: Data) throws -> DecodingType {
try decoder.decode(DecodingType.self, from: data)
internal func decodeFeed(data: Data) throws -> Feedable {
try decode(data: data)
}

static var label: String {
DecodingType.label
internal func decode(data: Data) throws -> DecodingType {
try decoder.decode(DecodingType.self, from: data)
}
}
6 changes: 3 additions & 3 deletions Sources/SyndiKit/Decoding/DecodingError.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import Foundation

extension DecodingError {
struct Dictionary: Error {
private struct Dictionary: Error {
internal init?(errors: [String: DecodingError]) {
guard errors.count > 1 else {
return nil
}
self.errors = errors
}

let errors: [String: DecodingError]
private let errors: [String: DecodingError]
}

static func failedAttempts(_ errors: [String: DecodingError]) -> Self {
internal static func failedAttempts(_ errors: [String: DecodingError]) -> Self {
let context = DecodingError.Context(
codingPath: [],
debugDescription: "Failed to decode data with several decoders.",
Expand Down
20 changes: 10 additions & 10 deletions Sources/SyndiKit/Decoding/SynDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import XMLCoder
///
/// - ``decode(_:)``
public class SynDecoder {
static func setupJSONDecoder(_ decoder: JSONDecoder) {
internal static func setupJSONDecoder(_ decoder: JSONDecoder) {
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .custom(DateFormatterDecoder.RSS.decoder.decode(from:))
}

static func setupXMLDecoder(_ decoder: XMLDecoder) {
internal static func setupXMLDecoder(_ decoder: XMLDecoder) {
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .custom(DateFormatterDecoder.RSS.decoder.decode(from:))
decoder.trimValueWhitespaces = false
}

init(
internal init(
types: [DecodableFeed.Type]? = nil,
defaultJSONDecoderSetup: ((JSONDecoder) -> Void)? = nil,
defaultXMLDecoderSetup: ((XMLDecoder) -> Void)? = nil
Expand All @@ -38,29 +38,29 @@ public class SynDecoder {
self.init(types: nil, defaultJSONDecoderSetup: nil, defaultXMLDecoderSetup: nil)
}

let defaultJSONDecoderSetup: (JSONDecoder) -> Void
let defaultXMLDecoderSetup: (XMLDecoder) -> Void
let types: [DecodableFeed.Type]
private let defaultJSONDecoderSetup: (JSONDecoder) -> Void
private let defaultXMLDecoderSetup: (XMLDecoder) -> Void
private let types: [DecodableFeed.Type]

static let defaultTypes: [DecodableFeed.Type] = [
private static let defaultTypes: [DecodableFeed.Type] = [
RSSFeed.self,
AtomFeed.self,
JSONFeed.self
]

lazy var defaultXMLDecoder: XMLDecoder = {
private lazy var defaultXMLDecoder: XMLDecoder = {
let decoder = XMLDecoder()
self.defaultXMLDecoderSetup(decoder)
return decoder
}()

lazy var defaultJSONDecoder: JSONDecoder = {
private lazy var defaultJSONDecoder: JSONDecoder = {
let decoder = JSONDecoder()
self.defaultJSONDecoderSetup(decoder)
return decoder
}()

lazy var decodings: [DecoderSource: [String: AnyDecoding]] = {
private lazy var decodings: [DecoderSource: [String: AnyDecoding]] = {
let decodings = types.map { type -> (DecoderSource, AnyDecoding) in
let source = type.source
let setup = type.source as? CustomDecoderSetup
Expand Down
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Decoding/TypeDecoder.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import XMLCoder

protocol TypeDecoder {
internal protocol TypeDecoder {
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T: DecodableFeed
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Dictionary.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extension Dictionary {
mutating func formUnion<SequenceType: Sequence, ElementType>(
internal mutating func formUnion<SequenceType: Sequence, ElementType>(
_ collection: SequenceType,
key: Key
) where Value == Set<ElementType>, SequenceType.Element == ElementType {
Expand Down
22 changes: 11 additions & 11 deletions Sources/SyndiKit/Formats/Blogs/SiteDirectory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public protocol SiteDirectory {
var categories: CategorySequence { get }
}

public extension SiteDirectory {
func sites(
extension SiteDirectory {
public func sites(
withLanguage language: SiteLanguageType? = nil,
withCategory category: SiteCategoryType? = nil
) -> SiteSequence {
Expand All @@ -35,7 +35,7 @@ public struct SiteCollectionDirectory: SiteDirectory {
public typealias CategorySequence =
Dictionary<SiteCategoryType, SiteCategory>.Values

let instance: Instance
private let instance: Instance

public var languages: Dictionary<
SiteLanguageType, SiteLanguage
Expand All @@ -56,16 +56,16 @@ public struct SiteCollectionDirectory: SiteDirectory {
instance.sites(withLanguage: language, withCategory: category)
}

init(blogs: SiteCollection) {
internal init(blogs: SiteCollection) {
instance = .init(blogs: blogs)
}

struct Instance {
let allSites: [Site]
let languageDictionary: [SiteLanguageType: SiteLanguage]
let categoryDictionary: [SiteCategoryType: SiteCategory]
let languageIndicies: [SiteLanguageType: Set<Int>]
let categoryIndicies: [SiteCategoryType: Set<Int>]
private struct Instance {
internal let allSites: [Site]
internal let languageDictionary: [SiteLanguageType: SiteLanguage]
internal let categoryDictionary: [SiteCategoryType: SiteCategory]
internal let languageIndicies: [SiteLanguageType: Set<Int>]
internal let categoryIndicies: [SiteCategoryType: Set<Int>]

public func sites(
withLanguage language: SiteLanguageType?,
Expand Down Expand Up @@ -107,7 +107,7 @@ public struct SiteCollectionDirectory: SiteDirectory {
}

// swiftlint:disable function_body_length
init(blogs: SiteCollection) {
internal init(blogs: SiteCollection) {
var categories = [CategoryLanguage]()
var languages = [SiteLanguage]()
var sites = [Site]()
Expand Down
Loading

0 comments on commit ca03f5f

Please sign in to comment.