diff --git a/.swiftlint.yml b/.swiftlint.yml index 5f9554e..9559bc0 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,5 +1,7 @@ only_rules: + - accessibility_trait_for_button - array_init + - blanket_disable_command - block_based_kvo - class_delegate_protocol - closing_brace @@ -19,12 +21,15 @@ only_rules: - contains_over_range_nil_comparison - control_statement - custom_rules + - deployment_target + - direct_return - discarded_notification_center_observer - discouraged_assert - discouraged_direct_init - discouraged_none_name - discouraged_object_literal - discouraged_optional_collection + - duplicate_conditions - duplicate_enum_cases - duplicate_imports - duplicated_key_in_dictionary_literal @@ -50,7 +55,7 @@ only_rules: - implicit_getter - implicit_return - inclusive_language - - inert_defer + - invalid_swiftlint_command - is_disjoint - joined_default_parameter - last_where @@ -66,7 +71,6 @@ only_rules: - lower_acl_than_parent - mark - modifier_order - - multiline_arguments - multiline_function_chains - multiline_literal_brackets - multiline_parameters @@ -76,12 +80,12 @@ only_rules: - no_fallthrough_only - no_space_in_method_call - notification_center_detachment + - ns_number_init_as_function_reference - nsobject_prefer_isequal - number_separator - opening_brace - operator_usage_whitespace - operator_whitespace - - orphaned_doc_comment - overridden_super_call - prefer_self_in_static_references - prefer_self_type_over_type_of_self @@ -108,11 +112,13 @@ only_rules: - self_binding - self_in_property_initialization - shorthand_operator + - shorthand_optional_binding - sorted_first_last - statement_position - static_operator - strong_iboutlet - superfluous_disable_command + - superfluous_else - switch_case_alignment - switch_case_on_newline - syntactic_sugar @@ -129,7 +135,6 @@ only_rules: - unneeded_parentheses_in_closure_argument - unowned_variable_capture - untyped_error_in_catch - - unused_capture_list - unused_closure_parameter - unused_control_flow_label - unused_enumerated @@ -142,12 +147,15 @@ only_rules: - void_function_in_ternary - void_return - xct_specific_matcher + - xctfail_message - yoda_condition analyzer_rules: - capture_variable - unused_declaration - unused_import - typesafe_array_init +for_where: + allow_for_as_filter: true number_separator: minimum_length: 5 identifier_name: @@ -157,7 +165,6 @@ identifier_name: min_length: warning: 2 error: 2 - validates_start_with_lowercase: false allowed_symbols: - '_' excluded: diff --git a/Sources/Defaults/Defaults+Bridge.swift b/Sources/Defaults/Defaults+Bridge.swift index a1221bb..c736b8b 100644 --- a/Sources/Defaults/Defaults+Bridge.swift +++ b/Sources/Defaults/Defaults+Bridge.swift @@ -422,9 +422,9 @@ extension Defaults { if #available(macOS 12.0, macOSApplicationExtension 12.0, *) { return Value(cgColor: cgColor) - } else { - return Value(cgColor) } + + return Value(cgColor) } } } diff --git a/Sources/Defaults/Observation+Combine.swift b/Sources/Defaults/Observation+Combine.swift index 247b5cc..16f4e11 100644 --- a/Sources/Defaults/Observation+Combine.swift +++ b/Sources/Defaults/Observation+Combine.swift @@ -107,7 +107,7 @@ extension Defaults { ) -> AnyPublisher { let initial = Empty(completeImmediately: false).eraseToAnyPublisher() - let combinedPublisher = + return keys .map { key in DefaultsPublisher(suite: key.suite, key: key.name, options: options) @@ -117,7 +117,5 @@ extension Defaults { .reduce(initial) { combined, keyPublisher in combined.merge(with: keyPublisher).eraseToAnyPublisher() } - - return combinedPublisher } } diff --git a/Sources/Defaults/Utilities.swift b/Sources/Defaults/Utilities.swift index 357e0c6..2df51c7 100644 --- a/Sources/Defaults/Utilities.swift +++ b/Sources/Defaults/Utilities.swift @@ -194,7 +194,10 @@ extension Defaults.Serializable { return anyObject } - guard let nextType = T.Serializable.self as? any Defaults.Serializable.Type, nextType != T.self else { + guard + let nextType = T.Serializable.self as? any Defaults.Serializable.Type, + nextType != T.self + else { // This is a special case for the types which do not conform to `Defaults.Serializable` (for example, `Any`). return T.bridge.deserialize(anyObject as? T.Serializable) as? T } diff --git a/Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift b/Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift index a0f9e61..64614c6 100644 --- a/Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift +++ b/Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift @@ -466,10 +466,10 @@ final class DefaultsAnySerializableTests: XCTestCase { waitForExpectations(timeout: 10) } - + func testWrongCast() { let value = Defaults.AnySerializable(false) - XCTAssertEqual(value.get(Bool.self), false) + XCTAssertEqual(value.get(Bool.self), false) // swiftlint:disable:this xct_specific_matcher XCTAssertNil(value.get(String.self)) } } diff --git a/Tests/DefaultsTests/DefaultsArrayTests.swift b/Tests/DefaultsTests/DefaultsArrayTests.swift index eb187c8..2b91eb8 100644 --- a/Tests/DefaultsTests/DefaultsArrayTests.swift +++ b/Tests/DefaultsTests/DefaultsArrayTests.swift @@ -117,7 +117,7 @@ final class DefaultsArrayTests: XCTestCase { .map { ($0.oldValue, $0.newValue) } .collect(3) - // swiftlint:disable discouraged_optional_collection + // swiftlint:disable:next discouraged_optional_collection let expectedValues: [([String]?, [String]?)] = [(nil, fixtureArray), (fixtureArray, newName), (newName, nil)] let cancellable = publisher.sink { actualValues in diff --git a/Tests/DefaultsTests/DefaultsDictionaryTests.swift b/Tests/DefaultsTests/DefaultsDictionaryTests.swift index 5ca3242..8ca3d15 100644 --- a/Tests/DefaultsTests/DefaultsDictionaryTests.swift +++ b/Tests/DefaultsTests/DefaultsDictionaryTests.swift @@ -99,7 +99,7 @@ final class DefaultsDictionaryTests: XCTestCase { .map { ($0.oldValue, $0.newValue) } .collect(3) - // swiftlint:disable discouraged_optional_collection + // swiftlint:disable:next discouraged_optional_collection let expectedValues: [([String: String]?, [String: String]?)] = [(nil, fixtureDictionary), (fixtureDictionary, newName), (newName, nil)] let cancellable = publisher.sink { actualValues in diff --git a/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift b/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift index 297618a..cc985b9 100644 --- a/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift +++ b/Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift @@ -317,7 +317,7 @@ final class DefaultsNSSecureCodingTests: XCTestCase { if counter == 2 { expect.fulfill() } else if counter > 2 { - XCTFail() + XCTFail() // swiftlint:disable:this xctfail_message } } diff --git a/Tests/DefaultsTests/DefaultsRangeTests.swift b/Tests/DefaultsTests/DefaultsRangeTests.swift index 793175b..5b60354 100644 --- a/Tests/DefaultsTests/DefaultsRangeTests.swift +++ b/Tests/DefaultsTests/DefaultsRangeTests.swift @@ -37,11 +37,13 @@ extension CustomDate: Comparable { static func < (lhs: CustomDate, rhs: CustomDate) -> Bool { if lhs.year != rhs.year { return lhs.year < rhs.year - } else if lhs.month != rhs.month { - return lhs.month < rhs.month - } else { - return lhs.day < rhs.day } + + if lhs.month != rhs.month { + return lhs.month < rhs.month + } + + return lhs.day < rhs.day } static func == (lhs: CustomDate, rhs: CustomDate) -> Bool { diff --git a/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift b/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift index b7b50aa..879157d 100644 --- a/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift +++ b/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift @@ -48,15 +48,15 @@ struct DefaultsSetAlgebra: SetAlgebra store.update(with: newMember) } - mutating func formUnion(_ other: DefaultsSetAlgebra) { + mutating func formUnion(_ other: Self) { store.formUnion(other.store) } - mutating func formSymmetricDifference(_ other: DefaultsSetAlgebra) { + mutating func formSymmetricDifference(_ other: Self) { store.formSymmetricDifference(other.store) } - mutating func formIntersection(_ other: DefaultsSetAlgebra) { + mutating func formIntersection(_ other: Self) { store.formIntersection(other.store) } } diff --git a/Tests/DefaultsTests/DefaultsTests.swift b/Tests/DefaultsTests/DefaultsTests.swift index 3dbfc99..2108c1c 100644 --- a/Tests/DefaultsTests/DefaultsTests.swift +++ b/Tests/DefaultsTests/DefaultsTests.swift @@ -362,7 +362,7 @@ final class DefaultsTests: XCTestCase { if counter == 2 { expect.fulfill() } else if counter > 2 { - XCTFail() + XCTFail() // swiftlint:disable:this xctfail_message } } @@ -465,7 +465,7 @@ final class DefaultsTests: XCTestCase { } print("--- Main Thread: \(Thread.isMainThread)") if !Thread.isMainThread { - XCTAssert(Defaults[key1]! == 4) + XCTAssertEqual(Defaults[key1]!, 4) expect.fulfill() } else { usleep(300_000) @@ -488,7 +488,7 @@ final class DefaultsTests: XCTestCase { let expect = expectation(description: "No infinite recursion") let observation1 = Defaults.observe(key2, options: []) { _ in - XCTFail() + XCTFail() // swiftlint:disable:this xctfail_message } let observation2 = Defaults.observe(keys: key1, key2, options: []) { @@ -713,7 +713,7 @@ final class DefaultsTests: XCTestCase { sleep(1) if index == 10 { - XCTFail() + XCTFail() // swiftlint:disable:this xctfail_message } } } @@ -751,7 +751,7 @@ final class DefaultsTests: XCTestCase { Defaults[key] = true guard let result = await waiter else { - XCTFail() + XCTFail() // swiftlint:disable:this xctfail_message return }