Fix lint issues.

This commit is contained in:
Brent Simmons 2025-01-25 10:46:09 -08:00
parent fd84481129
commit 48fc807f94
11 changed files with 63 additions and 58 deletions

View File

@ -108,13 +108,21 @@ public extension Article {
result.append(text) result.append(text)
} }
if let _ = scanner.scanString("<") { if scanner.scanString("<") != nil {
// All the allowed tags currently don't allow attributes // All the allowed tags currently don't allow attributes
if let tag = scanner.scanUpToString(">") { if let tag = scanner.scanUpToString(">") {
if Self.allowedTags.contains(tag.replacingOccurrences(of: "/", with: "")) { if Self.allowedTags.contains(tag.replacingOccurrences(of: "/", with: "")) {
forHTML ? result.append("<\(tag)>") : result.append("") if forHTML {
result.append("<\(tag)>")
} else { } else {
forHTML ? result.append("&lt;\(tag)&gt;") : result.append("<\(tag)>") result.append("")
}
} else {
if forHTML {
result.append("&lt;\(tag)&gt;")
} else {
result.append("<\(tag)>")
}
} }
_ = scanner.scanString(">") _ = scanner.scanString(">")

View File

@ -12,8 +12,8 @@ import os
public final class ArticleStatus: Sendable, Hashable { public final class ArticleStatus: Sendable, Hashable {
public enum Key: String { public enum Key: String {
case read = "read" case read
case starred = "starred" case starred
} }
public let articleID: String public let articleID: String

View File

@ -299,7 +299,7 @@ private final class StatusCache {
for status in statuses { for status in statuses {
let articleID = status.articleID let articleID = status.articleID
if let _ = self[articleID] { if self[articleID] != nil {
continue continue
} }
self[articleID] = status self[articleID] = status

View File

@ -192,18 +192,18 @@ private extension DateParser {
enum Month: Int { enum Month: Int {
case January = 1, case january = 1,
February, february,
March, march,
April, april,
May, may,
June, june,
July, july,
August, august,
September, september,
October, october,
November, november,
December december
} }
// MARK: - Standard Formats // MARK: - Standard Formats
@ -291,7 +291,7 @@ private extension DateParser {
var finalIndex = 0 var finalIndex = 0
let day = nextNumericValue(bytes, numberOfBytes, 0, 2, &finalIndex) ?? 1 let day = nextNumericValue(bytes, numberOfBytes, 0, 2, &finalIndex) ?? 1
let month = nextMonthValue(bytes, numberOfBytes, finalIndex + 1, &finalIndex) ?? .January let month = nextMonthValue(bytes, numberOfBytes, finalIndex + 1, &finalIndex) ?? .january
guard let year = nextNumericValue(bytes, numberOfBytes, finalIndex + 1, 4, &finalIndex) else { guard let year = nextNumericValue(bytes, numberOfBytes, finalIndex + 1, 4, &finalIndex) else {
return nil return nil
@ -451,7 +451,9 @@ private extension DateParser {
characters.append(character) characters.append(character)
} }
let name = String(decoding: characters, as: UTF8.self) guard let name = String(bytes: characters, encoding: .utf8) else {
return nil
}
return timeZoneTable[name] return timeZoneTable[name]
} }
@ -482,19 +484,19 @@ private extension DateParser {
numberOfAlphaCharactersFound+=1 numberOfAlphaCharactersFound+=1
if numberOfAlphaCharactersFound == 1 { if numberOfAlphaCharactersFound == 1 {
if ch == DateCharacter.F || ch == DateCharacter.f { if ch == DateCharacter.F || ch == DateCharacter.f {
return .February return .february
} }
if ch == DateCharacter.S || ch == DateCharacter.s { if ch == DateCharacter.S || ch == DateCharacter.s {
return .September return .september
} }
if ch == DateCharacter.O || ch == DateCharacter.o { if ch == DateCharacter.O || ch == DateCharacter.o {
return .October return .october
} }
if ch == DateCharacter.N || ch == DateCharacter.n { if ch == DateCharacter.N || ch == DateCharacter.n {
return .November return .november
} }
if ch == DateCharacter.D || ch == DateCharacter.d { if ch == DateCharacter.D || ch == DateCharacter.d {
return .December return .december
} }
} }
@ -510,32 +512,32 @@ private extension DateParser {
if monthCharacters[0] == DateCharacter.J || monthCharacters[0] == DateCharacter.j { // Jan, Jun, Jul if monthCharacters[0] == DateCharacter.J || monthCharacters[0] == DateCharacter.j { // Jan, Jun, Jul
if monthCharacters[1] == DateCharacter.A || monthCharacters[1] == DateCharacter.a { if monthCharacters[1] == DateCharacter.A || monthCharacters[1] == DateCharacter.a {
return .January return .january
} }
if monthCharacters[1] == DateCharacter.U || monthCharacters[1] == DateCharacter.u { if monthCharacters[1] == DateCharacter.U || monthCharacters[1] == DateCharacter.u {
if monthCharacters[2] == DateCharacter.N || monthCharacters[2] == DateCharacter.n { if monthCharacters[2] == DateCharacter.N || monthCharacters[2] == DateCharacter.n {
return .June return .june
} }
return .July return .july
} }
return .January return .january
} }
if monthCharacters[0] == DateCharacter.M || monthCharacters[0] == DateCharacter.m { // March, May if monthCharacters[0] == DateCharacter.M || monthCharacters[0] == DateCharacter.m { // March, May
if monthCharacters[2] == DateCharacter.Y || monthCharacters[2] == DateCharacter.y { if monthCharacters[2] == DateCharacter.Y || monthCharacters[2] == DateCharacter.y {
return .May return .may
} }
return .March return .march
} }
if monthCharacters[0] == DateCharacter.A || monthCharacters[0] == DateCharacter.a { // April, August if monthCharacters[0] == DateCharacter.A || monthCharacters[0] == DateCharacter.a { // April, August
if monthCharacters[1] == DateCharacter.U || monthCharacters[1] == DateCharacter.u { if monthCharacters[1] == DateCharacter.U || monthCharacters[1] == DateCharacter.u {
return .August return .august
} }
return .April return .april
} }
return .January // Should never get here (but possibly do) return .january // Should never get here (but possibly do)
} }
private static func nextNumericValue(_ bytes: DateBuffer, _ numberOfBytes: Int, _ startingIndex: Int, _ maximumNumberOfDigits: Int, _ finalIndex: inout Int) -> Int? { private static func nextNumericValue(_ bytes: DateBuffer, _ numberOfBytes: Int, _ startingIndex: Int, _ maximumNumberOfDigits: Int, _ finalIndex: inout Int) -> Int? {

View File

@ -12,7 +12,7 @@ public class RSToolbarItem: NSToolbarItem {
override public func validate() { override public func validate() {
guard let view = view, let _ = view.window else { guard view?.window != nil else {
isEnabled = false isEnabled = false
return return
} }

View File

@ -30,7 +30,7 @@ import AppKit
public func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] { public func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
if let _ = URL(string: urlString) { if URL(string: urlString) != nil {
return [.URL, .string] return [.URL, .string]
} }
return [.string] return [.string]

View File

@ -56,11 +56,11 @@ public final class BatchUpdate {
private extension BatchUpdate { private extension BatchUpdate {
func incrementCount() { func incrementCount() {
count = count + 1 count += 1
} }
func decrementCount() { func decrementCount() {
count = count - 1 count -= 1
if count < 1 { if count < 1 {
assert(count > -1, "Expected batch updates count to be 0 or greater.") assert(count > -1, "Expected batch updates count to be 0 or greater.")
count = 0 count = 0

View File

@ -88,6 +88,8 @@ public extension Data {
static let lessThan = "<".utf8.first! static let lessThan = "<".utf8.first!
static let greaterThan = ">".utf8.first! static let greaterThan = ">".utf8.first!
// swiftlint:disable non_optional_string_data_conversion
/// Tags in UTF-8/ASCII format. /// Tags in UTF-8/ASCII format.
enum UTF8 { enum UTF8 {
static let lowercaseHTML = "html".data(using: .utf8)! static let lowercaseHTML = "html".data(using: .utf8)!
@ -104,6 +106,7 @@ public extension Data {
static let uppercaseBody = "BODY".data(using: .utf16LittleEndian)! static let uppercaseBody = "BODY".data(using: .utf16LittleEndian)!
} }
// swiftlint:enable non_optional_string_data_conversion
} }
/// Returns `true` if the data looks like it could be HTML. /// Returns `true` if the data looks like it could be HTML.

View File

@ -8,14 +8,13 @@
import XCTest import XCTest
class String_RSCore: XCTestCase { class StringRSCore: XCTestCase {
func testCollapsingWhitespace() { func testCollapsingWhitespace() {
let str = " lots\t\tof random\n\nwhitespace\r\n" let str = " lots\t\tof random\n\nwhitespace\r\n"
let expected = "lots of random whitespace" let expected = "lots of random whitespace"
XCTAssertEqual(str.collapsingWhitespace, expected) XCTAssertEqual(str.collapsingWhitespace, expected)
} }
func testTrimmingWhitespace() { func testTrimmingWhitespace() {
@ -103,7 +102,6 @@ class String_RSCore: XCTestCase {
let str = #"<foo attr="value">bar&baz</foo>"# let str = #"<foo attr="value">bar&baz</foo>"#
let expected = "&lt;foo attr=&quot;value&quot;&gt;bar&amp;baz&lt;/foo&gt;" let expected = "&lt;foo attr=&quot;value&quot;&gt;bar&amp;baz&lt;/foo&gt;"
XCTAssertEqual(str.escapingSpecialXMLCharacters, expected) XCTAssertEqual(str.escapingSpecialXMLCharacters, expected)
} }
func testStrippingHTTPOrHTTPSScheme() { func testStrippingHTTPOrHTTPSScheme() {
@ -117,7 +115,6 @@ class String_RSCore: XCTestCase {
let noreplacement = "example://ranchero.com/" let noreplacement = "example://ranchero.com/"
XCTAssertEqual(noreplacement.strippingHTTPOrHTTPSScheme, noreplacement) XCTAssertEqual(noreplacement.strippingHTTPOrHTTPSScheme, noreplacement)
} }
func testNormalizedURL() { func testNormalizedURL() {
@ -150,7 +147,6 @@ class String_RSCore: XCTestCase {
// bare // bare
let http = "http://daringfireball.net/" let http = "http://daringfireball.net/"
XCTAssertEqual(http.normalizedURL, "http://daringfireball.net/") XCTAssertEqual(http.normalizedURL, "http://daringfireball.net/")
} }
func testMD5StringPerformance() { func testMD5StringPerformance() {
@ -181,5 +177,4 @@ class String_RSCore: XCTestCase {
} }
} }
} }
} }

View File

@ -21,10 +21,7 @@ public final class Node: Hashable {
private static var incrementingID = 0 private static var incrementingID = 0
public var isRoot: Bool { public var isRoot: Bool {
if let _ = parent { parent == nil
return false
}
return true
} }
public var numberOfChildNodes: Int { public var numberOfChildNodes: Int {