Skip to content

Commit 70ec292

Browse files
authored
Merge pull request #398 from Vkt0r/danger
Integrate Danger and Swiftlint to the project
2 parents 7e07b39 + 6fe56f2 commit 70ec292

35 files changed

+695
-522
lines changed

.circleci/config.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
version: 2
22

33
jobs:
4+
danger:
5+
macos:
6+
xcode: 10.2.0
7+
steps:
8+
- checkout
9+
- run:
10+
name: Set Ruby Version
11+
command: echo "ruby-2.4" > ~/.ruby-version
12+
- restore_cache:
13+
key: 1-gems-{{ checksum "Gemfile.lock" }}
14+
- run:
15+
name: Install Ruby Dependencies
16+
command: bundle check || bundle install
17+
environment:
18+
BUNDLE_JOBS: 4
19+
BUNDLE_RETRY: 3
20+
- save_cache:
21+
key: 1-gems-{{ checksum "Gemfile.lock" }}
22+
paths:
23+
- vendor/bundle
24+
- run:
25+
name: Danger
26+
command: bundle exec danger
427
macos:
528
environment:
629
TEST_REPORTS: /tmp/test-results
@@ -51,5 +74,10 @@ workflows:
5174
version: 2
5275
tests:
5376
jobs:
54-
- linux
55-
- macos
77+
- danger
78+
- linux:
79+
requires:
80+
- danger
81+
- macos:
82+
requires:
83+
- danger

.swiftlint.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
2+
identifier_name:
3+
min_length: # only min_length
4+
warning: 2
5+
error: 2 # only error
6+
excluded: # excluded via string array
7+
- ok
8+
- Name
9+
- DEFAULT_MIME_TYPE
10+
- sin_port
11+
- no_sig_pipe
12+
113
disabled_rules:
214
- line_length
315
- statement_position
416
- trailing_whitespace
5-
- variable_name_min_length
17+
18+
excluded: # paths to ignore during linting. Takes precedence over `included`.
19+
- LinuxMain.swift
20+
- Tests/XCTestManifests.swift
21+
- Package.swift

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file. Changes not
2020

