From 981ccb0a01c54abbe3c12ccb8226108527bbf115 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 10 Jun 2022 14:58:20 +0700 Subject: [PATCH] Minor tweaks --- .swiftlint.yml | 22 +++++++++++++++---- .../Defaults/Defaults+AnySerializable.swift | 2 +- Sources/Defaults/Defaults.swift | 2 +- Sources/Defaults/Utilities.swift | 8 +++---- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 49fa3fd..2ac73b5 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -20,11 +20,14 @@ only_rules: - control_statement - custom_rules - discarded_notification_center_observer + - discouraged_assert - discouraged_direct_init + - discouraged_none_name - discouraged_object_literal - discouraged_optional_collection - duplicate_enum_cases - duplicate_imports + - duplicated_key_in_dictionary_literal - dynamic_inline - empty_collection_literal - empty_count @@ -80,10 +83,12 @@ only_rules: - operator_whitespace - orphaned_doc_comment - overridden_super_call + - prefer_self_in_static_references - prefer_self_type_over_type_of_self - prefer_zero_over_explicit_init - private_action - private_outlet + - private_subject - private_unit_test - prohibited_super_call - protocol_property_accessors_order @@ -99,6 +104,8 @@ only_rules: - redundant_void_return - required_enum_case - return_arrow_whitespace + - return_value_from_void_function + - self_in_property_initialization - shorthand_operator - sorted_first_last - statement_position @@ -115,6 +122,7 @@ only_rules: - trailing_newline - trailing_semicolon - trailing_whitespace + - unavailable_condition - unavailable_function - unneeded_break_in_switch - unneeded_parentheses_in_closure_argument @@ -132,12 +140,13 @@ only_rules: - vertical_whitespace_closing_braces - vertical_whitespace_opening_braces - void_return - - weak_delegate - xct_specific_matcher - yoda_condition analyzer_rules: + - capture_variable - unused_declaration - unused_import + - typesafe_array_init number_separator: minimum_length: 5 identifier_name: @@ -153,12 +162,14 @@ identifier_name: excluded: - 'x' - 'y' + - 'z' - 'a' - 'b' - 'x1' - 'x2' - 'y1' - 'y2' + - 'z2' custom_rules: no_nsrect: regex: '\bNSRect\b' @@ -173,8 +184,11 @@ custom_rules: match_kinds: typeidentifier message: 'Use CGPoint instead of NSPoint' swiftui_state_private: - regex: '@(State|StateObject)\s+var' - message: "SwiftUI @State/@StateObject properties should be private" + regex: '@(State|StateObject|ObservedObject|EnvironmentObject)\s+var' + message: 'SwiftUI @State/@StateObject/@ObservedObject/@EnvironmentObject properties should be private' + swiftui_environment_private: + regex: '@Environment\(\\\.\w+\)\s+var' + message: 'SwiftUI @Environment properties should be private' final_class: regex: '^class [a-zA-Z\d]+[^{]+\{' - message: "Classes should be marked as final whenever possible. If you actually need it to be subclassable, just add `// swiftlint:disable:next final_class`." + message: 'Classes should be marked as final whenever possible. If you actually need it to be subclassable, just add `// swiftlint:disable:next final_class`.' diff --git a/Sources/Defaults/Defaults+AnySerializable.swift b/Sources/Defaults/Defaults+AnySerializable.swift index 6a1bdf1..a791f97 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: // swiftlint:disable:this no_cgfloat + case let value as CGFloat: hasher.combine(value) case let value as String: hasher.combine(value) diff --git a/Sources/Defaults/Defaults.swift b/Sources/Defaults/Defaults.swift index 5ef1e9b..f99bb68 100644 --- a/Sources/Defaults/Defaults.swift +++ b/Sources/Defaults/Defaults.swift @@ -86,7 +86,7 @@ extension Defaults { } extension Defaults.Key { - public convenience init(_ key: String, suite: UserDefaults = .standard) where Value == T? { + public convenience init(_ key: String, suite: UserDefaults = .standard) where Value == T? { self.init(key, default: nil, suite: suite) } } diff --git a/Sources/Defaults/Utilities.swift b/Sources/Defaults/Utilities.swift index 7921ea8..18c7adc 100644 --- a/Sources/Defaults/Utilities.swift +++ b/Sources/Defaults/Utilities.swift @@ -83,8 +83,8 @@ final class LifetimeAssociation { init(of target: AnyObject, with owner: AnyObject, deinitHandler: @escaping () -> Void = {}) { let wrappedObject = ObjectLifetimeTracker(for: target, deinitHandler: deinitHandler) - let associatedObjects = LifetimeAssociation.associatedObjects[owner] ?? [] - LifetimeAssociation.associatedObjects[owner] = associatedObjects + [wrappedObject] + let associatedObjects = Self.associatedObjects[owner] ?? [] + Self.associatedObjects[owner] = associatedObjects + [wrappedObject] self.wrappedObject = wrappedObject self.owner = owner @@ -106,14 +106,14 @@ final class LifetimeAssociation { guard let owner = owner, let wrappedObject = wrappedObject, - var associatedObjects = LifetimeAssociation.associatedObjects[owner], + var associatedObjects = Self.associatedObjects[owner], let wrappedObjectAssociationIndex = associatedObjects.firstIndex(where: { $0 === wrappedObject }) else { return } associatedObjects.remove(at: wrappedObjectAssociationIndex) - LifetimeAssociation.associatedObjects[owner] = associatedObjects + Self.associatedObjects[owner] = associatedObjects self.owner = nil } }