From 0f73f9401a416336931f2d598662cc524a13b21f Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 18 Jan 2024 16:58:06 +0700 Subject: [PATCH] Fix lint issues --- .swiftlint.yml | 15 +++++++++++++-- Sources/Defaults/Defaults+AnySerializable.swift | 4 ++-- Sources/Defaults/Defaults+Bridge.swift | 2 +- Sources/Defaults/Defaults+Extensions.swift | 1 + Sources/Defaults/SwiftUI.swift | 8 ++++---- .../DefaultsAnySeriliazableTests.swift | 10 +++++----- Tests/DefaultsTests/DefaultsArrayTests.swift | 6 +++--- .../DefaultsTests/DefaultsCodableEnumTests.swift | 4 ++-- Tests/DefaultsTests/DefaultsCodableTests.swift | 6 +++--- .../DefaultsCollectionCustomElementTests.swift | 4 ++-- Tests/DefaultsTests/DefaultsCollectionTests.swift | 4 ++-- .../DefaultsTests/DefaultsCustomBridgeTests.swift | 4 ++-- Tests/DefaultsTests/DefaultsDictionaryTests.swift | 6 +++--- Tests/DefaultsTests/DefaultsEnumTests.swift | 4 ++-- Tests/DefaultsTests/DefaultsNSColorTests.swift | 10 +++++----- .../DefaultsNSSecureCodingTests.swift | 6 +++--- .../DefaultsSetAlgebraCustomElementTests.swift | 4 ++-- Tests/DefaultsTests/DefaultsSetAlgebraTests.swift | 4 ++-- Tests/DefaultsTests/DefaultsSetTests.swift | 2 +- Tests/DefaultsTests/DefaultsTests.swift | 2 ++ Tests/DefaultsTests/DefaultsUIColorTests.swift | 10 +++++----- 21 files changed, 65 insertions(+), 51 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 9559bc0f..4602d5cc 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -28,6 +28,7 @@ only_rules: - discouraged_direct_init - discouraged_none_name - discouraged_object_literal + - discouraged_optional_boolean - discouraged_optional_collection - duplicate_conditions - duplicate_enum_cases @@ -79,6 +80,7 @@ only_rules: - no_extension_access_modifier - no_fallthrough_only - no_space_in_method_call + - non_overridable_class_declaration - notification_center_detachment - ns_number_init_as_function_reference - nsobject_prefer_isequal @@ -93,6 +95,7 @@ only_rules: - private_action - private_outlet - private_subject + - private_swiftui_state - private_unit_test - prohibited_super_call - protocol_property_accessors_order @@ -132,6 +135,7 @@ only_rules: - unavailable_condition - unavailable_function - unneeded_break_in_switch + - unneeded_override - unneeded_parentheses_in_closure_argument - unowned_variable_capture - untyped_error_in_catch @@ -191,9 +195,16 @@ custom_rules: regex: '\bNSPoint\b' match_kinds: typeidentifier message: 'Use CGPoint instead of NSPoint' + no_cgfloat: + regex: '\bCGFloat\b' + match_kinds: typeidentifier + message: 'Use Double instead of CGFloat' + no_cgfloat2: + regex: '\bCGFloat\(' + message: 'Use Double instead of CGFloat' swiftui_state_private: - regex: '@(State|StateObject|ObservedObject|EnvironmentObject)\s+var' - message: 'SwiftUI @State/@StateObject/@ObservedObject/@EnvironmentObject properties should be private' + regex: '@(ObservedObject|EnvironmentObject)\s+var' + message: 'SwiftUI @ObservedObject/@EnvironmentObject properties should be private' swiftui_environment_private: regex: '@Environment\(\\\.\w+\)\s+var' message: 'SwiftUI @Environment properties should be private' diff --git a/Sources/Defaults/Defaults+AnySerializable.swift b/Sources/Defaults/Defaults+AnySerializable.swift index 5c69461f..4e0e4fb6 100644 --- a/Sources/Defaults/Defaults+AnySerializable.swift +++ b/Sources/Defaults/Defaults+AnySerializable.swift @@ -88,7 +88,7 @@ extension Defaults.AnySerializable: Hashable { hasher.combine(value) case let value as Double: hasher.combine(value) - case let value as CGFloat: + case let value as CGFloat: // swiftlint:disable:this no_cgfloat hasher.combine(value) case let value as String: hasher.combine(value) @@ -135,7 +135,7 @@ extension Defaults.AnySerializable: Equatable { lhs == rhs case (let lhs as Double, let rhs as Double): lhs == rhs - case (let lhs as CGFloat, let rhs as CGFloat): + case (let lhs as CGFloat, let rhs as CGFloat): // swiftlint:disable:this no_cgfloat lhs == rhs case (let lhs as String, let rhs as String): lhs == rhs diff --git a/Sources/Defaults/Defaults+Bridge.swift b/Sources/Defaults/Defaults+Bridge.swift index 12eeeb53..7bcb25f5 100644 --- a/Sources/Defaults/Defaults+Bridge.swift +++ b/Sources/Defaults/Defaults+Bridge.swift @@ -412,7 +412,7 @@ extension Defaults { let object = object as? [Any], let rawColorspace = object[0] as? String, let colorspace = CGColorSpace(name: rawColorspace as CFString), - let components = object[1] as? [CGFloat], + let components = object[1] as? [CGFloat], // swiftlint:disable:this no_cgfloat let cgColor = CGColor(colorSpace: colorspace, components: components) else { return nil diff --git a/Sources/Defaults/Defaults+Extensions.swift b/Sources/Defaults/Defaults+Extensions.swift index 22efa7ee..7c4fd274 100644 --- a/Sources/Defaults/Defaults+Extensions.swift +++ b/Sources/Defaults/Defaults+Extensions.swift @@ -41,6 +41,7 @@ extension String: Defaults.Serializable { public static let isNativelySupportedType = true } +// swiftlint:disable:next no_cgfloat extension CGFloat: Defaults.Serializable { public static let isNativelySupportedType = true } diff --git a/Sources/Defaults/SwiftUI.swift b/Sources/Defaults/SwiftUI.swift index 0fc7287f..936c68fd 100644 --- a/Sources/Defaults/SwiftUI.swift +++ b/Sources/Defaults/SwiftUI.swift @@ -6,7 +6,7 @@ extension Defaults { final class Observable: ObservableObject { private var cancellable: AnyCancellable? private var task: Task? - + var key: Defaults.Key { didSet { if key != oldValue { @@ -24,14 +24,14 @@ extension Defaults { init(_ key: Key) { self.key = key - + observe() } - + deinit { task?.cancel() } - + func observe() { // We only use this on the latest OSes (as of adding this) since the backdeploy library has a lot of bugs. if #available(macOS 13, iOS 16, tvOS 16, watchOS 9, *) { diff --git a/Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift b/Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift index 64614c6b..051d1a4a 100644 --- a/Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift +++ b/Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift @@ -169,11 +169,11 @@ final class DefaultsAnySerializableTests: XCTestCase { XCTAssertEqual(Defaults[any].get()!, URL(string: "https://example.com")!) #if os(macOS) // Test NSColor - Defaults[any].set(NSColor(red: CGFloat(103) / CGFloat(0xFF), green: CGFloat(132) / CGFloat(0xFF), blue: CGFloat(255) / CGFloat(0xFF), alpha: 0.987)) + Defaults[any].set(NSColor(red: Double(103) / Double(0xFF), green: Double(132) / Double(0xFF), blue: Double(255) / Double(0xFF), alpha: 0.987)) XCTAssertEqual(Defaults[any].get(NSColor.self)?.alphaComponent, 0.987) #else // Test UIColor - Defaults[any].set(UIColor(red: CGFloat(103) / CGFloat(0xFF), green: CGFloat(132) / CGFloat(0xFF), blue: CGFloat(255) / CGFloat(0xFF), alpha: 0.654)) + Defaults[any].set(UIColor(red: Double(103) / Double(0xFF), green: Double(132) / Double(0xFF), blue: Double(255) / Double(0xFF), alpha: 0.654)) XCTAssertEqual(Defaults[any].get(UIColor.self)?.cgColor.alpha, 0.654) #endif // Test Codable type @@ -256,7 +256,7 @@ final class DefaultsAnySerializableTests: XCTestCase { Defaults[key].insert(float) XCTAssertTrue(Defaults[key].contains(float)) - let cgFloat = Defaults.AnySerializable(CGFloat(12_131.415)) + let cgFloat = Defaults.AnySerializable(CGFloat(12_131.415)) // swiftlint:disable:this no_cgfloat2 Defaults[key].insert(cgFloat) XCTAssertTrue(Defaults[key].contains(cgFloat)) @@ -278,7 +278,7 @@ final class DefaultsAnySerializableTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[Defaults.AnySerializable]?>("testArrayOptionalAnyKey") + let key = Defaults.Key<[Defaults.AnySerializable]?>("testArrayOptionalAnyKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = [123] Defaults[key]?.append(456) @@ -315,7 +315,7 @@ final class DefaultsAnySerializableTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: Defaults.AnySerializable]?>("independentDictionaryOptionalAnyKey") + let key = Defaults.Key<[String: Defaults.AnySerializable]?>("independentDictionaryOptionalAnyKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["unicorn": "🦄"] XCTAssertEqual(Defaults[key]?["unicorn"], "🦄") diff --git a/Tests/DefaultsTests/DefaultsArrayTests.swift b/Tests/DefaultsTests/DefaultsArrayTests.swift index 2b91eb8f..a0bc03d1 100644 --- a/Tests/DefaultsTests/DefaultsArrayTests.swift +++ b/Tests/DefaultsTests/DefaultsArrayTests.swift @@ -28,7 +28,7 @@ final class DefaultsArrayTests: XCTestCase { } func testOptionalKey() { - let key = Defaults.Key<[String]?>("independentArrayOptionalStringKey") + let key = Defaults.Key<[String]?>("independentArrayOptionalStringKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = fixtureArray XCTAssertEqual(Defaults[key]?[0], fixtureArray[0]) @@ -108,7 +108,7 @@ final class DefaultsArrayTests: XCTestCase { } func testObserveOptionalKeyCombine() { - let key = Defaults.Key<[String]?>("observeArrayOptionalKeyCombine") + let key = Defaults.Key<[String]?>("observeArrayOptionalKeyCombine") // swiftlint:disable:this discouraged_optional_collection let newName = ["Chen"] let expect = expectation(description: "Observation closure being called") @@ -157,7 +157,7 @@ final class DefaultsArrayTests: XCTestCase { } func testObserveOptionalKey() { - let key = Defaults.Key<[String]?>("observeArrayOptionalKey") + let key = Defaults.Key<[String]?>("observeArrayOptionalKey") // swiftlint:disable:this discouraged_optional_collection let expect = expectation(description: "Observation closure being called") var observation: Defaults.Observation! diff --git a/Tests/DefaultsTests/DefaultsCodableEnumTests.swift b/Tests/DefaultsTests/DefaultsCodableEnumTests.swift index a78da579..70e66bba 100644 --- a/Tests/DefaultsTests/DefaultsCodableEnumTests.swift +++ b/Tests/DefaultsTests/DefaultsCodableEnumTests.swift @@ -53,7 +53,7 @@ final class DefaultsCodableEnumTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[FixtureCodableEnum]?>("independentCodableEnumArrayOptionalKey") + let key = Defaults.Key<[FixtureCodableEnum]?>("independentCodableEnumArrayOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = [.halfHour] } @@ -86,7 +86,7 @@ final class DefaultsCodableEnumTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: FixtureCodableEnum]?>("independentCodableEnumDictionaryOptionalKey") + let key = Defaults.Key<[String: FixtureCodableEnum]?>("independentCodableEnumDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["0": .tenMinutes] Defaults[key]?["1"] = .halfHour diff --git a/Tests/DefaultsTests/DefaultsCodableTests.swift b/Tests/DefaultsTests/DefaultsCodableTests.swift index 18d36325..4dced9df 100644 --- a/Tests/DefaultsTests/DefaultsCodableTests.swift +++ b/Tests/DefaultsTests/DefaultsCodableTests.swift @@ -74,7 +74,7 @@ final class DefaultsCodableTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[Unicorn]?>("independentCodableArrayOptionalKey") + let key = Defaults.Key<[Unicorn]?>("independentCodableArrayOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = [fixtureCodable] Defaults[key]?.append(Unicorn(isUnicorn: false)) @@ -111,7 +111,7 @@ final class DefaultsCodableTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: Unicorn]?>("independentCodableDictionaryOptionalKey") + let key = Defaults.Key<[String: Unicorn]?>("independentCodableDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["0": fixtureCodable] Defaults[key]?["1"] = Unicorn(isUnicorn: false) @@ -209,7 +209,7 @@ final class DefaultsCodableTests: XCTestCase { .map { ($0.oldValue?.isUnicorn, $0.newValue?.isUnicorn) } .collect(2) - let expectedValue: [(Bool?, Bool?)] = [(nil, true), (true, nil)] + let expectedValue: [(Bool?, Bool?)] = [(nil, true), (true, nil)] // swiftlint:disable:this discouraged_optional_boolean let cancellable = publisher.sink { tuples in for (index, expected) in expectedValue.enumerated() { diff --git a/Tests/DefaultsTests/DefaultsCollectionCustomElementTests.swift b/Tests/DefaultsTests/DefaultsCollectionCustomElementTests.swift index 39b17d6c..99f21ef7 100644 --- a/Tests/DefaultsTests/DefaultsCollectionCustomElementTests.swift +++ b/Tests/DefaultsTests/DefaultsCollectionCustomElementTests.swift @@ -85,7 +85,7 @@ final class DefaultsCollectionCustomElementTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[Bag]?>("independentCollectionCustomElementArrayOptionalKey") + let key = Defaults.Key<[Bag]?>("independentCollectionCustomElementArrayOptionalKey") // swiftlint:disable:this discouraged_optional_collection Defaults[key] = [.init(items: [fixtureCustomCollection])] Defaults[key]?[0].insert(element: fixtureCustomCollection1, at: 1) Defaults[key]?.append(Bag(items: [fixtureCustomCollection2])) @@ -126,7 +126,7 @@ final class DefaultsCollectionCustomElementTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: Bag]?>("independentCollectionCustomElementDictionaryOptionalKey") + let key = Defaults.Key<[String: Bag]?>("independentCollectionCustomElementDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection Defaults[key] = ["0": .init(items: [fixtureCustomCollection])] Defaults[key]?["0"]?.insert(element: fixtureCustomCollection1, at: 1) Defaults[key]?["1"] = .init(items: [fixtureCustomCollection2]) diff --git a/Tests/DefaultsTests/DefaultsCollectionTests.swift b/Tests/DefaultsTests/DefaultsCollectionTests.swift index 1977cd95..33eb1916 100644 --- a/Tests/DefaultsTests/DefaultsCollectionTests.swift +++ b/Tests/DefaultsTests/DefaultsCollectionTests.swift @@ -81,7 +81,7 @@ final class DefaultsCollectionTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[Bag]?>("independentCollectionArrayOptionalKey") + let key = Defaults.Key<[Bag]?>("independentCollectionArrayOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = [Bag(items: [fixtureCollection[0]])] Defaults[key]?.append(Bag(items: [fixtureCollection[1]])) @@ -118,7 +118,7 @@ final class DefaultsCollectionTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: Bag]?>("independentCollectionDictionaryOptionalKey") + let key = Defaults.Key<[String: Bag]?>("independentCollectionDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["0": Bag(items: [fixtureCollection[0]])] Defaults[key]?["0"]?.insert(element: fixtureCollection[1], at: 1) diff --git a/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift b/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift index 9cb8e3a2..f203fd96 100644 --- a/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift +++ b/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift @@ -125,7 +125,7 @@ final class DefaultsCustomBridge: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[User]?>("independentCustomBridgeArrayOptionalKey") + let key = Defaults.Key<[User]?>("independentCustomBridgeArrayOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) let newUser = User(username: "hank121314", password: "123456") Defaults[key] = [newUser] @@ -174,7 +174,7 @@ final class DefaultsCustomBridge: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: User]?>("independentCustomBridgeDictionaryOptionalKey") + let key = Defaults.Key<[String: User]?>("independentCustomBridgeDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["0": fixtureCustomBridge] XCTAssertEqual(Defaults[key]?["0"], fixtureCustomBridge) diff --git a/Tests/DefaultsTests/DefaultsDictionaryTests.swift b/Tests/DefaultsTests/DefaultsDictionaryTests.swift index a34b4624..f81e4ea1 100644 --- a/Tests/DefaultsTests/DefaultsDictionaryTests.swift +++ b/Tests/DefaultsTests/DefaultsDictionaryTests.swift @@ -30,7 +30,7 @@ final class DefaultsDictionaryTests: XCTestCase { } func testOptionalKey() { - let key = Defaults.Key<[String: String]?>("independentDictionaryOptionalKey") + let key = Defaults.Key<[String: String]?>("independentDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = fixtureDictionary XCTAssertEqual(Defaults[key]?["0"], fixtureDictionary["0"]) @@ -100,7 +100,7 @@ final class DefaultsDictionaryTests: XCTestCase { } func testObserveOptionalKeyCombine() { - let key = Defaults.Key<[String: String]?>("observeDictionaryOptionalKeyCombine") + let key = Defaults.Key<[String: String]?>("observeDictionaryOptionalKeyCombine") // swiftlint:disable:this discouraged_optional_collection let expect = expectation(description: "Observation closure being called") let newName = ["0": "John"] let publisher = Defaults @@ -148,7 +148,7 @@ final class DefaultsDictionaryTests: XCTestCase { } func testObserveOptionalKey() { - let key = Defaults.Key<[String: String]?>("observeDictionaryOptionalKey") + let key = Defaults.Key<[String: String]?>("observeDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection let expect = expectation(description: "Observation closure being called") var observation: Defaults.Observation! diff --git a/Tests/DefaultsTests/DefaultsEnumTests.swift b/Tests/DefaultsTests/DefaultsEnumTests.swift index 483839a7..187513a1 100644 --- a/Tests/DefaultsTests/DefaultsEnumTests.swift +++ b/Tests/DefaultsTests/DefaultsEnumTests.swift @@ -48,7 +48,7 @@ final class DefaultsEnumTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[FixtureEnum]?>("independentEnumArrayOptionalKey") + let key = Defaults.Key<[FixtureEnum]?>("independentEnumArrayOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = [.tenMinutes] Defaults[key]?.append(.halfHour) @@ -83,7 +83,7 @@ final class DefaultsEnumTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: FixtureEnum]?>("independentEnumDictionaryOptionalKey") + let key = Defaults.Key<[String: FixtureEnum]?>("independentEnumDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["0": .tenMinutes] XCTAssertEqual(Defaults[key]?["0"], .tenMinutes) diff --git a/Tests/DefaultsTests/DefaultsNSColorTests.swift b/Tests/DefaultsTests/DefaultsNSColorTests.swift index 068f98a5..4bb19cf3 100644 --- a/Tests/DefaultsTests/DefaultsNSColorTests.swift +++ b/Tests/DefaultsTests/DefaultsNSColorTests.swift @@ -4,9 +4,9 @@ import Defaults import XCTest import AppKit -private let fixtureColor = NSColor(red: CGFloat(103) / CGFloat(0xFF), green: CGFloat(132) / CGFloat(0xFF), blue: CGFloat(255) / CGFloat(0xFF), alpha: 1) -private let fixtureColor1 = NSColor(red: CGFloat(255) / CGFloat(0xFF), green: CGFloat(241) / CGFloat(0xFF), blue: CGFloat(180) / CGFloat(0xFF), alpha: 1) -private let fixtureColor2 = NSColor(red: CGFloat(255) / CGFloat(0xFF), green: CGFloat(180) / CGFloat(0xFF), blue: CGFloat(194) / CGFloat(0xFF), alpha: 1) +private let fixtureColor = NSColor(red: Double(103) / Double(0xFF), green: Double(132) / Double(0xFF), blue: Double(255) / Double(0xFF), alpha: 1) +private let fixtureColor1 = NSColor(red: Double(255) / Double(0xFF), green: Double(241) / Double(0xFF), blue: Double(180) / Double(0xFF), alpha: 1) +private let fixtureColor2 = NSColor(red: Double(255) / Double(0xFF), green: Double(180) / Double(0xFF), blue: Double(194) / Double(0xFF), alpha: 1) extension Defaults.Keys { fileprivate static let color = Defaults.Key("NSColor", default: fixtureColor) @@ -57,7 +57,7 @@ final class DefaultsNSColorTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[NSColor]?>("independentNSColorOptionalKey") + let key = Defaults.Key<[NSColor]?>("independentNSColorOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = [fixtureColor] Defaults[key]?.append(fixtureColor1) @@ -91,7 +91,7 @@ final class DefaultsNSColorTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: NSColor]?>("independentNSColorDictionaryOptionalKey") + let key = Defaults.Key<[String: NSColor]?>("independentNSColorDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["0": fixtureColor] Defaults[key]?["1"] = fixtureColor1 diff --git a/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift b/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift index cc985b9b..0067b8c2 100644 --- a/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift +++ b/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift @@ -21,7 +21,7 @@ private final class ExamplePersistentHistory: NSPersistentHistoryToken, Defaults coder.encode(value, forKey: "value") } - override class var supportsSecureCoding: Bool { true } + override class var supportsSecureCoding: Bool { true } // swiftlint:disable:this non_overridable_class_declaration } // NSSecureCoding @@ -77,7 +77,7 @@ final class DefaultsNSSecureCodingTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[ExamplePersistentHistory]?>("independentNSSecureCodingArrayOptionalKey") + let key = Defaults.Key<[ExamplePersistentHistory]?>("independentNSSecureCodingArrayOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = [persistentHistoryValue] XCTAssertEqual(Defaults[key]?[0].value, persistentHistoryValue.value) @@ -120,7 +120,7 @@ final class DefaultsNSSecureCodingTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: ExamplePersistentHistory]?>("independentNSSecureCodingDictionaryOptionalKey") + let key = Defaults.Key<[String: ExamplePersistentHistory]?>("independentNSSecureCodingDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["0": persistentHistoryValue] XCTAssertEqual(Defaults[key]?["0"]?.value, persistentHistoryValue.value) diff --git a/Tests/DefaultsTests/DefaultsSetAlgebraCustomElementTests.swift b/Tests/DefaultsTests/DefaultsSetAlgebraCustomElementTests.swift index 8cfc8606..aa151a02 100644 --- a/Tests/DefaultsTests/DefaultsSetAlgebraCustomElementTests.swift +++ b/Tests/DefaultsTests/DefaultsSetAlgebraCustomElementTests.swift @@ -85,7 +85,7 @@ final class DefaultsSetAlgebraCustomElementTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[DefaultsSetAlgebra]?>("independentSetAlgebraArrayOptionalKey") + let key = Defaults.Key<[DefaultsSetAlgebra]?>("independentSetAlgebraArrayOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = [.init([fixtureSetAlgebra])] Defaults[key]?[0].insert(fixtureSetAlgebra1) @@ -129,7 +129,7 @@ final class DefaultsSetAlgebraCustomElementTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: DefaultsSetAlgebra]?>("independentSetAlgebraDictionaryOptionalKey") + let key = Defaults.Key<[String: DefaultsSetAlgebra]?>("independentSetAlgebraDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["0": .init([fixtureSetAlgebra])] Defaults[key]?["0"]?.insert(fixtureSetAlgebra1) diff --git a/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift b/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift index 879157d1..3ccb60e0 100644 --- a/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift +++ b/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift @@ -117,7 +117,7 @@ final class DefaultsSetAlgebraTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[DefaultsSetAlgebra]?>("independentSetAlgebraArrayOptionalKey") + let key = Defaults.Key<[DefaultsSetAlgebra]?>("independentSetAlgebraArrayOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = [.init([fixtureSetAlgebra])] Defaults[key]?[0].insert(fixtureSetAlgebra1) @@ -161,7 +161,7 @@ final class DefaultsSetAlgebraTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: DefaultsSetAlgebra]?>("independentSetAlgebraDictionaryOptionalKey") + let key = Defaults.Key<[String: DefaultsSetAlgebra]?>("independentSetAlgebraDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["0": .init([fixtureSetAlgebra])] Defaults[key]?["0"]?.insert(fixtureSetAlgebra1) diff --git a/Tests/DefaultsTests/DefaultsSetTests.swift b/Tests/DefaultsTests/DefaultsSetTests.swift index c171ef4e..d8a5daca 100644 --- a/Tests/DefaultsTests/DefaultsSetTests.swift +++ b/Tests/DefaultsTests/DefaultsSetTests.swift @@ -27,7 +27,7 @@ final class DefaultsSetTests: XCTestCase { } func testOptionalKey() { - let key = Defaults.Key?>("independentSetOptionalKey") + let key = Defaults.Key?>("independentSetOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = fixtureSet XCTAssertEqual(Defaults[key]?.count, fixtureSet.count) diff --git a/Tests/DefaultsTests/DefaultsTests.swift b/Tests/DefaultsTests/DefaultsTests.swift index 8ef82e3d..e158e35e 100644 --- a/Tests/DefaultsTests/DefaultsTests.swift +++ b/Tests/DefaultsTests/DefaultsTests.swift @@ -1,3 +1,4 @@ +// swiftlint:disable discouraged_optional_boolean import Foundation import Combine import XCTest @@ -818,3 +819,4 @@ extension Task { try await sleep(nanoseconds: UInt64(seconds * Double(NSEC_PER_SEC))) } } +// swiftlint:enable discouraged_optional_boolean diff --git a/Tests/DefaultsTests/DefaultsUIColorTests.swift b/Tests/DefaultsTests/DefaultsUIColorTests.swift index d8ee69b4..c248bf6a 100644 --- a/Tests/DefaultsTests/DefaultsUIColorTests.swift +++ b/Tests/DefaultsTests/DefaultsUIColorTests.swift @@ -4,9 +4,9 @@ import Defaults import XCTest import UIKit -private let fixtureColor = UIColor(red: CGFloat(103) / CGFloat(0xFF), green: CGFloat(132) / CGFloat(0xFF), blue: CGFloat(255) / CGFloat(0xFF), alpha: 1) -private let fixtureColor1 = UIColor(red: CGFloat(255) / CGFloat(0xFF), green: CGFloat(241) / CGFloat(0xFF), blue: CGFloat(180) / CGFloat(0xFF), alpha: 1) -private let fixtureColor2 = UIColor(red: CGFloat(255) / CGFloat(0xFF), green: CGFloat(180) / CGFloat(0xFF), blue: CGFloat(194) / CGFloat(0xFF), alpha: 1) +private let fixtureColor = UIColor(red: Double(103) / Double(0xFF), green: Double(132) / Double(0xFF), blue: Double(255) / Double(0xFF), alpha: 1) +private let fixtureColor1 = UIColor(red: Double(255) / Double(0xFF), green: Double(241) / Double(0xFF), blue: Double(180) / Double(0xFF), alpha: 1) +private let fixtureColor2 = UIColor(red: Double(255) / Double(0xFF), green: Double(180) / Double(0xFF), blue: Double(194) / Double(0xFF), alpha: 1) extension Defaults.Keys { fileprivate static let color = Defaults.Key("NSColor", default: fixtureColor) @@ -56,7 +56,7 @@ final class DefaultsNSColorTests: XCTestCase { } func testArrayOptionalKey() { - let key = Defaults.Key<[UIColor]?>("independentNSColorOptionalKey") + let key = Defaults.Key<[UIColor]?>("independentNSColorOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = [fixtureColor] Defaults[key]?.append(fixtureColor1) @@ -90,7 +90,7 @@ final class DefaultsNSColorTests: XCTestCase { } func testDictionaryOptionalKey() { - let key = Defaults.Key<[String: UIColor]?>("independentNSColorDictionaryOptionalKey") + let key = Defaults.Key<[String: UIColor]?>("independentNSColorDictionaryOptionalKey") // swiftlint:disable:this discouraged_optional_collection XCTAssertNil(Defaults[key]) Defaults[key] = ["0": fixtureColor] Defaults[key]?["1"] = fixtureColor1