Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 3, 2023
1 parent 03d5386 commit 957d807
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 27 deletions.
17 changes: 12 additions & 5 deletions .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
Expand All @@ -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
Expand All @@ -50,7 +55,7 @@ only_rules:
- implicit_getter
- implicit_return
- inclusive_language
- inert_defer
- invalid_swiftlint_command
- is_disjoint
- joined_default_parameter
- last_where
Expand All @@ -66,7 +71,6 @@ only_rules:
- lower_acl_than_parent
- mark
- modifier_order
- multiline_arguments
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -157,7 +165,6 @@ identifier_name:
min_length:
warning: 2
error: 2
validates_start_with_lowercase: false
allowed_symbols:
- '_'
excluded:
Expand Down
4 changes: 2 additions & 2 deletions Sources/Defaults/Defaults+Bridge.swift
Expand Up @@ -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)
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions Sources/Defaults/Observation+Combine.swift
Expand Up @@ -107,7 +107,7 @@ extension Defaults {
) -> AnyPublisher<Void, Never> {
let initial = Empty<Void, Never>(completeImmediately: false).eraseToAnyPublisher()

let combinedPublisher =
return
keys
.map { key in
DefaultsPublisher(suite: key.suite, key: key.name, options: options)
Expand All @@ -117,7 +117,5 @@ extension Defaults {
.reduce(initial) { combined, keyPublisher in
combined.merge(with: keyPublisher).eraseToAnyPublisher()
}

return combinedPublisher
}
}
5 changes: 4 additions & 1 deletion Sources/Defaults/Utilities.swift
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift
Expand Up @@ -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))
}
}
2 changes: 1 addition & 1 deletion Tests/DefaultsTests/DefaultsArrayTests.swift
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/DefaultsTests/DefaultsDictionaryTests.swift
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/DefaultsTests/DefaultsNSSecureCodingTests.swift
Expand Up @@ -317,7 +317,7 @@ final class DefaultsNSSecureCodingTests: XCTestCase {
if counter == 2 {
expect.fulfill()
} else if counter > 2 {
XCTFail()
XCTFail() // swiftlint:disable:this xctfail_message
}
}

Expand Down
8 changes: 5 additions & 3 deletions Tests/DefaultsTests/DefaultsRangeTests.swift
Expand Up @@ -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 {
}

if lhs.month != rhs.month {
return lhs.month < rhs.month
} else {
return lhs.day < rhs.day
}

return lhs.day < rhs.day
}

static func == (lhs: CustomDate, rhs: CustomDate) -> Bool {
Expand Down
6 changes: 3 additions & 3 deletions Tests/DefaultsTests/DefaultsSetAlgebraTests.swift
Expand Up @@ -48,15 +48,15 @@ struct DefaultsSetAlgebra<Element: Defaults.Serializable & Hashable>: 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)
}
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/DefaultsTests/DefaultsTests.swift
Expand Up @@ -362,7 +362,7 @@ final class DefaultsTests: XCTestCase {
if counter == 2 {
expect.fulfill()
} else if counter > 2 {
XCTFail()
XCTFail() // swiftlint:disable:this xctfail_message
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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: []) {
Expand Down Expand Up @@ -713,7 +713,7 @@ final class DefaultsTests: XCTestCase {
sleep(1)

if index == 10 {
XCTFail()
XCTFail() // swiftlint:disable:this xctfail_message
}
}
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 957d807

Please sign in to comment.