Skip to content

Commit f322911

Browse files
Merge #237
237: Run autocorrect with swiftlint r=bidoubiwa a=brunoocasali Related to #235 All changes were made automatically by swiftlint. Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
2 parents a9c5693 + f4baaaa commit f322911

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+62
-505
lines changed

Demos/PerfectDemo/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ let package = Package(
1515
.target(name: "PerfectTemplate", dependencies: [
1616
.product(name: "PerfectHTTPServer"),
1717
.product(name: "MeiliSearch", package: "meilisearch-swift")
18-
])
18+
])
1919
]
2020
)

Demos/PerfectDemo/Sources/PerfectTemplate/main.swift

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ private let client = try! MeiliSearch(host: "http://localhost:7700", apiKey: "ma
2727
// swiftlint:disable force_try
2828

2929
private struct Movie: Codable, Equatable {
30-
3130
let id: Int
3231
let title: String
3332
let comment: String?
@@ -37,12 +36,10 @@ private struct Movie: Codable, Equatable {
3736
self.title = title
3837
self.comment = comment
3938
}
40-
4139
}
4240

4341
// 127.0.0.1:8181/index?uid=books_test
4442
func index(request: HTTPRequest, response: HTTPResponse) {
45-
4643
guard let uid: String = request.param(name: "uid") else {
4744
response.setHeader(.contentType, value: "application/json")
4845
let body = """
@@ -57,13 +54,12 @@ func index(request: HTTPRequest, response: HTTPResponse) {
5754
}
5855

5956
client.getIndex(uid) { result in
60-
6157
switch result {
6258
case .success(let index):
6359

64-
let encoder: JSONEncoder = JSONEncoder()
60+
let encoder = JSONEncoder()
6561
let data: Data = try! encoder.encode(index)
66-
let body: String = String(decoding: data, as: UTF8.self)
62+
let body = String(decoding: data, as: UTF8.self)
6763

6864
response.setHeader(.contentType, value: "application/json")
6965
response.appendBody(string: body)
@@ -79,18 +75,14 @@ func index(request: HTTPRequest, response: HTTPResponse) {
7975

8076
response.setHeader(.contentType, value: "application/json")
8177
response.appendBody(string: body)
82-
8378
}
8479

8580
response.completed()
86-
8781
}
88-
8982
}
9083

9184
// 127.0.0.1:8181/search?query=botman
9285
func search(request: HTTPRequest, response: HTTPResponse) {
93-
9486
guard let query: String = request.param(name: "query") else {
9587
response.setHeader(.contentType, value: "application/json")
9688
let body = """
@@ -107,14 +99,13 @@ func search(request: HTTPRequest, response: HTTPResponse) {
10799
let searchParameters = SearchParameters.query(query)
108100

109101
client.index("books_test").search(searchParameters) { (result: Result<SearchResult<Movie>, Swift.Error>) in
110-
111102
switch result {
112103
case .success(let searchResult):
113104

114105
let jsonData = try! JSONSerialization.data(
115106
withJSONObject: searchResult.hits,
116107
options: [])
117-
let body: String = String(decoding: jsonData, as: UTF8.self)
108+
let body = String(decoding: jsonData, as: UTF8.self)
118109

119110
response.setHeader(.contentType, value: "application/json")
120111
response.appendBody(string: body)
@@ -130,13 +121,10 @@ func search(request: HTTPRequest, response: HTTPResponse) {
130121

131122
response.setHeader(.contentType, value: "application/json")
132123
response.appendBody(string: body)
133-
134124
}
135125

136126
response.completed()
137-
138127
}
139-
140128
}
141129

142130
var routes = Routes()

Demos/VaporDemo/Sources/App/routes.swift

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Vapor
22
import MeiliSearch
33

44
private struct Movie: Codable, Equatable {
5-
65
// swiftlint:disable identifier_name
76
let id: Int
87
// swiftlint:enable identifier_name
@@ -14,46 +13,39 @@ private struct Movie: Codable, Equatable {
1413
self.title = title
1514
self.comment = comment
1615
}
17-
1816
}
1917

2018
func routes(_ app: Application) throws {
21-
2219
guard let client = try? MeiliSearch(host: "127.0.0.1:7700", apiKey: "masterKey") else {
2320
throw NSError(domain: "Failed to initialize MeiliSearch", code: 123)
2421
}
2522

2623
// 127.0.0.1:8080/index?uid=books_test
2724
app.get("index") { req -> EventLoopFuture<String> in
28-
2925
/// Create a new void promise
3026
let promise = req.eventLoop.makePromise(of: String.self)
3127

3228
/// Dispatch some work to happen on a background thread
3329
req.application.threadPool.submit { _ in
34-
3530
guard let uid: String = req.query["uid"] else {
3631
promise.fail(Abort(.badRequest))
3732
return
3833
}
3934

4035
client.getIndex(uid) { result in
41-
4236
switch result {
4337
case .success(let index):
4438

45-
let encoder: JSONEncoder = JSONEncoder()
39+
let encoder = JSONEncoder()
4640
if let data: Data = try? encoder.encode(index) {
47-
let dataString: String = String(decoding: data, as: UTF8.self)
41+
let dataString = String(decoding: data, as: UTF8.self)
4842
promise.succeed(dataString)
4943
}
5044

5145
case .failure(let error):
5246
promise.fail(error)
5347
}
54-
5548
}
56-
5749
}
5850

5951
/// Wait for the future to be completed,
@@ -63,13 +55,11 @@ func routes(_ app: Application) throws {
6355

6456
// 127.0.0.1:8080/search?query=botman
6557
app.get("search") { req -> EventLoopFuture<String> in
66-
6758
/// Create a new void promise
6859
let promise = req.eventLoop.makePromise(of: String.self)
6960

7061
/// Dispatch some work to happen on a background thread
7162
req.application.threadPool.submit { _ in
72-
7363
guard let query: String = req.query["query"] else {
7464
promise.fail(Abort(.badRequest))
7565
return
@@ -81,19 +71,17 @@ func routes(_ app: Application) throws {
8171
switch result {
8272
case .success(let searchResult):
8373
if let jsonData = try? JSONSerialization.data(withJSONObject: searchResult.hits, options: []) {
84-
let dataString: String = String(decoding: jsonData, as: UTF8.self)
74+
let dataString = String(decoding: jsonData, as: UTF8.self)
8575
promise.succeed(dataString)
8676
}
8777
case .failure(let error):
8878
promise.fail(error)
8979
}
9080
}
91-
9281
}
9382

9483
/// Wait for the future to be completed,
9584
/// then transform the result to a simple String
9685
return promise.futureResult
9786
}
98-
9987
}

Sources/MeiliSearch/Client.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Foundation
88
or dispatch queues.
99
*/
1010
public struct MeiliSearch {
11-
1211
// MARK: Properties
1312

1413
/**

Sources/MeiliSearch/Config.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Foundation
44
A `Config` instance represents the config used by MeiliSearch instance.
55
*/
66
public class Config {
7-
87
// MARK: Properties
98

109
/// Address for the MeiliSearch server.

Sources/MeiliSearch/Constants.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import Foundation
22

33
struct Constants {
4-
54
static let customJSONDecoder: JSONDecoder = {
6-
let decoder: JSONDecoder = JSONDecoder()
5+
let decoder = JSONDecoder()
76
decoder.dateDecodingStrategy = JSONDecoder.DateDecodingStrategy.formatted(Formatter.iso8601)
87
return decoder
98
}()
109

1110
static let customJSONEecoder: JSONEncoder = {
12-
let encoder: JSONEncoder = JSONEncoder()
11+
let encoder = JSONEncoder()
1312
encoder.dateEncodingStrategy = JSONEncoder.DateEncodingStrategy.formatted(Formatter.iso8601)
1413
return encoder
1514
}()
16-
1715
}

Sources/MeiliSearch/Documents.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Foundation
22

33
struct Documents {
4-
54
// MARK: Properties
65

76
let request: Request
@@ -19,7 +18,6 @@ struct Documents {
1918
_ identifier: String,
2019
_ completion: @escaping (Result<T, Swift.Error>) -> Void)
2120
where T: Codable, T: Equatable {
22-
2321
let query: String = "/indexes/\(uid)/documents/\(identifier)"
2422
request.get(api: query) { result in
2523
switch result {
@@ -72,7 +70,6 @@ struct Documents {
7270
_ document: Data,
7371
_ primaryKey: String? = nil,
7472
_ completion: @escaping (Result<Update, Swift.Error>) -> Void) {
75-
7673
var query: String = "/indexes/\(uid)/documents"
7774
if let primaryKey: String = primaryKey {
7875
query += "?primaryKey=\(primaryKey)"
@@ -94,7 +91,6 @@ struct Documents {
9491
_ encoder: JSONEncoder? = nil,
9592
_ primaryKey: String? = nil,
9693
_ completion: @escaping (Result<Update, Swift.Error>) -> Void) where T: Encodable {
97-
9894
var query: String = "/indexes/\(uid)/documents"
9995
if let primaryKey: String = primaryKey {
10096
query += "?primaryKey=\(primaryKey)"
@@ -124,7 +120,6 @@ struct Documents {
124120
_ document: Data,
125121
_ primaryKey: String? = nil,
126122
_ completion: @escaping (Result<Update, Swift.Error>) -> Void) {
127-
128123
var query: String = "/indexes/\(uid)/documents"
129124
if let primaryKey: String = primaryKey {
130125
query += "?primaryKey=\(primaryKey)"
@@ -146,7 +141,6 @@ struct Documents {
146141
_ encoder: JSONEncoder? = nil,
147142
_ primaryKey: String? = nil,
148143
_ completion: @escaping (Result<Update, Swift.Error>) -> Void) where T: Encodable {
149-
150144
var query: String = "/indexes/\(uid)/documents"
151145
if let primaryKey: String = primaryKey {
152146
query += "?primaryKey=\(primaryKey)"
@@ -177,9 +171,7 @@ struct Documents {
177171
_ uid: String,
178172
_ identifier: String,
179173
_ completion: @escaping (Result<Update, Swift.Error>) -> Void) {
180-
181174
self.request.delete(api: "/indexes/\(uid)/documents/\(identifier)") { result in
182-
183175
switch result {
184176
case .success(let result):
185177

@@ -199,9 +191,7 @@ struct Documents {
199191
func deleteAll(
200192
_ uid: String,
201193
_ completion: @escaping (Result<Update, Swift.Error>) -> Void) {
202-
203194
self.request.delete(api: "/indexes/\(uid)/documents") { result in
204-
205195
switch result {
206196
case .success(let data):
207197

@@ -222,7 +212,6 @@ struct Documents {
222212
_ uid: String,
223213
_ documentsIdentifiers: [Int],
224214
_ completion: @escaping (Result<Update, Swift.Error>) -> Void) {
225-
226215
let data: Data
227216

228217
do {
@@ -233,7 +222,6 @@ struct Documents {
233222
}
234223

235224
self.request.post(api: "/indexes/\(uid)/documents/delete-batch", data) { result in
236-
237225
switch result {
238226
case .success(let data):
239227

@@ -242,9 +230,7 @@ struct Documents {
242230
case .failure(let error):
243231
completion(.failure(error))
244232
}
245-
246233
}
247-
248234
}
249235

250236
private static func decodeJSON<T: Codable>(
@@ -271,5 +257,4 @@ struct Documents {
271257
return .failure(error)
272258
}
273259
}
274-
275260
}

Sources/MeiliSearch/Dumps.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import Foundation
55
can be used to launch MeiliSearch. Dumps are compatible between MeiliSearch versions.
66
*/
77
struct Dumps {
8-
98
// MARK: Properties
109

1110
let request: Request
@@ -39,7 +38,6 @@ struct Dumps {
3938
func status(
4039
_ uid: String,
4140
_ completion: @escaping (Result<Dump, Swift.Error>) -> Void) {
42-
4341
self.request.get(api: "/dumps/\(uid)/status") { result in
4442
switch result {
4543
case .success(let data):

Sources/MeiliSearch/Error.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Foundation
44
Represent all error types in the client.
55
*/
66
public extension MeiliSearch {
7-
87
// MARK: Error
98
struct MSErrorResponse: Decodable, Encodable, Equatable {
109
public let message: String
@@ -14,7 +13,6 @@ public extension MeiliSearch {
1413
}
1514

1615
static func errorHandler(url: URL, data: Data?, response: URLResponse?, error: Swift.Error?) throws {
17-
1816
// Communication Error with MeiliSearch
1917
if let error: Swift.Error = error {
2018
throw MeiliSearch.Error.meiliSearchCommunicationError(
@@ -55,7 +53,6 @@ public extension MeiliSearch {
5553

5654
/// Generic Error types for MeiliSearch,
5755
enum Error: Swift.Error, LocalizedError, Equatable {
58-
5956
/// The client tried to contact the server but it was not found.
6057
case serverNotFound
6158

Sources/MeiliSearch/Formatter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
extension Formatter {
44
static let iso8601: DateFormatter = {
5-
let formatter: DateFormatter = DateFormatter()
5+
let formatter = DateFormatter()
66
formatter.calendar = Calendar(identifier: .iso8601)
77
formatter.locale = Locale(identifier: "en_US_POSIX")
88
formatter.timeZone = TimeZone(secondsFromGMT: 0)
@@ -15,7 +15,7 @@ func queryURL(api: String, _ values: [String: String]) -> String {
1515
if values.isEmpty {
1616
return api
1717
}
18-
guard var components: URLComponents = URLComponents(string: api) else {
18+
guard var components = URLComponents(string: api) else {
1919
fatalError()
2020
}
2121
components.queryItems = values.map { (name: String, value: String) in

0 commit comments

Comments
 (0)