Skip to content

Commit 20b9a74

Browse files
authored
tech(swiftlint): Fix warnings (#20)
1 parent ecf2743 commit 20b9a74

File tree

16 files changed

+111
-87
lines changed

16 files changed

+111
-87
lines changed

.github/workflows/doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- main
77

88
jobs:
9-
test:
9+
doc:
1010
runs-on: macos-latest
1111

1212
steps:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
uses: actions/checkout@v2
1818

1919
- name: Lint code
20-
uses: swiftlint lint
20+
run: swiftlint lint
2121

2222
- name: Run tests
2323
run: swift test --enable-test-discovery

.swiftlint.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ opt_in_rules:
1616
- empty_count
1717
- indentation_width
1818

19-
line_length: 120
20-
warning_threshold: 0
19+
line_length:
20+
warning: 120
21+
ignores_comments: true
22+
warning_threshold: 1

Sources/SimpleHTTP/MultipartForm/MultipartFormData.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,25 @@ public struct MultipartFormData {
176176
private func mimeType(from url: URL) -> String {
177177
if #available(iOS 14.0, *), #available(macOS 11.0, *) {
178178
guard let type = UTType(filenameExtension: url.pathExtension), let mime = type.preferredMIMEType else {
179-
return HTTPContentType.octetStream.value
179+
return HTTPContentType.octetStream.value
180180
}
181+
181182
return mime
182-
} else {
183-
if let id = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, url.pathExtension as CFString, nil)?.takeRetainedValue(),
184-
let contentType = UTTypeCopyPreferredTagWithClass(id, kUTTagClassMIMEType)?.takeRetainedValue() {
185-
return contentType as String
186-
}
187-
return HTTPContentType.octetStream.value
188183
}
184+
185+
let contentType = UTTypeCreatePreferredIdentifierForTag(
186+
kUTTagClassFilenameExtension,
187+
url.pathExtension as CFString,
188+
nil
189+
)
190+
.flatMap { UTTypeCopyPreferredTagWithClass($0.takeRetainedValue(), kUTTagClassMIMEType) }
191+
.map { $0.takeRetainedValue() }
192+
193+
if let contentType = contentType {
194+
return contentType as String
195+
}
196+
197+
return HTTPContentType.octetStream.value
189198
}
190199

191200
}

Sources/SimpleHTTP/MultipartForm/MultipartFormDataEncoder.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ struct MultipartFormDataEncoder {
2020
var encoded = Data()
2121

2222
if var first = bodyParts.first {
23-
first.hasInitialBoundary = true
24-
bodyParts[0] = first
23+
first.hasInitialBoundary = true
24+
bodyParts[0] = first
2525
}
2626

2727
if var last = bodyParts.last {
28-
last.hasFinalBoundary = true
29-
bodyParts[bodyParts.count - 1] = last
28+
last.hasFinalBoundary = true
29+
bodyParts[bodyParts.count - 1] = last
3030
}
3131

3232
for bodyPart in bodyParts {
33-
encoded.append(try encodeBodyPart(bodyPart))
33+
encoded.append(try encodeBodyPart(bodyPart))
3434
}
3535

3636
return encoded

Sources/SimpleHTTP/MultipartForm/URLRequest+Multipart.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import FoundationNetworking
66

77
extension URLRequest {
88
public mutating func multipartBody(_ body: MultipartFormData) throws {
9-
var multipartEncode = MultipartFormDataEncoder(body: body)
9+
var multipartEncode = MultipartFormDataEncoder(body: body)
1010

11-
httpBody = try multipartEncode.encode()
11+
httpBody = try multipartEncode.encode()
1212

13-
setHeaders([.contentType: HTTPContentType.multipart(boundary: body.boundary).value])
13+
setHeaders([.contentType: HTTPContentType.multipart(boundary: body.boundary).value])
1414
}
1515
}

Sources/SimpleHTTP/Request/Path.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public struct Path: Equatable, ExpressibleByStringLiteral, ExpressibleByStringIn
3737
self.init(value: stringInterpolation.description)
3838
}
3939

40-
public static func ==(lhs: Path, rhs: String) -> Bool {
40+
public static func == (lhs: Path, rhs: String) -> Bool {
4141
lhs.value == rhs
4242
}
4343
}

Sources/SimpleHTTP/Request/Request+URLRequest.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ extension Request {
99
/// - Parameter encoder: the encoder to use to encode the body is present
1010
/// - Parameter relativeTo: the base URL to append to the request path
1111
/// - Parameter accepting: if not nil will be used to set "Accept" header value
12-
public func toURLRequest(encoder: ContentDataEncoder, relativeTo baseURL: URL, accepting: ContentDataDecoder? = nil) throws -> URLRequest {
12+
public func toURLRequest(
13+
encoder: ContentDataEncoder,
14+
relativeTo baseURL: URL,
15+
accepting: ContentDataDecoder? = nil
16+
) throws -> URLRequest {
1317
let request = try toURLRequest(encoder: encoder)
1418
.relativeTo(baseURL)
1519

Sources/SimpleHTTP/Response/URLSession+DataResponse.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extension URLSession {
88
public func data(for urlRequest: URLRequest) async throws -> URLDataResponse {
99
let (data, response) = try await data(for: urlRequest)
1010

11+
// swiftlint:disable force_cast
1112
return URLDataResponse(data: data, response: response as! HTTPURLResponse)
13+
// swiftlint:enable force_cast
1214
}
1315
}

Sources/SimpleHTTP/Session/SessionConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public struct SessionConfiguration {
3737
interceptors: CompositeInterceptor = [],
3838
dataError: DataError.Type
3939
) {
40-
self.init(encoder: encoder, decoder: decoder, decodingQueue: decodingQueue, interceptors: interceptors)
40+
self.init(encoder: encoder, decoder: decoder, decodingQueue: decodingQueue, interceptors: interceptors)
4141
self.errorConverter = {
4242
try decoder.decode(dataError, from: $0)
4343
}

0 commit comments

Comments
 (0)