Skip to content

Commit

Permalink
Remove warnings from Swift 5 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTim authored and gperdomor committed May 6, 2019
1 parent 54e9b97 commit 8e3ddf8
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/Packages
/*.xcodeproj
Package.resolved
DerivedData/
4 changes: 2 additions & 2 deletions Sources/AsyncExt/Future+Bool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public extension Future where T == Bool {
/// - Parameter error: The error to be thrown.
/// - Returns: The result of the comparison wrapped in a Future.
/// - Throws: Throws the passed error in the opposite case.
public func `true`(or error: Error) throws -> Future<Bool> {
func `true`(or error: Error) throws -> Future<Bool> {
return map(to: Bool.self) { boolean in
if !boolean {
throw error
Expand All @@ -38,7 +38,7 @@ public extension Future where T == Bool {
/// - Parameter error: The error to be thrown.
/// - Returns: The result of the comparison wrapped in a Future.
/// - Throws: Throws the passed error in the opposite case.
public func `false`(or error: Error) throws -> Future<Bool> {
func `false`(or error: Error) throws -> Future<Bool> {
return map(to: Bool.self) { boolean in
if boolean {
throw error
Expand Down
16 changes: 8 additions & 8 deletions Sources/AsyncExt/Future+Comparable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public extension Future where T: Comparable {
///
/// - Parameter value: The value to compare.
/// - Returns: The result of the comparison wrapped in a Future.
public func greater(than value: T) -> Future<Bool> {
func greater(than value: T) -> Future<Bool> {
return map(to: Bool.self) { current in
current > value
}
Expand All @@ -36,7 +36,7 @@ public extension Future where T: Comparable {
/// - error: The error to be thrown.
/// - Returns: The result of the comparison wrapped in a Future.
/// - Throws: Throws the passed error if the current value is not greater than the passed value.
public func greater(than value: T, or error: Error) throws -> Future<Bool> {
func greater(than value: T, or error: Error) throws -> Future<Bool> {
return try greater(than: value).true(or: error)
}

Expand All @@ -48,7 +48,7 @@ public extension Future where T: Comparable {
///
/// - Parameter value: The value to compare.
/// - Returns: The result of the comparison wrapped in a Future.
public func greaterOrEqual(to value: T) -> Future<Bool> {
func greaterOrEqual(to value: T) -> Future<Bool> {
return map(to: Bool.self) { current in
current >= value
}
Expand All @@ -65,7 +65,7 @@ public extension Future where T: Comparable {
/// - error: The error to be thrown.
/// - Returns: The result of the comparison wrapped in a Future.
/// - Throws: Throws the passed error if the current value is not greater or equal to the passed value.
public func greaterOrEqual(to value: T, or error: Error) throws -> Future<Bool> {
func greaterOrEqual(to value: T, or error: Error) throws -> Future<Bool> {
return try greaterOrEqual(to: value).true(or: error)
}

Expand All @@ -77,7 +77,7 @@ public extension Future where T: Comparable {
///
/// - Parameter value: The value to compare.
/// - Returns: The result of the comparison wrapped in a Future.
public func less(than value: T) -> Future<Bool> {
func less(than value: T) -> Future<Bool> {
return map(to: Bool.self) { current in
current < value
}
Expand All @@ -94,7 +94,7 @@ public extension Future where T: Comparable {
/// - error: The error to be thrown.
/// - Returns: The result of the comparison wrapped in a Future.
/// - Throws: Throws the passed error if the current value is not less than the passed value.
public func less(than value: T, or error: Error) throws -> Future<Bool> {
func less(than value: T, or error: Error) throws -> Future<Bool> {
return try less(than: value).true(or: error)
}

Expand All @@ -106,7 +106,7 @@ public extension Future where T: Comparable {
///
/// - Parameter value: The value to compare.
/// - Returns: The result of the comparison wrapped in a Future.
public func lessOrEqual(to value: T) -> Future<Bool> {
func lessOrEqual(to value: T) -> Future<Bool> {
return map(to: Bool.self) { current in
current <= value
}
Expand All @@ -123,7 +123,7 @@ public extension Future where T: Comparable {
/// - error: The error to be thrown.
/// - Returns: The result of the comparison wrapped in a Future.
/// - Throws: Throws the passed error if the current value is not less or equal to the passed value.
public func lessOrEqual(to value: T, or error: Error) throws -> Future<Bool> {
func lessOrEqual(to value: T, or error: Error) throws -> Future<Bool> {
return try lessOrEqual(to: value).true(or: error)
}
}
8 changes: 4 additions & 4 deletions Sources/AsyncExt/Future+Equatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public extension Future where T: Equatable {
///
/// - Parameter value: The value to compare.
/// - Returns: The result of the comparison wrapped in a Future.
public func equal(to value: T) -> Future<Bool> {
func equal(to value: T) -> Future<Bool> {
return map(to: Bool.self) { current in
current == value
}
Expand All @@ -36,7 +36,7 @@ public extension Future where T: Equatable {
/// - error: The error to be thrown.
/// - Returns: The result of the comparison wrapped in a Future.
/// - Throws: Throws the passed error if values are not equals.
public func equal(to value: T, or error: Error) throws -> Future<Bool> {
func equal(to value: T, or error: Error) throws -> Future<Bool> {
return try map(to: Bool.self) { current in
current == value
}.true(or: error)
Expand All @@ -50,7 +50,7 @@ public extension Future where T: Equatable {
///
/// - Parameter value: The value to compare.
/// - Returns: The result of the comparison wrapped in a Future.
public func notEqual(to value: T) -> Future<Bool> {
func notEqual(to value: T) -> Future<Bool> {
return map(to: Bool.self) { current in
current != value
}
Expand All @@ -67,7 +67,7 @@ public extension Future where T: Equatable {
/// - error: The error to be thrown.
/// - Returns: The result of the comparison wrapped in a Future.
/// - Throws: Throws the passed error if values are not equals.
public func notEqual(to value: T, or error: Error) throws -> Future<Bool> {
func notEqual(to value: T, or error: Error) throws -> Future<Bool> {
return try map(to: Bool.self) { current in
current != value
}.true(or: error)
Expand Down
4 changes: 2 additions & 2 deletions Sources/AsyncExt/Future+Optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Async
import Core

public extension Future where Expectation: OptionalType {
public func `nil`(or error: @autoclosure @escaping () -> Error) -> Future<Expectation.WrappedType?> {
func `nil`(or error: @autoclosure @escaping () -> Error) -> Future<Expectation.WrappedType?> {
return map { optional in
if let _ = optional.wrapped {
throw error()
Expand All @@ -20,7 +20,7 @@ public extension Future where Expectation: OptionalType {
}
}

public func `nil`() -> Future<Bool> {
func `nil`() -> Future<Bool> {
return map { optional in
optional.wrapped == nil
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/FluentExt/Extensions/QueryBuilder+Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public extension QueryBuilder where Result: Model, Result.Database == Database {
/// - req: the request.
/// - Returns: Self
/// - Throws: FluentError
public func filter<T>(_ keyPath: KeyPath<Result, T>, at parameter: String, on req: Request) throws -> Self where T: Codable {
func filter<T>(_ keyPath: KeyPath<Result, T>, at parameter: String, on req: Request) throws -> Self where T: Codable {
let decoder = try req.make(ContentCoders.self).requireDataDecoder(for: .urlEncodedForm)

guard let config = req.query[String.self, at: parameter] else {
Expand Down Expand Up @@ -79,7 +79,7 @@ public extension QueryBuilder where Result: Model, Result.Database == Database,
/// - req: the request.
/// - Returns: Self
/// - Throws: FluentError
public func filter(_ keyPath: KeyPath<Result, String>, at parameter: String, on req: Request) throws -> Self {
func filter(_ keyPath: KeyPath<Result, String>, at parameter: String, on req: Request) throws -> Self {
let decoder = try req.make(ContentCoders.self).requireDataDecoder(for: .urlEncodedForm)

guard let config = req.query[String.self, at: parameter] else {
Expand Down Expand Up @@ -145,7 +145,7 @@ public extension QueryBuilder where Result: Model, Result.Database == Database,
/// - req: the request.
/// - Returns: Self
/// - Throws: FluentError
public func filter(_ keyPath: KeyPath<Result, String?>, at parameter: String, on req: Request) throws -> Self {
func filter(_ keyPath: KeyPath<Result, String?>, at parameter: String, on req: Request) throws -> Self {
let decoder = try req.make(ContentCoders.self).requireDataDecoder(for: .urlEncodedForm)

guard let config = req.query[String.self, at: parameter] else {
Expand Down
6 changes: 3 additions & 3 deletions Sources/FluentExt/Extensions/QueryBuilder+Sort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public extension QueryBuilder where Result: Model, Result.Database == Database {
/// - req: the request.
/// - Returns: Self
/// - Throws: FluentError
public func sort<T>(_ keyPath: KeyPath<Result, T>, at queryParam: String, as parameter: String, default direction: Database.QuerySortDirection? = nil, on req: Request) throws -> Self {
func sort<T>(_ keyPath: KeyPath<Result, T>, at queryParam: String, as parameter: String, default direction: Database.QuerySortDirection? = nil, on req: Request) throws -> Self {
if let sort = req.query[String.self, at: queryParam] {
let sortOpts = sort.components(separatedBy: ",")

Expand Down Expand Up @@ -59,15 +59,15 @@ public extension QueryBuilder where Result: Model, Result.Database == Database {
/// - req: the request.
/// - Returns: Self
/// - Throws: FluentError
public func sort<T>(_ keyPath: KeyPath<Result, T>, as parameter: String, default direction: Database.QuerySortDirection? = nil, on req: Request) throws -> Self {
func sort<T>(_ keyPath: KeyPath<Result, T>, as parameter: String, default direction: Database.QuerySortDirection? = nil, on req: Request) throws -> Self {
return try sort(keyPath, at: "sort", as: parameter, default: direction, on: req)
}

/// Applies sort criteria over a keypath using criteria configured in a request query params
///
/// - Parameter sorts: Some `QuerySort`s to be applied.
/// - Returns: Self
public func sort(by sorts: [Database.QuerySort]? = nil) -> Self {
func sort(by sorts: [Database.QuerySort]? = nil) -> Self {
sorts?.forEach { sort in
Database.querySortApply(sort, to: &query)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/FluentExt/Extensions/Request+Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public extension Request {
/// - parameter: the parameter name in filter config from request url params.
/// - Returns: FilterOperator
/// - Throws: FluentError
public func filter<Result, T>(_ keyPath: KeyPath<Result, T>, at parameter: String) throws -> FilterOperator<Result.Database, Result>? where T: Codable, Result: Model {
func filter<Result, T>(_ keyPath: KeyPath<Result, T>, at parameter: String) throws -> FilterOperator<Result.Database, Result>? where T: Codable, Result: Model {
let decoder = try make(ContentCoders.self).requireDataDecoder(for: .urlEncodedForm)

guard let config = self.query[String.self, at: parameter] else {
Expand Down Expand Up @@ -68,7 +68,7 @@ public extension Request {
/// - parameter: the parameter name in filter config from request url params.
/// - Returns: FilterOperator
/// - Throws: FluentError
public func filter<Result>(_ keyPath: KeyPath<Result, String>, at parameter: String) throws -> FilterOperator<Result.Database, Result>? where Result: Model, Result.Database.QueryFilterMethod: SQLBinaryOperator {
func filter<Result>(_ keyPath: KeyPath<Result, String>, at parameter: String) throws -> FilterOperator<Result.Database, Result>? where Result: Model, Result.Database.QueryFilterMethod: SQLBinaryOperator {
let decoder = try make(ContentCoders.self).requireDataDecoder(for: .urlEncodedForm)

guard let config = self.query[String.self, at: parameter] else {
Expand Down Expand Up @@ -132,7 +132,7 @@ public extension Request {
/// - parameter: the parameter name in filter config from request url params.
/// - Returns: FilterOperator
/// - Throws: FluentError
public func filter<Result>(_ keyPath: KeyPath<Result, String?>, at parameter: String) throws -> FilterOperator<Result.Database, Result>? where Result: Model, Result.Database.QueryFilterMethod: SQLBinaryOperator {
func filter<Result>(_ keyPath: KeyPath<Result, String?>, at parameter: String) throws -> FilterOperator<Result.Database, Result>? where Result: Model, Result.Database.QueryFilterMethod: SQLBinaryOperator {
let decoder = try make(ContentCoders.self).requireDataDecoder(for: .urlEncodedForm)

guard let config = self.query[String.self, at: parameter] else {
Expand Down
8 changes: 4 additions & 4 deletions Sources/FluentExt/Extensions/Request+Sort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public extension Request {
/// - parameter: the parameter name in sorting config.
/// - Returns: QuerySort criteria
/// - Throws: FluentError
public func sort<M, T>(_ keyPath: KeyPath<M, T>, at queryParam: String, as parameter: String) throws -> M.Database.QuerySort? where M: Model {
func sort<M, T>(_ keyPath: KeyPath<M, T>, at queryParam: String, as parameter: String) throws -> M.Database.QuerySort? where M: Model {
if let sort = self.query[String.self, at: queryParam] {
let sortOpts = sort.components(separatedBy: ",")

Expand Down Expand Up @@ -54,7 +54,7 @@ public extension Request {
/// - direction: Default direction to apply if no value is found in url query params.
/// - Returns: QuerySort criteria
/// - Throws: FluentError
public func sort<M, T>(_ keyPath: KeyPath<M, T>, at queryParam: String, as parameter: String, default direction: M.Database.QuerySortDirection) throws -> M.Database.QuerySort where M: Model {
func sort<M, T>(_ keyPath: KeyPath<M, T>, at queryParam: String, as parameter: String, default direction: M.Database.QuerySortDirection) throws -> M.Database.QuerySort where M: Model {
if let sort = try self.sort(keyPath, at: queryParam, as: parameter) {
return sort
}
Expand All @@ -69,7 +69,7 @@ public extension Request {
/// - parameter: the parameter name in sorting config.
/// - Returns: QuerySort criteria
/// - Throws: FluentError
public func sort<M, T>(_ keyPath: KeyPath<M, T>, as parameter: String) throws -> M.Database.QuerySort? where M: Model {
func sort<M, T>(_ keyPath: KeyPath<M, T>, as parameter: String) throws -> M.Database.QuerySort? where M: Model {
return try sort(keyPath, at: "sort", as: parameter)
}

Expand All @@ -81,7 +81,7 @@ public extension Request {
/// - direction: Default direction to apply if no value is found in url query params.
/// - Returns: QuerySort criteria
/// - Throws: FluentError
public func sort<M, T>(_ keyPath: KeyPath<M, T>, as parameter: String, default direction: M.Database.QuerySortDirection) throws -> M.Database.QuerySort where M: Model {
func sort<M, T>(_ keyPath: KeyPath<M, T>, as parameter: String, default direction: M.Database.QuerySortDirection) throws -> M.Database.QuerySort where M: Model {
return try sort(keyPath, at: "sort", as: parameter, default: direction)
}
}
2 changes: 1 addition & 1 deletion Sources/ServiceExt/Environment+DotEnv.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public extension Environment {
/// Loads environment variables from .env files.
///
/// - Parameter filename: name of your env file.
public static func dotenv(filename: String = ".env") {
static func dotenv(filename: String = ".env") {
guard let path = getAbsolutePath(for: filename),
let contents = try? String(contentsOfFile: path, encoding: .utf8) else {
return
Expand Down
10 changes: 5 additions & 5 deletions Sources/ServiceExt/Environment+Getters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public extension Environment {
///
/// - Parameter key: the environment variable name.
/// - Returns: the environment variable value if exists.
public static func get(_ key: String) -> Int? {
static func get(_ key: String) -> Int? {
if let value: String = self.get(key), let parsed = Int(value) {
return parsed
}
Expand All @@ -33,7 +33,7 @@ public extension Environment {
///
/// - Parameter key: the environment variable name.
/// - Returns: the environment variable value if exists.
public static func get(_ key: String) -> Bool? {
static func get(_ key: String) -> Bool? {
if let value: String = self.get(key), let parsed = value.lowercased().bool {
return parsed
}
Expand All @@ -47,7 +47,7 @@ public extension Environment {
/// - key: the environment variable name.
/// - fallback: the default value.
/// - Returns: the environment variable value if exists, otherwise the `fallback` value.
public static func get(_ key: String, _ fallback: String) -> String {
static func get(_ key: String, _ fallback: String) -> String {
return get(key) ?? fallback
}

Expand All @@ -57,7 +57,7 @@ public extension Environment {
/// - key: the environment variable name.
/// - fallback: the default value.
/// - Returns: the environment variable value if exists, otherwise the `fallback` value.
public static func get(_ key: String, _ fallback: Int) -> Int {
static func get(_ key: String, _ fallback: Int) -> Int {
guard let value: Int = self.get(key) else {
return fallback
}
Expand All @@ -71,7 +71,7 @@ public extension Environment {
/// - key: the environment variable name.
/// - fallback: the default value.
/// - Returns: the environment variable value if exists, otherwise the `fallback` value.
public static func get(_ key: String, _ fallback: Bool) -> Bool {
static func get(_ key: String, _ fallback: Bool) -> Bool {
guard let value: Bool = self.get(key) else {
return fallback
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/VaporExt/Encodable+Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public extension Future where T: Encodable {
/// - contentType: The MediaType to encode the data
/// - Returns: A Future<Response> with the encodable data
/// - Throws: Errors errors during encoding
public func toResponse(on req: Request, as status: HTTPStatus, contentType: MediaType = .json) throws -> Future<Response> {
func toResponse(on req: Request, as status: HTTPStatus, contentType: MediaType = .json) throws -> Future<Response> {
return map(to: Response.self) { encodable in
let response = req.response()
try response.content.encode(encodable, as: contentType)
Expand Down

0 comments on commit 8e3ddf8

Please sign in to comment.