Fix lint issues.

This commit is contained in:
Brent Simmons
2025-01-22 22:13:20 -08:00
parent d210692d7d
commit 72a5e46dcc
115 changed files with 584 additions and 711 deletions

View File

@@ -36,7 +36,7 @@ public enum FeedType: Sendable {
return .unknown
}
let cCharPointer = baseAddress.assumingMemoryBound(to: CChar.self)
if isProbablyJSON(cCharPointer, count) {
if isPartialData {

View File

@@ -160,7 +160,7 @@ private extension JSONFeedParser {
let dateModified = parseDate(itemDictionary[Key.dateModified] as? String)
let authors = parseAuthors(itemDictionary)
var tags: Set<String>? = nil
var tags: Set<String>?
if let tagsArray = itemDictionary[Key.tags] as? [String] {
tags = Set(tagsArray)
}

View File

@@ -53,8 +53,7 @@ public struct RSSInJSONParser {
return ParsedFeed(type: .rssInJSON, title: title, homePageURL: homePageURL, feedURL: feedURL, language: feedLanguage, feedDescription: feedDescription, nextURL: nil, iconURL: nil, faviconURL: nil, authors: nil, expired: false, hubs: nil, items: items)
}
catch { throw error }
} catch { throw error }
}
}
@@ -62,7 +61,7 @@ private extension RSSInJSONParser {
static func parseItems(_ itemsObject: JSONArray, _ feedURL: String) -> Set<ParsedItem> {
return Set(itemsObject.compactMap{ (oneItemDictionary) -> ParsedItem? in
return Set(itemsObject.compactMap { (oneItemDictionary) -> ParsedItem? in
return parsedItemWithDictionary(oneItemDictionary, feedURL)
})
@@ -74,7 +73,7 @@ private extension RSSInJSONParser {
let title = itemDictionary["title"] as? String
var contentHTML = itemDictionary["description"] as? String
var contentText: String? = nil
var contentText: String?
if contentHTML != nil && !(contentHTML!.contains("<")) {
contentText = contentHTML
contentHTML = nil
@@ -83,7 +82,7 @@ private extension RSSInJSONParser {
return nil
}
var datePublished: Date? = nil
var datePublished: Date?
if let datePublishedString = itemDictionary["pubDate"] as? String {
datePublished = DateParser.date(string: datePublishedString)
}
@@ -150,9 +149,8 @@ private extension RSSInJSONParser {
return Set([oneTag])
}
return nil
}
else if let categoryArray = itemDictionary["category"] as? JSONArray {
return Set(categoryArray.compactMap{ $0["#value"] as? String })
} else if let categoryArray = itemDictionary["category"] as? JSONArray {
return Set(categoryArray.compactMap { $0["#value"] as? String })
}
return nil
}

View File

@@ -20,7 +20,7 @@ public final class ParsedAttachment: Hashable, Sendable {
if url.isEmpty {
return nil
}
self.url = url
self.mimeType = mimeType
self.title = title

View File

@@ -14,7 +14,7 @@ public final class ParsedAuthor: Hashable, Codable, Sendable {
public let url: String?
public let avatarURL: String?
public let emailAddress: String?
public init(name: String?, url: String?, avatarURL: String?, emailAddress: String?) {
self.name = name
self.url = url
@@ -39,17 +39,13 @@ public final class ParsedAuthor: Hashable, Codable, Sendable {
public func hash(into hasher: inout Hasher) {
if let name {
hasher.combine(name)
}
else if let url {
} else if let url {
hasher.combine(url)
}
else if let emailAddress {
} else if let emailAddress {
hasher.combine(emailAddress)
}
else if let avatarURL{
} else if let avatarURL {
hasher.combine(avatarURL)
}
else {
} else {
hasher.combine("")
}
}

View File

@@ -17,7 +17,7 @@ public final class ParsedHub: Hashable, Sendable {
self.type = type
self.url = url
}
// MARK: - Hashable
public func hash(into hasher: inout Hasher) {

View File

@@ -10,8 +10,8 @@ import Foundation
public final class ParsedItem: Hashable, Sendable {
public let syncServiceID: String? //Nil when not syncing
public let uniqueID: String //RSS guid, for instance; may be calculated
public let syncServiceID: String? // Nil when not syncing
public let uniqueID: String // RSS guid, for instance; may be calculated
public let feedURL: String
public let url: String?
public let externalURL: String?
@@ -27,12 +27,12 @@ public final class ParsedItem: Hashable, Sendable {
public let authors: Set<ParsedAuthor>?
public let tags: Set<String>?
public let attachments: Set<ParsedAttachment>?
public init(syncServiceID: String?, uniqueID: String, feedURL: String, url: String?, externalURL: String?, title: String?,
language: String?, contentHTML: String?, contentText: String?, summary: String?, imageURL: String?,
bannerImageURL: String?,datePublished: Date?, dateModified: Date?, authors: Set<ParsedAuthor>?,
bannerImageURL: String?, datePublished: Date?, dateModified: Date?, authors: Set<ParsedAuthor>?,
tags: Set<String>?, attachments: Set<ParsedAttachment>?) {
self.syncServiceID = syncServiceID
self.uniqueID = uniqueID
self.feedURL = feedURL
@@ -57,8 +57,7 @@ public final class ParsedItem: Hashable, Sendable {
public func hash(into hasher: inout Hasher) {
if let syncServiceID = syncServiceID {
hasher.combine(syncServiceID)
}
else {
} else {
hasher.combine(uniqueID)
hasher.combine(feedURL)
}
@@ -69,4 +68,3 @@ public final class ParsedItem: Hashable, Sendable {
lhs.syncServiceID == rhs.syncServiceID && lhs.uniqueID == rhs.uniqueID && lhs.feedURL == rhs.feedURL && lhs.url == rhs.url && lhs.externalURL == rhs.externalURL && lhs.title == rhs.title && lhs.language == rhs.language && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.summary == rhs.summary && lhs.imageURL == rhs.imageURL && lhs.bannerImageURL == rhs.bannerImageURL && lhs.datePublished == rhs.datePublished && lhs.dateModified == rhs.dateModified && lhs.authors == rhs.authors && lhs.tags == rhs.tags && lhs.attachments == rhs.attachments
}
}

View File

@@ -181,29 +181,17 @@ private extension AtomParser {
if SAXEqualTags(localName, XMLName.id) {
currentArticle.guid = currentString(saxParser)
}
else if SAXEqualTags(localName, XMLName.title) {
} else if SAXEqualTags(localName, XMLName.title) {
currentArticle.title = currentString(saxParser)
}
else if SAXEqualTags(localName, XMLName.content) {
} else if SAXEqualTags(localName, XMLName.content) {
addContent(saxParser, currentArticle)
}
else if SAXEqualTags(localName, XMLName.summary) {
} else if SAXEqualTags(localName, XMLName.summary) {
addSummary(saxParser, currentArticle)
}
else if SAXEqualTags(localName, XMLName.link) {
} else if SAXEqualTags(localName, XMLName.link) {
addLink(currentArticle)
}
else if SAXEqualTags(localName, XMLName.published) {
} else if SAXEqualTags(localName, XMLName.published) {
currentArticle.datePublished = currentDate(saxParser)
}
else if SAXEqualTags(localName, XMLName.updated) {
} else if SAXEqualTags(localName, XMLName.updated) {
currentArticle.dateModified = currentDate(saxParser)
}
@@ -212,8 +200,7 @@ private extension AtomParser {
if currentArticle.datePublished == nil {
currentArticle.datePublished = currentDate(saxParser)
}
}
else if SAXEqualTags(localName, XMLName.modified) {
} else if SAXEqualTags(localName, XMLName.modified) {
if currentArticle.dateModified == nil {
currentArticle.dateModified = currentDate(saxParser)
}
@@ -258,13 +245,11 @@ private extension AtomParser {
if article.link == nil {
article.link = resolvedURLString
}
}
else if rel == AttributeValue.alternate {
} else if rel == AttributeValue.alternate {
if article.permalink == nil {
article.permalink = resolvedURLString
}
}
else if rel == AttributeValue.enclosure {
} else if rel == AttributeValue.enclosure {
if let enclosure = enclosure(resolvedURLString, attributes) {
article.addEnclosure(enclosure)
}
@@ -372,7 +357,7 @@ extension AtomParser: SAXParserDelegate {
currentArticle?.language = xmlAttributes["xml:lang"]
}
let contentType = xmlAttributes["type"];
let contentType = xmlAttributes["type"]
if contentType == "xhtml" {
parsingXHTML = true
xhtmlString = ""
@@ -416,9 +401,7 @@ extension AtomParser: SAXParserDelegate {
if isContentTag {
currentArticle?.body = xhtmlString
}
else if isSummaryTag {
} else if isSummaryTag {
if (currentArticle?.body?.count ?? 0) < 1 {
currentArticle?.body = xhtmlString
}
@@ -438,9 +421,7 @@ extension AtomParser: SAXParserDelegate {
} else {
assertionFailure("xhtmlString must not be nil when parsingXHTML in xmlEndElement.")
}
}
else if parsingAuthor {
} else if parsingAuthor {
if SAXEqualTags(localName, XMLName.author) {
parsingAuthor = false
@@ -448,32 +429,21 @@ extension AtomParser: SAXParserDelegate {
currentArticle?.addAuthor(currentAuthor)
}
currentAuthor = nil
}
else if SAXEqualTags(localName, XMLName.name) {
} else if SAXEqualTags(localName, XMLName.name) {
currentAuthor?.name = saxParser.currentStringWithTrimmedWhitespace
}
else if SAXEqualTags(localName, XMLName.email) {
} else if SAXEqualTags(localName, XMLName.email) {
currentAuthor?.emailAddress = saxParser.currentStringWithTrimmedWhitespace
}
else if SAXEqualTags(localName, XMLName.uri) {
} else if SAXEqualTags(localName, XMLName.uri) {
currentAuthor?.url = saxParser.currentStringWithTrimmedWhitespace
}
}
else if SAXEqualTags(localName, XMLName.entry) {
} else if SAXEqualTags(localName, XMLName.entry) {
parsingArticle = false
entryDepth = -1
}
else if parsingArticle && !parsingSource && depth == entryDepth + 1 {
} else if parsingArticle && !parsingSource && depth == entryDepth + 1 {
addArticleElement(saxParser, localName, prefix)
}
else if SAXEqualTags(localName, XMLName.source) {
} else if SAXEqualTags(localName, XMLName.source) {
parsingSource = false
}
else if !parsingArticle && !parsingSource && SAXEqualTags(localName, XMLName.title) {
} else if !parsingArticle && !parsingSource && SAXEqualTags(localName, XMLName.title) {
addFeedTitle(saxParser)
}

View File

@@ -6,7 +6,7 @@
//
import Foundation
//import FoundationExtras
// import FoundationExtras
final class RSSArticle {
@@ -81,28 +81,21 @@ private extension RSSArticle {
if let permalink, !permalink.isEmpty, let datePublishedTimeStampString {
s.append(permalink)
s.append(datePublishedTimeStampString)
}
else if let link, !link.isEmpty, let datePublishedTimeStampString {
} else if let link, !link.isEmpty, let datePublishedTimeStampString {
s.append(link)
s.append(datePublishedTimeStampString)
}
else if let title, !title.isEmpty, let datePublishedTimeStampString {
} else if let title, !title.isEmpty, let datePublishedTimeStampString {
s.append(title)
s.append(datePublishedTimeStampString)
}
else if let datePublishedTimeStampString {
} else if let datePublishedTimeStampString {
s.append(datePublishedTimeStampString)
}
else if let permalink, !permalink.isEmpty {
} else if let permalink, !permalink.isEmpty {
s.append(permalink)
}
else if let link, !link.isEmpty {
} else if let link, !link.isEmpty {
s.append(link)
}
else if let title, !title.isEmpty {
} else if let title, !title.isEmpty {
s.append(title)
}
else if let body, !body.isEmpty {
} else if let body, !body.isEmpty {
s.append(body)
}

View File

@@ -20,7 +20,7 @@ final class RSSAuthor {
self.avatarURL = avatarURL
self.emailAddress = emailAddress
}
/// Use when the actual property is unknown. Guess based on contents of the string. (This is common with RSS.)
convenience init(singleString: String) {

View File

@@ -79,11 +79,9 @@ private extension RSSParser {
if feed.link == nil {
feed.link = saxParser.currentString
}
}
else if SAXEqualTags(localName, XMLName.title) {
} else if SAXEqualTags(localName, XMLName.title) {
feed.title = saxParser.currentString
}
else if SAXEqualTags(localName, XMLName.language) {
} else if SAXEqualTags(localName, XMLName.language) {
feed.language = saxParser.currentString
}
}
@@ -118,26 +116,20 @@ private extension RSSParser {
if let currentString = saxParser.currentString {
if SAXEqualTags(localName, XMLName.guid) {
addGuid(currentString, currentArticle)
}
else if SAXEqualTags(localName, XMLName.author) {
} else if SAXEqualTags(localName, XMLName.author) {
addAuthorWithString(currentString, currentArticle)
}
else if SAXEqualTags(localName, XMLName.link) {
} else if SAXEqualTags(localName, XMLName.link) {
currentArticle.link = urlString(currentString)
}
else if SAXEqualTags(localName, XMLName.description) {
} else if SAXEqualTags(localName, XMLName.description) {
if currentArticle.body == nil {
currentArticle.body = currentString
}
}
else if !parsingAuthor && SAXEqualTags(localName, XMLName.title) {
} else if !parsingAuthor && SAXEqualTags(localName, XMLName.title) {
currentArticle.title = currentString
}
else if SAXEqualTags(localName, XMLName.pubDate) {
} else if SAXEqualTags(localName, XMLName.pubDate) {
currentArticle.datePublished = currentDate(saxParser)
}
}
else if SAXEqualTags(localName, XMLName.enclosure), let currentAttributes {
} else if SAXEqualTags(localName, XMLName.enclosure), let currentAttributes {
addEnclosure(currentAttributes, currentArticle)
}
}
@@ -148,8 +140,7 @@ private extension RSSParser {
if let currentString = saxParser.currentString {
addAuthorWithString(currentString, currentArticle)
}
}
else if SAXEqualTags(localName, XMLName.date) {
} else if SAXEqualTags(localName, XMLName.date) {
currentArticle.datePublished = currentDate(saxParser)
}
}
@@ -298,7 +289,7 @@ extension RSSParser: SAXParserDelegate {
return
}
var xmlAttributes: StringDictionary? = nil
var xmlAttributes: StringDictionary?
if (isRDF && SAXEqualTags(localName, XMLName.item)) || SAXEqualTags(localName, XMLName.guid) || SAXEqualTags(localName, XMLName.enclosure) {
xmlAttributes = saxParser.attributesDictionary(attributes, attributeCount: attributeCount)
}
@@ -314,11 +305,9 @@ extension RSSParser: SAXParserDelegate {
currentArticle.guid = rdfGuid
currentArticle.permalink = rdfGuid
}
}
else if prefix == nil && SAXEqualTags(localName, XMLName.image) {
} else if prefix == nil && SAXEqualTags(localName, XMLName.image) {
parsingChannelImage = true
}
else if prefix == nil && SAXEqualTags(localName, XMLName.author) {
} else if prefix == nil && SAXEqualTags(localName, XMLName.author) {
if parsingArticle {
parsingAuthor = true
}
@@ -337,23 +326,18 @@ extension RSSParser: SAXParserDelegate {
if isRDF && SAXEqualTags(localName, XMLName.uppercaseRDF) {
endRSSFound = true
}
else if SAXEqualTags(localName, XMLName.rss) {
} else if SAXEqualTags(localName, XMLName.rss) {
endRSSFound = true
}
else if SAXEqualTags(localName, XMLName.image) {
} else if SAXEqualTags(localName, XMLName.image) {
parsingChannelImage = false
}
else if SAXEqualTags(localName, XMLName.item) {
} else if SAXEqualTags(localName, XMLName.item) {
parsingArticle = false
}
else if parsingArticle {
} else if parsingArticle {
addArticleElement(saxParser, localName, prefix)
if SAXEqualTags(localName, XMLName.author) {
parsingAuthor = false
}
}
else if !parsingChannelImage {
} else if !parsingChannelImage {
addFeedElement(saxParser, localName, prefix)
}
}
@@ -363,4 +347,3 @@ extension RSSParser: SAXParserDelegate {
// Required method.
}
}

View File

@@ -70,7 +70,7 @@ private func decodedEntities(_ sourceBuffer: UnsafeBufferPointer<UInt8>, _ didDe
resultBuffer.initializeMemory(as: UInt8.self, repeating: 0, count: resultBufferByteCount)
let result = resultBuffer.assumingMemoryBound(to: UInt8.self)
var sourceLocation = 0
var resultLocation = 0
@@ -78,7 +78,7 @@ private func decodedEntities(_ sourceBuffer: UnsafeBufferPointer<UInt8>, _ didDe
let ch = sourceBuffer[sourceLocation]
var decodedEntity: String? = nil
var decodedEntity: String?
if ch == ampersandCharacter {
decodedEntity = decodedEntityValue(sourceBuffer, byteCount, &sourceLocation)
@@ -112,7 +112,7 @@ private func addDecodedEntity(_ decodedEntity: String, _ result: UnsafeMutablePo
}
}
private func decodedEntityValue(_ buffer: UnsafeBufferPointer<UInt8>, _ byteCount: Int, _ sourceLocation: inout Int) -> /*[UInt8]?*/ String? {
private func decodedEntityValue(_ buffer: UnsafeBufferPointer<UInt8>, _ byteCount: Int, _ sourceLocation: inout Int) -> String? {
guard let rawEntity = rawEntityValue(buffer, byteCount, &sourceLocation) else {
return nil
@@ -153,8 +153,7 @@ private func decodedNumericEntity(_ rawEntity: ContiguousArray<UInt8>) -> String
if rawEntity[1] == xCharacter || rawEntity[1] == XCharacter { // Hex?
decodedNumber = decodedHexEntity(rawEntity)
}
else {
} else {
decodedNumber = decodedDecimalEntity(rawEntity)
}
@@ -247,7 +246,7 @@ private func decodedDecimalEntity(_ rawEntity: ContiguousArray<UInt8>) -> UInt32
if number == 0 {
return nil
}
return number
}
@@ -271,7 +270,7 @@ private func rawEntityValue(_ buffer: UnsafeBufferPointer<UInt8>, _ byteCount: I
while true {
sourceLocation += 1
if sourceLocation >= byteCount || entityCharactersIndex >= maxEntityCharacters { // did not parse entity
if sourceLocation >= byteCount || entityCharactersIndex >= maxEntityCharacters { // did not parse entity
sourceLocation = savedSourceLocation
return nil
}

View File

@@ -28,8 +28,7 @@ public final class HTMLMetadata: Sendable {
self.appleTouchIcons = appleTouchIconTags.map { htmlTag in
HTMLMetadataAppleTouchIcon(urlString, htmlTag)
}
}
else {
} else {
self.appleTouchIcons = nil
}
@@ -37,8 +36,7 @@ public final class HTMLMetadata: Sendable {
self.feedLinks = feedLinkTags.map { htmlTag in
HTMLMetadataFeedLink(urlString, htmlTag)
}
}
else {
} else {
self.feedLinks = nil
}
@@ -89,7 +87,7 @@ public final class HTMLMetadata: Sendable {
}
let feedLinkTags = alternateLinkTags.filter { tag in
guard let attributes = tag.attributes, let type = attributes.object(forCaseInsensitiveKey: "type"), typeIsFeedType(type) else {
return false
}
@@ -206,8 +204,7 @@ public final class HTMLMetadataAppleTouchIcon: Sendable {
let sizeComponents = sizes.components(separatedBy: CharacterSet(charactersIn: "x"))
if sizeComponents.count == 2, let width = Double(sizeComponents[0]), let height = Double(sizeComponents[1]) {
self.size = CGSize(width: width, height: height)
}
else {
} else {
self.size = nil
}
}
@@ -313,25 +310,19 @@ private extension HTMLOpenGraphProperties {
if propertyName == OGValue.ogImage {
url = content
}
else if propertyName == OGValue.ogImageURL {
} else if propertyName == OGValue.ogImageURL {
url = content
}
else if propertyName == OGValue.ogImageSecureURL {
} else if propertyName == OGValue.ogImageSecureURL {
secureURL = content
}
else if propertyName == OGValue.ogImageType {
} else if propertyName == OGValue.ogImageType {
mimeType = content
}
else if propertyName == OGValue.ogImageAlt {
} else if propertyName == OGValue.ogImageAlt {
altText = content
}
else if propertyName == OGValue.ogImageWidth {
} else if propertyName == OGValue.ogImageWidth {
if let value = Double(content) {
width = CGFloat(value)
}
}
else if propertyName == OGValue.ogImageHeight {
} else if propertyName == OGValue.ogImageHeight {
if let value = Double(content) {
height = CGFloat(value)
}
@@ -341,14 +332,14 @@ private extension HTMLOpenGraphProperties {
if url == nil && secureURL == nil && mimeType == nil && width == nil && height == nil && altText == nil {
return nil
}
return HTMLOpenGraphImage(url: url, secureURL: secureURL, mimeType: mimeType, width: width, height: height, altText: altText)
}
}
public final class HTMLOpenGraphImage: Sendable {
public let url : String?
public let url: String?
public let secureURL: String?
public let mimeType: String?
public let width: CGFloat?
@@ -434,4 +425,3 @@ private func absoluteURLStringWithRelativeURLString(_ relativeURLString: String,
}
return absoluteURL.absoluteURL.standardized.absoluteString
}

View File

@@ -34,13 +34,13 @@ private extension HTMLMetadataParser {
extension HTMLMetadataParser: SAXHTMLParserDelegate {
private struct HTMLName {
static let link = "link".utf8CString
static let meta = "meta".utf8CString
}
private struct HTMLKey {
static let href = "href"
static let src = "src"
static let rel = "rel"
@@ -81,8 +81,7 @@ extension HTMLMetadataParser: SAXHTMLParserDelegate {
if let d, !d.isEmpty {
handleLinkAttributes(d)
}
}
else if SAXEqualTags(name, HTMLName.meta) {
} else if SAXEqualTags(name, HTMLName.meta) {
let d = saxHTMLParser.attributesDictionary(attributes)
if let d, !d.isEmpty {
handleMetaAttributes(d)

View File

@@ -9,8 +9,8 @@ import Foundation
public final class OPMLDocument: OPMLItem {
public var title: String? = nil
public var url: String? = nil
public var title: String?
public var url: String?
init(url: String?) {
self.url = url

View File

@@ -37,4 +37,3 @@ public struct OPMLFeedSpecifier: Sendable {
self.feedURL = feedURL
}
}

View File

@@ -20,7 +20,7 @@ public class OPMLItem {
(items?.count ?? 0) > 0
}
init(attributes: [String : String]?) {
init(attributes: [String: String]?) {
self.titleFromAttributes = attributes?.opml_title ?? attributes?.opml_text
self.attributes = attributes
@@ -33,7 +33,7 @@ public class OPMLItem {
}
public func add(_ item: OPMLItem) {
if items == nil {
items = [OPMLItem]()
}

View File

@@ -50,7 +50,7 @@ private extension OPMLParser {
}
func canParseData() -> Bool {
data.containsASCIIString("<opml")
}

View File

@@ -14,7 +14,7 @@ public extension Dictionary where Key == String, Value == String {
if let object = self[key] {
return object
}
let lowercaseKey = key.lowercased()
for (oneKey, oneValue) in self {

View File

@@ -103,7 +103,7 @@ public final class SAXHTMLParser {
var dictionary = [String: String]()
var ix = 0
var currentKey: String? = nil
var currentKey: String?
while true {
let oneAttribute = attributes[ix]

View File

@@ -61,7 +61,7 @@ public final class SAXParser {
}
public func parse() {
guard !data.isEmpty else {
return
}
@@ -99,7 +99,7 @@ public final class SAXParser {
}
var dictionary = [String: String]()
let fieldCount = 5
var i = 0, j = 0
while i < attributeCount {
@@ -201,4 +201,3 @@ nonisolated(unsafe) private var saxHandlerStruct: xmlSAXHandler = {
return handler
}()

View File

@@ -10,8 +10,8 @@ import libxml2
public func SAXEqualTags(_ localName: XMLPointer, _ tag: ContiguousArray<Int8>) -> Bool {
return tag.withUnsafeBufferPointer { bufferPointer in
return tag.withUnsafeBufferPointer { _ in
let tagCount = tag.count // includes 0 terminator
for i in 0..<tagCount - 1 {