Skip to content

Commit

Permalink
Enabled more swiftlint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
spinnerok committed Jan 27, 2023
1 parent aa5a061 commit 65831b9
Show file tree
Hide file tree
Showing 52 changed files with 222 additions and 467 deletions.
78 changes: 72 additions & 6 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ excluded:
- .build

line_length: 160

identifier_name:
max_length:
warning: 45
error: 60
min_length:
warning: 1

analyzer_rules:
disabled_rules:
- cyclomatic_complexity
- file_length
Expand All @@ -11,9 +20,66 @@ disabled_rules:
- todo
- type_body_length

identifier_name:
max_length:
warning: 45
error: 60
min_length:
warning: 1
opt_in_rules:
- array_init
- closure_end_indentation
- closure_spacing
- collection_alignment
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- discouraged_object_literal
- empty_count
- empty_string
- empty_xctest_method
- explicit_init
- extension_access_modifier
- fallthrough
# - file_header
# - file_name
- first_where
- flatmap_over_map_reduce
- identical_operands
- joined_default_parameter
- legacy_random
- let_var_whitespace
- last_where
- literal_expression_end_indentation
- lower_acl_than_parent
# - modifier_order
- nimble_operator
- nslocalizedstring_key
- number_separator
# - object_literal
- operator_usage_whitespace
- overridden_super_call
- override_in_extension
- pattern_matching_keywords
- private_action
- private_outlet
# - prohibited_interface_builder
- prohibited_super_call
- quick_discouraged_call
- quick_discouraged_focused_test
- quick_discouraged_pending_test
- reduce_into
- redundant_nil_coalescing
- redundant_type_annotation
- single_test_class
# - sorted_first_last
- sorted_imports
- static_operator
# - strong_iboutlet
- toggle_bool
- unavailable_function
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- xct_specific_matcher
- yoda_condition

number_separator:
minimum_length: 5
26 changes: 6 additions & 20 deletions CocoaMQTTTests/CocoaMQTTDeliverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@
// Copyright © 2019 emqtt.io. All rights reserved.
//

import XCTest
@testable import CocoaMQTT
import XCTest

