Skip to content

Commit 8db2708

Browse files
committed
Add the trailing whitespace rule in Swiftlint
* Autocorrect the new rule in Swiftlint to remove all the trailing whitespaces * Update the CHANGELOG
1 parent 8b5afb4 commit 8db2708

32 files changed

+352
-352
lines changed

.swiftlint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ identifier_name:
1313
disabled_rules:
1414
- line_length
1515
- statement_position
16-
- trailing_whitespace
1716

1817
excluded: # paths to ignore during linting. Takes precedence over `included`.
1918
- LinuxMain.swift

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ All notable changes to this project will be documented in this file. Changes not
1818
1919
# [Unreleased]
2020

21-
* Nothing yet.
21+
## Added
22+
23+
- Add the `trailing_whitespace` rule in Swiftlint and autocorrect all the source files. ([#416](https://github.com/httpswift/swifter/pull/416)) by [@Vkt0r](https://github.com/Vkt0r)
2224

2325
# [1.4.7]
2426

XCode/Sources/DemoServer.swift

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import Foundation
99

1010
// swiftlint:disable function_body_length
1111
public func demoServer(_ publicDir: String) -> HttpServer {
12-
12+
1313
print(publicDir)
14-
14+
1515
let server = HttpServer()
16-
16+
1717
server["/public/:path"] = shareFilesFromDirectory(publicDir)
1818

1919
server["/files/:path"] = directoryBrowser("/")
@@ -29,37 +29,37 @@ public func demoServer(_ publicDir: String) -> HttpServer {
2929
}
3030
}
3131
}
32-
32+
3333
server["/magic"] = { .ok(.htmlBody("You asked for " + $0.path)) }
34-
34+
3535
server["/test/:param1/:param2"] = { request in
3636
scopes {
3737
html {
3838
body {
3939
h3 { inner = "Address: \(request.address ?? "unknown")" }
4040
h3 { inner = "Url: \(request.path)" }
4141
h3 { inner = "Method: \(request.method)" }
42-
42+
4343
h3 { inner = "Query:" }
44-
44+
4545
table(request.queryParams) { param in
4646
tr {
4747
td { inner = param.0 }
4848
td { inner = param.1 }
4949
}
5050
}
51-
51+
5252
h3 { inner = "Headers:" }
53-
53+
5454
table(request.headers) { header in
5555
tr {
5656
td { inner = header.0 }
5757
td { inner = header.1 }
5858
}
5959
}
60-
60+
6161
h3 { inner = "Route params:" }
62-
62+
6363
table(request.params) { param in
6464
tr {
6565
td { inner = param.0 }
@@ -70,19 +70,19 @@ public func demoServer(_ publicDir: String) -> HttpServer {
7070
}
7171
}(request)
7272
}
73-
73+
7474
server.GET["/upload"] = scopes {
7575
html {
7676
body {
7777
form {
7878
method = "POST"
7979
action = "/upload"
8080
enctype = "multipart/form-data"
81-
81+
8282
input { name = "my_file1"; type = "file" }
8383
input { name = "my_file2"; type = "file" }
8484
input { name = "my_file3"; type = "file" }
85-
85+
8686
button {
8787
type = "submit"
8888
inner = "Upload"
@@ -91,7 +91,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
9191
}
9292
}
9393
}
94-
94+
9595
server.POST["/upload"] = { request in
9696
var response = ""
9797
for multipart in request.parseMultiPartFormData() {
@@ -100,7 +100,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
100100
}
101101
return HttpResponse.ok(.htmlBody(response))
102102
}
103-
103+
104104
server.GET["/login"] = scopes {
105105
html {
106106
head {
@@ -109,11 +109,11 @@ public func demoServer(_ publicDir: String) -> HttpServer {
109109
}
110110
body {
111111
h3 { inner = "Sign In" }
112-
112+
113113
form {
114114
method = "POST"
115115
action = "/login"
116-
116+
117117
fieldset {
118118
input { placeholder = "E-mail"; name = "email"; type = "email"; autofocus = "" }
119119
input { placeholder = "Password"; name = "password"; type = "password"; autofocus = "" }
@@ -125,20 +125,20 @@ public func demoServer(_ publicDir: String) -> HttpServer {
125125
}
126126
}
127127
}
128-
128+
129129
}
130130
javascript {
131131
src = "http://cdn.staticfile.org/twitter-bootstrap/3.3.0/js/bootstrap.min.js"
132132
}
133133
}
134134
}
135135
}
136-
136+
137137
server.POST["/login"] = { request in
138138
let formFields = request.parseUrlencodedForm()
139139
return HttpResponse.ok(.htmlBody(formFields.map({ "\($0.0) = \($0.1)" }).joined(separator: "<br>")))
140140
}
141-
141+
142142
server["/demo"] = scopes {
143143
html {
144144
body {
@@ -149,15 +149,15 @@ public func demoServer(_ publicDir: String) -> HttpServer {
149149
}
150150
}
151151
}
152-
152+
153153
server["/raw"] = { _ in
154154
return HttpResponse.raw(200, "OK", ["XXX-Custom-Header": "value"], { try $0.write([UInt8]("test".utf8)) })
155155
}
156-
156+
157157
server["/redirect/permanently"] = { _ in
158158
return .movedPermanently("http://www.google.com")
159159
}
160-
160+
161161
server["/redirect/temporarily"] = { _ in
162162
return .movedTemporarily("http://www.google.com")
163163
}
@@ -167,19 +167,19 @@ public func demoServer(_ publicDir: String) -> HttpServer {
167167
for index in 0..<1000 { longResponse += "(\(index)),->" }
168168
return .ok(.htmlBody(longResponse))
169169
}
170-
170+
171171
server["/wildcard/*/test/*/:param"] = { request in
172172
return .ok(.htmlBody(request.path))
173173
}
174-
174+
175175
server["/stream"] = { _ in
176176
return HttpResponse.raw(200, "OK", nil, { writer in
177177
for index in 0...100 {
178178
try writer.write([UInt8]("[chunk \(index)]".utf8))
179179
}
180180
})
181181
}
182-
182+
183183
server["/websocket-echo"] = websocket(text: { (session, text) in
184184
session.writeText(text)
185185
}, binary: { (session, binary) in
@@ -191,16 +191,15 @@ public func demoServer(_ publicDir: String) -> HttpServer {
191191
}, disconnected: { _ in
192192
// Client disconnected
193193
})
194-
194+
195195
server.notFoundHandler = { _ in
196196
return .movedPermanently("https://github.com/404")
197197
}
198-
198+
199199
server.middleware.append { request in
200200
print("Middleware: \(request.address ?? "unknown address") -> \(request.method) -> \(request.path)")
201201
return nil
202202
}
203-
203+
204204
return server
205205
}
206-

XCode/Sources/Errno.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
public class Errno {
11-
11+
1212
public class func description() -> String {
1313
// https://forums.developer.apple.com/thread/113919
1414
return String(cString: strerror(errno))

XCode/Sources/Files.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ public func shareFilesFromDirectory(_ directoryPath: String, defaults: [String]
3535
}
3636
}
3737
let filePath = directoryPath + String.pathSeparator + fileRelativePath.value
38-
38+
3939
if let file = try? filePath.openForReading() {
4040
let mimeType = fileRelativePath.value.mimeType()
4141
var responseHeader: [String: String] = ["Content-Type": mimeType]
42-
42+
4343
if let attr = try? FileManager.default.attributesOfItem(atPath: filePath),
4444
let fileSize = attr[FileAttributeKey.size] as? UInt64 {
4545
responseHeader["Content-Length"] = String(fileSize)
4646
}
47-
47+
4848
return .raw(200, "OK", responseHeader, { writer in
4949
try? writer.write(file)
5050
file.close()

XCode/Sources/HttpParser.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ enum HttpParserError: Error {
1212
}
1313

1414
public class HttpParser {
15-
15+
1616
public init() { }
17-
17+
1818
public func readHttpRequest(_ socket: Socket) throws -> HttpRequest {
1919
let statusLine = try socket.readLine()
2020
let statusLineTokens = statusLine.components(separatedBy: " ")
@@ -36,7 +36,7 @@ public class HttpParser {
3636
private func readBody(_ socket: Socket, size: Int) throws -> [UInt8] {
3737
return try socket.read(length: size)
3838
}
39-
39+
4040
private func readHeaders(_ socket: Socket) throws -> [String: String] {
4141
var headers = [String: String]()
4242
while case let headerLine = try socket.readLine(), !headerLine.isEmpty {
@@ -47,7 +47,7 @@ public class HttpParser {
4747
}
4848
return headers
4949
}
50-
50+
5151
func supportsKeepAlive(_ headers: [String: String]) -> Bool {
5252
if let value = headers["connection"] {
5353
return "keep-alive" == value.trimmingCharacters(in: .whitespaces)

XCode/Sources/HttpRequest.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88
import Foundation
99

1010
public class HttpRequest {
11-
11+
1212
public var path: String = ""
1313
public var queryParams: [(String, String)] = []
1414
public var method: String = ""
1515
public var headers: [String: String] = [:]
1616
public var body: [UInt8] = []
1717
public var address: String? = ""
1818
public var params: [String: String] = [:]
19-
19+
2020
public init() {}
21-
21+
2222
public func hasTokenForHeader(_ headerName: String, token: String) -> Bool {
2323
guard let headerValue = headers[headerName] else {
2424
return false
2525
}
2626
return headerValue.components(separatedBy: ",").filter({ $0.trimmingCharacters(in: .whitespaces).lowercased() == token }).count > 0
2727
}
28-
28+
2929
public func parseUrlencodedForm() -> [(String, String)] {
3030
guard let contentTypeHeader = headers["content-type"] else {
3131
return []
@@ -47,20 +47,20 @@ public class HttpRequest {
4747
return ("", "")
4848
}
4949
}
50-
50+
5151
public struct MultiPart {
52-
52+
5353
public let headers: [String: String]
5454
public let body: [UInt8]
55-
55+
5656
public var name: String? {
5757
return valueFor("content-disposition", parameter: "name")?.unquote()
5858
}
59-
59+
6060
public var fileName: String? {
6161
return valueFor("content-disposition", parameter: "filename")?.unquote()
6262
}
63-
63+
6464
private func valueFor(_ headerName: String, parameter: String) -> String? {
6565
return headers.reduce([String]()) { (combined, header: (key: String, value: String)) -> [String] in
6666
guard header.key == headerName else {
@@ -77,7 +77,7 @@ public class HttpRequest {
7777
}.first
7878
}
7979
}
80-
80+
8181
public func parseMultiPartFormData() -> [MultiPart] {
8282
guard let contentTypeHeader = headers["content-type"] else {
8383
return []
@@ -98,7 +98,7 @@ public class HttpRequest {
9898
}
9999
return []
100100
}
101-
101+
102102
private func parseMultiPartFormData(_ data: [UInt8], boundary: String) -> [MultiPart] {
103103
var generator = data.makeIterator()
104104
var result = [MultiPart]()
@@ -107,7 +107,7 @@ public class HttpRequest {
107107
}
108108
return result
109109
}
110-
110+
111111
private func nextMultiPart(_ generator: inout IndexingIterator<[UInt8]>, boundary: String, isFirst: Bool) -> MultiPart? {
112112
if isFirst {
113113
guard nextUTF8MultiPartLine(&generator) == boundary else {
@@ -128,7 +128,7 @@ public class HttpRequest {
128128
}
129129
return MultiPart(headers: headers, body: body)
130130
}
131-
131+
132132
private func nextUTF8MultiPartLine(_ generator: inout IndexingIterator<[UInt8]>) -> String? {
133133
var temp = [UInt8]()
134134
while let value = generator.next() {
@@ -141,11 +141,11 @@ public class HttpRequest {
141141
}
142142
return String(bytes: temp, encoding: String.Encoding.utf8)
143143
}
144-
144+
145145
// swiftlint:disable identifier_name
146146
static let CR = UInt8(13)
147147
static let NL = UInt8(10)
148-
148+
149149
private func nextMultiPartBody(_ generator: inout IndexingIterator<[UInt8]>, boundary: String) -> [UInt8]? {
150150
var body = [UInt8]()
151151
let boundaryArray = [UInt8](boundary.utf8)

XCode/Sources/HttpResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public protocol HttpResponseBodyWriter {
2121
}
2222

2323
public enum HttpResponseBody {
24-
24+
2525
case json(Any)
2626
case html(String)
2727
case htmlBody(String)

0 commit comments

Comments
 (0)