Skip to content

Commit d3c3d79

Browse files
Mark Pospeselmpospese
authored andcommitted
[CM-997] Add linter rules, fix violations
1 parent 183da6b commit d3c3d79

File tree

9 files changed

+33
-6
lines changed

9 files changed

+33
-6
lines changed

.swiftlint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ opt_in_rules: # some rules are turned off by default, so you need to opt-in
99
- empty_count
1010
- first_where
1111
- force_unwrapping
12+
- implicit_return
13+
- missing_docs
1214
- multiline_arguments
1315
- multiline_arguments_brackets
1416
- multiline_function_chains
@@ -24,6 +26,8 @@ opt_in_rules: # some rules are turned off by default, so you need to opt-in
2426

2527
excluded: # paths to ignore during linting. Takes precedence over `included`.
2628
- Pods
29+
- docs
30+
- .build
2731

2832
# configurable rules can be customized from this configuration file
2933
# binary rules can set their severity level

Sources/YNetwork/Core/Extensions/String+regex.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension String {
1414
/// - Parameter pattern: the regular expression pattern to evaluate
1515
/// - Returns: `true` if the string matches the pattern, otherwise `false`.
1616
public func matches(regex pattern: String) -> Bool {
17-
return self.range(
17+
range(
1818
of: pattern,
1919
options: .regularExpression,
2020
range: nil,

Sources/YNetwork/Extensions/String+isAbsoluteURLPath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ let kUrlSchemaRegex = "^(ht|f)tp(s?)\\:\\/\\/"
1515
extension String {
1616
/// Determines whether the string begins with `http://`, `https://`, `ftp://`, or `ftps://`
1717
public var isAbsoluteURLPath: Bool {
18-
return self.matches(regex: kUrlSchemaRegex)
18+
matches(regex: kUrlSchemaRegex)
1919
}
2020
}

Sources/YNetwork/Models/JWT/JWTToken.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ import Foundation
1010

1111
/// JWT token.
1212
public struct JWTToken {
13+
/// JWT token header
1314
public let header: [String: Any]
15+
/// JWT token body
1416
public let body: [String: Any]
17+
/// JWT token signature
1518
public let signature: String?
19+
/// Original JWT token string
1620
public let string: String
1721

1822
/// public init method

Sources/YNetwork/NetworkManager/NetworkManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ open class NetworkManager: NSObject {
3030
@available(iOS 14.0, tvOS 14.0, *)
3131
open var logger: Logger? {
3232
get {
33-
return _logger as? Logger
33+
_logger as? Logger
3434
} set {
3535
_logger = newValue
3636
}

Sources/YNetwork/Protocols/MultipartRequest.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ public protocol MultipartRequest: NetworkRequest {
1818

1919
/// Default implementation for Multipart Request properties.
2020
public extension MultipartRequest {
21+
/// Uses `.POST` HTTP method
2122
var method: HttpMethod { .POST }
23+
24+
/// Sets `.multipart` as request content type
2225
var requestType: RequestContentType {
2326
.multipart(boundary: multipart.boundary)
2427
}
28+
29+
/// Sets the `multipart` builder as the body
2530
var body: BodyBuilder? { multipart }
2631
}

Sources/YNetwork/Protocols/NetworkRequest.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,36 @@ public protocol NetworkRequest {
7979
/// Default implementation for Network Request properties.
8080
/// The only required property to implement is `path`. Everything else has default values.
8181
public extension NetworkRequest {
82+
/// Uses no base path
8283
var basePath: PathRepresentable? { nil }
8384

85+
/// Uses `.GET` HTTP method
8486
var method: HttpMethod { .GET }
8587

88+
/// Includes no additional headers
8689
var headers: HttpHeaders? { nil }
8790

91+
/// Sets `.JSON` as request content type
8892
var requestType: RequestContentType { .JSON }
8993

94+
/// Sets `.JSON` as response content type
9095
var responseType: ResponseContentType { .JSON }
9196

97+
/// No query parameters
9298
var queryParameters: ParametersBuilder? { nil }
9399

100+
/// No body
94101
var body: BodyBuilder? { nil }
95102

103+
/// Uses the default timeout interval
96104
var timeoutInterval: TimeInterval { 0 }
97105

106+
/// Uses the default cache policy
98107
var cachePolicy: URLRequest.CachePolicy? { nil }
99-
108+
109+
/// Uses the default parser factory
100110
var parserFactory: DataParserFactory? { nil }
101111

112+
/// Uses session tokens (if `NetworkManager.sessionManager` is specified)
102113
var usesSession: Bool { true }
103114
}

Tests/YNetworkTests/NetworkManager/Helpers/MockURLNetworkEngine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ final class MockURLNetworkEngine: URLNetworkEngine {
3737
}
3838

3939
override func submitBackgroundDownload(_ request: URLRequest) throws -> Cancelable {
40-
return MockURLSessionTask()
40+
MockURLSessionTask()
4141
}
4242

4343
override func submitBackgroundUpload(_ request: URLRequest, fileUrl: URL) throws -> Cancelable {
44-
return MockURLSessionTask()
44+
MockURLSessionTask()
4545
}
4646
}
4747

Tests/YNetworkTests/NetworkManager/URLBuilderTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import XCTest
1010
@testable import YNetwork
1111

12+
// Large tuples help us build unit test expectations concisely
13+
// swiftlint:disable large_tuple
14+
1215
typealias PathTestCase = (basePath: PathTestUrl?, path: String, output: String)
1316
typealias FormUrlTestCase = (key: String, value: Any, output: String?)
1417
typealias QueryTestCase = (params: Parameters, output: String)

0 commit comments

Comments
 (0)