Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix strict lint voilations #67

Merged
merged 7 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
58 changes: 43 additions & 15 deletions Sources/SyndiKit/Formats/Media/Podcast/PodcastPerson+Role.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,29 @@ extension PodcastPerson {

init?(role: Role) {
devahmedshendy marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -65,13 +80,26 @@ extension PodcastPerson {

private init(knownRole: KnownRole) {
devahmedshendy marked this conversation as resolved.
Show resolved Hide resolved
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
27 changes: 12 additions & 15 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 @@ -184,11 +174,8 @@ 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
Expand All @@ -212,3 +199,13 @@ extension WordPressPost: Hashable {
hasher.combine(id)
}
}

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

return try? WordPressPost(item: rssItem)
}
}
6 changes: 3 additions & 3 deletions Tests/SyndiKitTests/WordpressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ final class WordpressTests: XCTestCase {
XCTAssertEqual(post.parentID, wpPostParent)
XCTAssertEqual(post.menuOrder, wpMenuOrder)
XCTAssertEqual(post.isSticky, wpIsSticky != 0)
XCTAssertEqual(post.ID, wpPostID)
XCTAssertEqual(post.id, wpPostID)
XCTAssertEqual(post.postDate, wpPostDate)
XCTAssertEqual(post.modifiedDate, wpModifiedDate)
XCTAssertEqual(post.name, wpPostName)
Expand Down Expand Up @@ -229,7 +229,7 @@ final class WordpressTests: XCTestCase {
XCTAssertEqual(post.parentID, wpPostParent)
XCTAssertEqual(post.menuOrder, wpMenuOrder)
XCTAssertEqual(post.isSticky, wpIsSticky != 0)
XCTAssertEqual(post.ID, wpPostID)
XCTAssertEqual(post.id, wpPostID)
XCTAssertEqual(post.postDate, wpPostDate)
XCTAssertEqual(post.modifiedDate, wpModifiedDate)
XCTAssertEqual(post.name, wpPostName)
Expand Down Expand Up @@ -312,7 +312,7 @@ final class WordpressTests: XCTestCase {
XCTAssertEqual(post.parentID, wpPostParent)
XCTAssertEqual(post.menuOrder, wpMenuOrder)
XCTAssertEqual(post.isSticky, wpIsSticky != 0)
XCTAssertEqual(post.ID, wpPostID)
XCTAssertEqual(post.id, wpPostID)
XCTAssertEqual(post.postDate, wpPostDate)
XCTAssertEqual(post.modifiedDate, wpModifiedDate)
XCTAssertEqual(post.name, wpPostName)
Expand Down
Loading