class CocoaMQTTDeliverTests: XCTestCase {

override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testSerialDeliver() {
let caller = Caller()
let deliver = CocoaMQTTDeliver()
Expand All @@ -37,7 +28,6 @@ class CocoaMQTTDeliverTests: XCTestCase {
for i in 0 ..< frames.count {
assertEqual(frames[i], caller.frames[i])
}

}

func testAckMessage() {
Expand All @@ -64,7 +54,7 @@ class CocoaMQTTDeliverTests: XCTestCase {
XCTAssertEqual(inflights.count, 2)
XCTAssertEqual(deliver.t_queuedFrames().count, 0)
for i in 0 ..< inflights.count {
assertEqual(inflights[i], frames[i+1])
assertEqual(inflights[i], frames[i + 1])
}

deliver.ack(by: FramePubAck(msgid: 1))
Expand Down Expand Up @@ -99,10 +89,10 @@ class CocoaMQTTDeliverTests: XCTestCase {
deliver.mqueueSize = 1
deliver.delegate = caller

XCTAssertEqual(true, deliver.add(frames[1]))
XCTAssertTrue(deliver.add(frames[1]))
ms_sleep(100) // Wait the message transfer to inflight-window
XCTAssertEqual(true, deliver.add(frames[2]))
XCTAssertEqual(false, deliver.add(frames[0]))
XCTAssertTrue(deliver.add(frames[2]))
XCTAssertFalse(deliver.add(frames[0]))

ms_sleep(1100) // Wait for re-delivering timeout
XCTAssertEqual(caller.frames.count, 2)
Expand Down Expand Up @@ -132,7 +122,6 @@ class CocoaMQTTDeliverTests: XCTestCase {
}

func testStorage() {

let clientID = "deliver-unit-testing"
let caller = Caller()
let deliver = CocoaMQTTDeliver()
Expand Down Expand Up @@ -184,9 +173,7 @@ class CocoaMQTTDeliverTests: XCTestCase {
XCTAssertEqual(storage.readAll().count, 0)
}

func testTODO() {
// TODO: How to test large of messages combined qos0/qos1/qos2
}
// TODO: How to test large of messages combined qos0/qos1/qos2

// Helper for assert equality for Frame
private func assertEqual(_ f1: Frame, _ f2: Frame, _ lines: Int = #line) {
Expand All @@ -210,7 +197,6 @@ class CocoaMQTTDeliverTests: XCTestCase {
}

private class Caller: CocoaMQTTDeliverProtocol {

private let delegateQueueKey = DispatchSpecificKey<String>()
private let delegateQueueVal = "_custom_delegate_queue_"

Expand Down
11 changes: 1 addition & 10 deletions CocoaMQTTTests/CocoaMQTTStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@
// Copyright © 2019 emqtt.io. All rights reserved.
//

import XCTest
@testable import CocoaMQTT
import XCTest

class CocoaMQTTStorageTests: XCTestCase {

var clientId = "c1"

override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testStorage() {
let frames = [FramePublish(topic: "t/1", payload: [0x01], qos: .qos1, msgid: 1),
FramePublish(topic: "t/2", payload: [0x01], qos: .qos1, msgid: 2),
Expand Down
14 changes: 5 additions & 9 deletions CocoaMQTTTests/CocoaMQTTTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2015年 emqx.io. All rights reserved.
//

import XCTest
@testable import CocoaMQTT
import XCTest
#if IS_SWIFT_PACKAGE
@testable import CocoaMQTTWebSocket
#endif
Expand All @@ -21,7 +21,6 @@ private let delegateQueueKey = DispatchSpecificKey<String>()
private let delegateQueueVal = "_custom_delegate_queue_"

class CocoaMQTTTests: XCTestCase {

var deleQueue: DispatchQueue!

override func setUp() {
Expand Down Expand Up @@ -83,7 +82,6 @@ class CocoaMQTTTests: XCTestCase {
caller.isConnected == false
}
XCTAssertEqual(mqtt.connState, .disconnected)

}

// This is a basic test of the websocket authentication used by AWS IoT Custom Authorizers
Expand Down Expand Up @@ -229,7 +227,7 @@ class CocoaMQTTTests: XCTestCase {

mqtt.publish("t/1", withString: longStringGen(), qos: .qos2)
wait_for {
guard caller.recvs.count > 0 else {
guard !caller.recvs.isEmpty else {
return false
}
XCTAssertEqual(caller.recvs[0].topic, "t/1")
Expand Down Expand Up @@ -287,7 +285,7 @@ class CocoaMQTTTests: XCTestCase {

_ = mqtt.connect()
wait_for { caller.isConnected }
XCTAssertEqual(caller.isSSL, true)
XCTAssertTrue(caller.isSSL)
XCTAssertEqual(mqtt.connState, .connected)

mqtt.disconnect()
Expand All @@ -313,13 +311,12 @@ class CocoaMQTTTests: XCTestCase {

_ = mqtt.connect()
wait_for { caller.isConnected }
XCTAssertEqual(caller.isSSL, true)
XCTAssertTrue(caller.isSSL)
XCTAssertEqual(mqtt.connState, .connected)

mqtt.disconnect()
wait_for { caller.isConnected == false }
XCTAssertEqual(mqtt.connState, .disconnected)

}
}

Expand Down Expand Up @@ -387,7 +384,6 @@ extension CocoaMQTTTests {
}

private class Caller: CocoaMQTTDelegate {

var recvs = [FramePublish]()

var sents = [UInt16]()
Expand Down Expand Up @@ -434,7 +430,7 @@ private class Caller: CocoaMQTTDelegate {
func mqtt(_ mqtt: CocoaMQTT, didUnsubscribeTopics topics: [String]) {
assert_in_del_queue()

subs = subs.filter { (e) -> Bool in
subs = subs.filter { e -> Bool in
!topics.contains(e)
}
}
Expand Down
Loading

0 comments on commit 65831b9

Please sign in to comment.