Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mono0926 committed Jan 24, 2025
1 parent e7f3080 commit 6a76cd1
Show file tree
Hide file tree
Showing 14 changed files with 1,432 additions and 1,285 deletions.
6 changes: 5 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ disabled_rules:
- force_try
- force_cast
- function_parameter_count
- blanket_disable_command
- opening_brace
- trailing_comma

included:
- Sources
- Tests

excluded:
- Tests/LicensePlistTests/XcodeProjects
- Tests/LicensePlistTests/Resources

line_length: 250
nesting:
Expand Down
2 changes: 1 addition & 1 deletion Sources/LicensePlistCore/Consts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct Consts {
public static let prefix = "com.mono0926.LicensePlist"
public static let outputPath = "\(prefix).Output"
public static let configPath = "license_plist.yml"
public static let version = "3.25.1"
public static let version = "3.26.0"
public static let encoding = String.Encoding.utf8
public static let licenseFileNames = ["LICENSE", "LICENSE.*"]
}
35 changes: 18 additions & 17 deletions Sources/LicensePlistCore/Entity/CocoaPods.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import Foundation
import APIKit
import Foundation
import LoggerAPI

public struct CocoaPods: Library {
public let name: String
public let nameSpecified: String?
public let version: String?
public var source: String? { "https://cocoapods.org/pods/\(name)" }
public let licenseType: LicenseType
public let name: String
public let nameSpecified: String?
public let version: String?
public var source: String? { "https://cocoapods.org/pods/\(name)" }
public let licenseType: LicenseType

public init(name: String, nameSpecified: String?, version: String?, licenseType: LicenseType = .unknown) {
self.name = name
self.nameSpecified = nameSpecified
self.version = version
self.licenseType = licenseType
}
public init(
name: String, nameSpecified: String?, version: String?, licenseType: LicenseType = .unknown
) {
self.name = name
self.nameSpecified = nameSpecified
self.version = version
self.licenseType = licenseType
}
}

extension CocoaPods {
public static func==(lhs: CocoaPods, rhs: CocoaPods) -> Bool {
return lhs.name == rhs.name &&
lhs.nameSpecified == rhs.nameSpecified &&
lhs.version == rhs.version
}
public static func == (lhs: CocoaPods, rhs: CocoaPods) -> Bool {
return lhs.name == rhs.name && lhs.nameSpecified == rhs.nameSpecified
&& lhs.version == rhs.version
}
}
89 changes: 47 additions & 42 deletions Sources/LicensePlistCore/Entity/CocoaPodsLicense.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,67 @@ import Foundation
import LoggerAPI

public struct CocoaPodsLicense: License, Equatable {
public let library: CocoaPods
public let body: String
public let library: CocoaPods
public let body: String

public static func==(lhs: CocoaPodsLicense, rhs: CocoaPodsLicense) -> Bool {
return lhs.library == rhs.library &&
lhs.body == rhs.body
}
public static func == (lhs: CocoaPodsLicense, rhs: CocoaPodsLicense) -> Bool {
return lhs.library == rhs.library && lhs.body == rhs.body
}
}

extension CocoaPodsLicense: CustomStringConvertible {
public var description: String {
return "name: \(library.name), nameSpecified: \(nameSpecified ?? "")\nbody: \(String(body.prefix(20)))\nversion: \(version ?? "")"
}
public var description: String {
return
"name: \(library.name), nameSpecified: \(nameSpecified ?? "")\nbody: \(String(body.prefix(20)))\nversion: \(version ?? "")"
}
}

extension CocoaPodsLicense {
public static func load(_ content: String, versionInfo: VersionInfo, config: Config) -> [CocoaPodsLicense] {
do {
let plistData = content.data(using: .utf8)!
let plistDecoder = PropertyListDecoder()

return try plistDecoder.decode(AcknowledgementsPlist.self, from: plistData).preferenceSpecifiers
.filter { $0.isLicense }
.map {
let name = $0.title
return CocoaPodsLicense(library: CocoaPods(name: name,
nameSpecified: config.renames[name],
version: versionInfo.version(name: $0.title),
licenseType: LicenseType(id: $0.license)),
body: $0.footerText)
}
} catch let e {
Log.error(String(describing: e))
return []
public static func load(_ content: String, versionInfo: VersionInfo, config: Config)
-> [CocoaPodsLicense]
{
do {
let plistData = content.data(using: .utf8)!
let plistDecoder = PropertyListDecoder()

return try plistDecoder.decode(AcknowledgementsPlist.self, from: plistData)
.preferenceSpecifiers
.filter { $0.isLicense }
.map {
let name = $0.title
return CocoaPodsLicense(
library: CocoaPods(
name: name,
nameSpecified: config.renames[name],
version: versionInfo.version(name: $0.title),
licenseType: LicenseType(id: $0.license)),
body: $0.footerText)
}
} catch let e {
Log.error(String(describing: e))
return []
}
}
}

private struct AcknowledgementsPlist: Decodable {
enum CodingKeys: String, CodingKey {
case preferenceSpecifiers = "PreferenceSpecifiers"
}
let preferenceSpecifiers: [PreferenceSpecifier]
enum CodingKeys: String, CodingKey {
case preferenceSpecifiers = "PreferenceSpecifiers"
}
let preferenceSpecifiers: [PreferenceSpecifier]
}

private struct PreferenceSpecifier: Decodable {
enum CodingKeys: String, CodingKey {
case footerText = "FooterText"
case title = "Title"
case type = "Type"
case license = "License"
}
enum CodingKeys: String, CodingKey {
case footerText = "FooterText"
case title = "Title"
case type = "Type"
case license = "License"
}

let footerText: String
let title: String
let type: String
let license: String?
var isLicense: Bool { return license != nil }
let footerText: String
let title: String
let type: String
let license: String?
var isLicense: Bool { return license != nil }
}
Loading

0 comments on commit 6a76cd1

Please sign in to comment.