Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 10, 2022
1 parent 9e65eac commit 981ccb0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
22 changes: 18 additions & 4 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -153,12 +162,14 @@ identifier_name:
excluded:
- 'x'
- 'y'
- 'z'
- 'a'
- 'b'
- 'x1'
- 'x2'
- 'y1'
- 'y2'
- 'z2'
custom_rules:
no_nsrect:
regex: '\bNSRect\b'
Expand All @@ -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`.'
2 changes: 1 addition & 1 deletion Sources/Defaults/Defaults+AnySerializable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Defaults/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension Defaults {
}

extension Defaults.Key {
public convenience init<T: Defaults.Serializable>(_ key: String, suite: UserDefaults = .standard) where Value == T? {
public convenience init<T>(_ key: String, suite: UserDefaults = .standard) where Value == T? {
self.init(key, default: nil, suite: suite)
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Defaults/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down

0 comments on commit 981ccb0

Please sign in to comment.