Skip to content

Commit

Permalink
Fix strict lint voilations (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
devahmedshendy authored Jan 22, 2024
1 parent 0c20300 commit 50dd741
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Mintfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nicklockwood/SwiftFormat@0.47.0
realm/SwiftLint@0.41.0
peripheryapp/periphery@2.12.3
peripheryapp/periphery@2.18.0
4 changes: 2 additions & 2 deletions Sources/SyndiKit/Decoding/DecodingError.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Foundation

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

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

internal static func failedAttempts(_ errors: [String: DecodingError]) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Decoding/SynDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class SynDecoder {

return (source.source, type.anyDecoding(using: decoder))
}
return Dictionary(grouping: decodings, by: { $0.0 })
return Dictionary(grouping: decodings) { $0.0 }
.mapValues { $0
.map { $0.1 }
.map { (type(of: $0).label, $0) }
Expand Down
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Formats/Blogs/SiteCategory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct SiteCategory {
return nil
}
self.type = type
descriptors = Dictionary(grouping: languages, by: { $0.language })
descriptors = Dictionary(grouping: languages) { $0.language }
.compactMapValues { $0.first?.descriptor }
}
}
24 changes: 11 additions & 13 deletions Sources/SyndiKit/Formats/Blogs/SiteDirectory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public struct SiteCollectionDirectory: SiteDirectory {
public typealias CategorySequence =
Dictionary<SiteCategoryType, SiteCategory>.Values

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

fileprivate func sites(
internal 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>]

internal func sites(
withLanguage language: SiteLanguageType?,
withCategory category: SiteCategoryType?
) -> [Site] {
Expand Down Expand Up @@ -56,7 +56,7 @@ public struct SiteCollectionDirectory: SiteDirectory {
}

// swiftlint:disable function_body_length
fileprivate init(blogs: SiteCollection) {
internal init(blogs: SiteCollection) {
var categories = [CategoryLanguage]()
var languages = [SiteLanguage]()
var sites = [Site]()
Expand Down Expand Up @@ -90,10 +90,8 @@ public struct SiteCollectionDirectory: SiteDirectory {
languages.append(language)
}

categoryDictionary = Dictionary(
grouping: categories,
by: { $0.type }
).compactMapValues(SiteCategory.init)
categoryDictionary = Dictionary(grouping: categories) { $0.type }
.compactMapValues(SiteCategory.init)
languageDictionary = Dictionary(
uniqueKeysWithValues: languages.map { ($0.type, $0) }
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Foundation

// swiftlint:disable nesting
extension SiteLanguageCategory {
public struct Site: Codable {
public let title: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ extension PodcastChapters {

init?(mimeType: MimeType) {
switch mimeType {
case .json: self = .json
case .unknown: return nil
case .json:
self = .json

case .unknown:
return nil
}
}
}
Expand Down Expand Up @@ -47,7 +50,8 @@ extension PodcastChapters {

private init(knownMimeType: KnownMimeType) {
switch knownMimeType {
case .json: self = .json
case .json:
self = .json
}
}
}
Expand Down
60 changes: 45 additions & 15 deletions Sources/SyndiKit/Formats/Media/Podcast/PodcastPerson+Role.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,32 @@ extension PodcastPerson {
self.init(rawValue: caseInsensitive.lowercased())
}

// swiftlint:disable:next function_body_length cyclomatic_complexity
init?(role: Role) {
switch role {
case .guest: self = .guest
case .host: self = .host
case .editor: self = .editor
case .writer: self = .writer
case .designer: self = .designer
case .composer: self = .composer
case .producer: self = .producer
case .unknown: return nil
case .guest:
self = .guest

case .host:
self = .host

case .editor:
self = .editor

case .writer:
self = .writer

case .designer:
self = .designer

case .composer:
self = .composer

case .producer:
self = .producer

case .unknown:
return nil
}
}
}
Expand Down Expand Up @@ -63,15 +79,29 @@ extension PodcastPerson {
}
}

// swiftlint:disable:next cyclomatic_complexity
private init(knownRole: KnownRole) {
switch knownRole {
case .guest: self = .guest
case .host: self = .host
case .editor: self = .editor
case .writer: self = .writer
case .designer: self = .designer
case .composer: self = .composer
case .producer: self = .producer
case .guest:
self = .guest

case .host:
self = .host

case .editor:
self = .editor

case .writer:
self = .writer

case .designer:
self = .designer

case .composer:
self = .composer

case .producer:
self = .producer
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,26 @@ extension PodcastTranscript {

init?(mimeType: MimeType) {
switch mimeType {
case .plain: self = .plain
case .html: self = .html
case .srt: self = .srt
case .vtt: self = .vtt
case .json: self = .json
case .subrip: self = .subrip
case .unknown: return nil
case .plain:
self = .plain

case .html:
self = .html

case .srt:
self = .srt

case .vtt:
self = .vtt

case .json:
self = .json

case .subrip:
self = .subrip

case .unknown:
return nil
}
}
}
Expand Down Expand Up @@ -62,12 +75,23 @@ extension PodcastTranscript {

private init(knownMimeType: KnownMimeType) {
switch knownMimeType {
case .plain: self = .plain
case .html: self = .html
case .srt: self = .srt
case .vtt: self = .vtt
case .json: self = .json
case .subrip: self = .subrip
case .plain:
self = .plain

case .html:
self = .html

case .srt:
self = .srt

case .vtt:
self = .vtt

case .json:
self = .json

case .subrip:
self = .subrip
}
}
}
Expand Down
37 changes: 17 additions & 20 deletions Sources/SyndiKit/Formats/Media/Wordpress/WordPressPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ public enum WordPressError: Error, Equatable {
case missingField(WordPressPost.Field)
}

extension Entryable {
public var wpPost: WordPressPost? {
guard let rssItem = self as? RSSItem else {
return nil
}

return try? WordPressPost(item: rssItem)
}
}

public struct WordPressPost {
public typealias PostType = String
public typealias CommentStatus = String
Expand Down Expand Up @@ -61,7 +51,7 @@ public struct WordPressPost {
public let pingStatus: PingStatus
public let parentID: Int?
public let menuOrder: Int?
public let id: Int
public let ID: Int
public let isSticky: Bool
public let postDate: Date
public let postDateGMT: Date?
Expand Down Expand Up @@ -108,7 +98,7 @@ public struct WordPressPost {
self.pingStatus = pingStatus
self.parentID = parentID
self.menuOrder = menuOrder
self.id = id
self.ID = id
self.isSticky = isSticky
self.postDate = postDate
self.postDateGMT = postDateGMT
Expand Down Expand Up @@ -184,17 +174,14 @@ extension WordPressPost {
self.body = body.value
tags = categoryDictionary["post_tag", default: []].map { $0.value }
categories = categoryDictionary["category", default: []].map { $0.value }
self.meta = Dictionary(grouping: meta, by: {
$0.key.value
}).compactMapValues {
$0.last?.value.value
}
self.meta = Dictionary(grouping: meta) { $0.key.value }
.compactMapValues { $0.last?.value.value }
self.status = status.value
self.commentStatus = commentStatus.value
self.pingStatus = pingStatus.value
self.parentID = parentID
self.menuOrder = menuOrder
self.id = id
self.ID = id
self.isSticky = (isSticky != 0)
self.postDate = postDate
postDateGMT = item.wpPostDateGMT
Expand All @@ -205,10 +192,20 @@ extension WordPressPost {

extension WordPressPost: Hashable {
public static func == (lhs: WordPressPost, rhs: WordPressPost) -> Bool {
lhs.id == rhs.id
lhs.ID == rhs.ID
}

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(ID)
}
}

extension Entryable {
public var wpPost: WordPressPost? {
guard let rssItem = self as? RSSItem else {
return nil
}

return try? WordPressPost(item: rssItem)
}
}

0 comments on commit 50dd741

Please sign in to comment.