2121
## Added
2222
- A new `CHANGELOG.md` to keep track of changes in the project. ([#385](https://github.com/httpswift/swifter/pull/385)) by [@Vkt0r](https://github.com/Vkt0r)
23+
- Added [Danger](https://danger.systems/ruby/) and Swiftlint to the project. ([#398](https://github.com/httpswift/swifter/pull/398)) by [@Vkt0r](https://github.com/Vkt0r)
2324

2425
## Fixed
2526
- An issue in the `HttpRouter` causing issues to handle routes with overlapping in the tail. ([#379](https://github.com/httpswift/swifter/pull/359), [#382](https://github.com/httpswift/swifter/pull/382)) by [@Vkt0r](https://github.com/Vkt0r)

Dangerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# send a welcome message for the user
2+
message "Hey, @#{github.pr_author} 👋."
3+
4+
# Just to let people know
5+
warn("PR is classed as Work in Progress.") if github.pr_title.include? "[WIP]"
6+
7+
# Warn when there is a big PR
8+
warn("Big PR") if git.lines_of_code > 500
9+
10+
# ensure there is a summary for a PR
11+
fail "Please provide a summary in the Pull Request description." if github.pr_body.length < 5
12+
13+
# Changelog entries are required for changes to library files.
14+
fail("Please include a CHANGELOG entry. You can find it at [CHANGELOG.md](https://github.com/httpswift/swifter/blob/stable/CHANGELOG.md).") unless git.modified_files.include?("CHANGELOG.md") || git.added_files.include?("CHANGELOG.md")
15+
16+
# Don't accept PR on master for now
17+
fail "Please re-submit this PR to stable, you're trying to merge the PR on master." if github.branch_for_base == "master"
18+
19+
# If these are all empty something has gone wrong, better to raise it in a comment
20+
if git.modified_files.empty? && git.added_files.empty? && git.deleted_files.empty?
21+
fail "This PR has no changes at all, this is likely a developer issue."
22+
end
23+
24+
# Run SwiftLint
25+
swiftlint.config_file = '.swiftlint.yml'
26+
swiftlint.lint_files
27+
28+
# Warn when new tests are added but the XCTestManifests wasn't updated to run on Linux
29+
tests_added_or_modified = git.modified_files.grep(/XCode\/Tests/).empty? || git.added_files.grep(/XCode\/Tests/).empty?
30+
xc_manifest_updated = !git.modified_files.grep(/XCode\/Tests\/XCTestManifests.swift/).empty?
31+
if tests_added_or_modified && !xc_manifest_updated
32+
warn("It seems like you've added new tests to the library. If that's the case, please update the [XCTestManifests.swift](https://github.com/httpswift/swifter/blob/stable/XCode/Tests/XCTestManifests.swift) file running in your terminal the command `swift test --generate-linuxmain`.")
33+
34+
# This is a temporary warning to remove the entry for the failed test until we solve the issue in Linux
35+
warn("If you ran the command `swift test --generate-linuxmain` in your terminal, please remove the line `testCase(IOSafetyTests.__allTests__IOSafetyTests),` from `public func __allTests() -> [XCTestCaseEntry]` in the bottom of the file. For more reference see [#366](https://github.com/httpswift/swifter/issues/366).")
36+
end

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6+
7+
gem 'danger'
8+
gem 'danger-swiftlint'

Gemfile.lock

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
addressable (2.5.2)
5+
public_suffix (>= 2.0.2, < 4.0)
6+
claide (1.0.2)
7+
claide-plugins (0.9.2)
8+
cork
9+
nap
10+
open4 (~> 1.3)
11+
colored2 (3.1.2)
12+
cork (0.3.0)
13+
colored2 (~> 3.1)
14+
danger (6.0.6)
15+
claide (~> 1.0)
16+
claide-plugins (>= 0.9.2)
17+
colored2 (~> 3.1)
18+
cork (~> 0.1)
19+
faraday (~> 0.9)
20+
faraday-http-cache (~> 1.0)
21+
git (~> 1.5)
22+
kramdown (~> 2.0)
23+
kramdown-parser-gfm (~> 1.0)
24+
no_proxy_fix
25+
octokit (~> 4.7)
26+
terminal-table (~> 1)
27+
danger-swiftlint (0.20.1)
28+
danger
29+
rake (> 10)
30+
thor (~> 0.19)
31+
faraday (0.15.4)
32+
multipart-post (>= 1.2, < 3)
33+
faraday-http-cache (1.3.1)
34+
faraday (~> 0.8)
35+
git (1.5.0)
36+
kramdown (2.1.0)
37+
kramdown-parser-gfm (1.0.1)
38+
kramdown (~> 2.0)
39+
multipart-post (2.0.0)
40+
nap (1.1.0)
41+
no_proxy_fix (0.1.2)
42+
octokit (4.14.0)
43+
sawyer (~> 0.8.0, >= 0.5.3)
44+
open4 (1.3.4)
45+
public_suffix (3.0.3)
46+
rake (12.3.2)
47+
sawyer (0.8.1)
48+
addressable (>= 2.3.5, < 2.6)
49+
faraday (~> 0.8, < 1.0)
50+
terminal-table (1.8.0)
51+
unicode-display_width (~> 1.1, >= 1.1.1)
52+
thor (0.20.3)
53+
unicode-display_width (1.5.0)
54+
55+
PLATFORMS
56+
ruby
57+
58+
DEPENDENCIES
59+
danger
60+
danger-swiftlint
61+
62+
BUNDLED WITH
63+
1.16.5

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let package = Package(
1313
dependencies: [],
1414

1515
targets: [
16-
.target(name: "Swifter", dependencies: [], path: "Sources"),
16+
.target(name: "Swifter", dependencies: [], path: "XCode/Sources"),
1717
.target(name: "Example", dependencies: ["Swifter"], path: "Example"),
1818
.testTarget(name: "SwifterTests", dependencies: ["Swifter"], path: "XCode/Tests")
1919
]
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
10+
// swiftlint:disable function_body_length
1111
public func demoServer(_ publicDir: String) -> HttpServer {
1212

1313
print(publicDir)
@@ -32,17 +32,17 @@ public func demoServer(_ publicDir: String) -> HttpServer {
3232

3333
server["/magic"] = { .ok(.html("You asked for " + $0.path)) }
3434

35-
server["/test/:param1/:param2"] = { r in
35+
server["/test/:param1/:param2"] = { request in
3636
scopes {
3737
html {
3838
body {
39-
h3 { inner = "Address: \(r.address ?? "unknown")" }
40-
h3 { inner = "Url: \(r.path)" }
41-
h3 { inner = "Method: \(r.method)" }
39+
h3 { inner = "Address: \(request.address ?? "unknown")" }
40+
h3 { inner = "Url: \(request.path)" }
41+
h3 { inner = "Method: \(request.method)" }
4242

4343
h3 { inner = "Query:" }
4444

45-
table(r.queryParams) { param in
45+
table(request.queryParams) { param in
4646
tr {
4747
td { inner = param.0 }
4848
td { inner = param.1 }
@@ -51,7 +51,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
5151

5252
h3 { inner = "Headers:" }
5353

54-
table(r.headers) { header in
54+
table(request.headers) { header in
5555
tr {
5656
td { inner = header.0 }
5757
td { inner = header.1 }
@@ -60,15 +60,15 @@ public func demoServer(_ publicDir: String) -> HttpServer {
6060

6161
h3 { inner = "Route params:" }
6262

63-
table(r.params) { param in
63+
table(request.params) { param in
6464
tr {
6565
td { inner = param.0 }
6666
td { inner = param.1 }
6767
}
6868
}
6969
}
7070
}
71-
}(r)
71+
}(request)
7272
}
7373

7474
server.GET["/upload"] = scopes {
@@ -92,9 +92,9 @@ public func demoServer(_ publicDir: String) -> HttpServer {
9292
}
9393
}
9494

95-
server.POST["/upload"] = { r in
95+
server.POST["/upload"] = { request in
9696
var response = ""
97-
for multipart in r.parseMultiPartFormData() {
97+
for multipart in request.parseMultiPartFormData() {
9898
guard let name = multipart.name, let fileName = multipart.fileName else { continue }
9999
response += "Name: \(name) File name: \(fileName) Size: \(multipart.body.count)<br>"
100100
}
@@ -134,8 +134,8 @@ public func demoServer(_ publicDir: String) -> HttpServer {
134134
}
135135
}
136136

137-
server.POST["/login"] = { r in
138-
let formFields = r.parseUrlencodedForm()
137+
server.POST["/login"] = { request in
138+
let formFields = request.parseUrlencodedForm()
139139
return HttpResponse.ok(.html(formFields.map({ "\($0.0) = \($0.1)" }).joined(separator: "<br>")))
140140
}
141141

@@ -150,32 +150,32 @@ public func demoServer(_ publicDir: String) -> HttpServer {
150150
}
151151
}
152152

153-
server["/raw"] = { r in
153+
server["/raw"] = { _ in
154154
return HttpResponse.raw(200, "OK", ["XXX-Custom-Header": "value"], { try $0.write([UInt8]("test".utf8)) })
155155
}
156156

157-
server["/redirect/permanently"] = { r in
157+
server["/redirect/permanently"] = { _ in
158158
return .movedPermanently("http://www.google.com")
159159
}
160160

161-
server["/redirect/temporarily"] = { r in
161+
server["/redirect/temporarily"] = { _ in
162162
return .movedTemporarily("http://www.google.com")
163163
}
164164

165-
server["/long"] = { r in
165+
server["/long"] = { _ in
166166
var longResponse = ""
167-
for k in 0..<1000 { longResponse += "(\(k)),->" }
167+
for index in 0..<1000 { longResponse += "(\(index)),->" }
168168
return .ok(.html(longResponse))
169169
}
170170

171-
server["/wildcard/*/test/*/:param"] = { r in
172-
return .ok(.html(r.path))
171+
server["/wildcard/*/test/*/:param"] = { request in
172+
return .ok(.html(request.path))
173173
}
174174

175-
server["/stream"] = { r in
176-
return HttpResponse.raw(200, "OK", nil, { w in
177-
for i in 0...100 {
178-
try w.write([UInt8]("[chunk \(i)]".utf8))
175+
server["/stream"] = { _ in
176+
return HttpResponse.raw(200, "OK", nil, { writer in
177+
for index in 0...100 {
178+
try writer.write([UInt8]("[chunk \(index)]".utf8))
179179
}
180180
})
181181
}
@@ -184,20 +184,20 @@ public func demoServer(_ publicDir: String) -> HttpServer {
184184
session.writeText(text)
185185
}, binary: { (session, binary) in
186186
session.writeBinary(binary)
187-
}, pong: { (session, pong) in
187+
}, pong: { (_, _) in
188188
// Got a pong frame
189-
}, connected: { (session) in
189+
}, connected: { _ in
190190
// New client connected
191-
}, disconnected: { (session) in
191+
}, disconnected: { _ in
192192
// Client disconnected
193193
})
194194

195-
server.notFoundHandler = { r in
195+
server.notFoundHandler = { _ in
196196
return .movedPermanently("https://github.com/404")
197197
}
198198

199-
server.middleware.append { r in
200-
print("Middleware: \(r.address ?? "unknown address") -> \(r.method) -> \(r.path)")
199+
server.middleware.append { request in
200+
print("Middleware: \(request.address ?? "unknown address") -> \(request.method) -> \(request.path)")
201201
return nil
202202
}
203203

0 commit comments

Comments
 (0)