diff --git a/Sources/Sugar/Commands/SeederCommand/Seedable.swift b/Sources/Sugar/Commands/SeederCommand/Seedable.swift index 892aa6d..db5d45a 100644 --- a/Sources/Sugar/Commands/SeederCommand/Seedable.swift +++ b/Sources/Sugar/Commands/SeederCommand/Seedable.swift @@ -10,11 +10,11 @@ public protocol Seedable: Model { } public extension Seedable { - public static var arguments: [CommandArgument] { + static var arguments: [CommandArgument] { return [] } - public static var options: [CommandOption] { + static var options: [CommandOption] { return [] } } diff --git a/Sources/Sugar/Helpers/Array.swift b/Sources/Sugar/Helpers/Array.swift index 79b26bd..b963e40 100644 --- a/Sources/Sugar/Helpers/Array.swift +++ b/Sources/Sugar/Helpers/Array.swift @@ -1,5 +1,5 @@ public extension Array { - public subscript(safe index: Int) -> Element? { + subscript(safe index: Int) -> Element? { return indices.contains(index) ? self[index] : nil } } diff --git a/Sources/Sugar/Helpers/Bool.swift b/Sources/Sugar/Helpers/Bool.swift index 3c4a4b7..24520fe 100644 --- a/Sources/Sugar/Helpers/Bool.swift +++ b/Sources/Sugar/Helpers/Bool.swift @@ -1,5 +1,5 @@ public extension Bool { - public init(from string: String) { + init(from string: String) { self = ["1", "true"].contains(string.lowercased()) } } diff --git a/Sources/Sugar/Helpers/CommandConfig.swift b/Sources/Sugar/Helpers/CommandConfig.swift index 8facb93..d7a0c2b 100644 --- a/Sources/Sugar/Helpers/CommandConfig.swift +++ b/Sources/Sugar/Helpers/CommandConfig.swift @@ -1,7 +1,7 @@ import Vapor public extension CommandConfig { - public mutating func use(_ list: [String: Command]) { + mutating func use(_ list: [String: Command]) { for item in list { self.use(item.value, as: item.key) } diff --git a/Sources/Sugar/Helpers/Date.swift b/Sources/Sugar/Helpers/Date.swift index 2291cc4..1035059 100644 --- a/Sources/Sugar/Helpers/Date.swift +++ b/Sources/Sugar/Helpers/Date.swift @@ -5,22 +5,22 @@ public extension Date { static let hourInSec = 3600 static let minInSec = 60 - public static func startOfMonth() -> Date? { + static func startOfMonth() -> Date? { return Date().startOfMonth() } - public static func endOfMonth() -> Date? { + static func endOfMonth() -> Date? { return Date().endOfMonth() } - public func startOfMonth(calendar: Calendar = .current) -> Date? { + func startOfMonth(calendar: Calendar = .current) -> Date? { return calendar.date( from: calendar.dateComponents([.year, .month], from: calendar.startOfDay(for: self)) ) } - public func endOfMonth(calendar: Calendar = .current) -> Date? { + func endOfMonth(calendar: Calendar = .current) -> Date? { guard let startOfMonth = self.startOfMonth() else { return nil } return calendar.date( byAdding: DateComponents(month: 1, day: -1), @@ -28,28 +28,28 @@ public extension Date { ) } - public func add(days: Int, calendar: Calendar = .current) -> Date? { + func add(days: Int, calendar: Calendar = .current) -> Date? { return calendar.date( byAdding: DateComponents(day: days), to: self ) } - public func sub(days: Int, calendar: Calendar = .current) -> Date? { + func sub(days: Int, calendar: Calendar = .current) -> Date? { return calendar.date( byAdding: DateComponents(day: -days), to: self ) } - public func add(hours: Int, calendar: Calendar = .current) -> Date? { + func add(hours: Int, calendar: Calendar = .current) -> Date? { return calendar.date( byAdding: DateComponents(hour: hours), to: self ) } - public func sub(hours: Int, calendar: Calendar = .current) -> Date? { + func sub(hours: Int, calendar: Calendar = .current) -> Date? { return calendar.date( byAdding: DateComponents(hour: -hours), to: self @@ -66,7 +66,7 @@ public extension Date { /// - minute: Int /// - second: Int /// - Returns: Date? - public func dateBySetting( + func dateBySetting( hour: Int, minute: Int, second: Int, diff --git a/Sources/Sugar/Helpers/Environment.swift b/Sources/Sugar/Helpers/Environment.swift index fd99b03..3aa7ca7 100644 --- a/Sources/Sugar/Helpers/Environment.swift +++ b/Sources/Sugar/Helpers/Environment.swift @@ -5,11 +5,11 @@ public extension Environment { case keyNotFound(key: String) } - public static func get(_ key: String, _ fallback: String) -> String { + static func get(_ key: String, _ fallback: String) -> String { return ProcessInfo.processInfo.environment[key] ?? fallback } - public static func assertGet(_ key: String) throws -> String { + static func assertGet(_ key: String) throws -> String { guard let value = Environment.get(key) else { throw Environment.EnvironmentError.keyNotFound(key: key) } diff --git a/Sources/Sugar/Helpers/Future.swift b/Sources/Sugar/Helpers/Future.swift index b814050..1a79cba 100644 --- a/Sources/Sugar/Helpers/Future.swift +++ b/Sources/Sugar/Helpers/Future.swift @@ -1,14 +1,14 @@ import Vapor public extension Future { - public func `try`(_ callback: @escaping (Expectation) throws -> Void) -> Future { + func `try`(_ callback: @escaping (Expectation) throws -> Void) -> Future { return map { try callback($0) return $0 } } - public func flatTry(_ callback: @escaping (Expectation) throws -> Future) -> Future { + func flatTry(_ callback: @escaping (Expectation) throws -> Future) -> Future { return flatMap { expectation in try callback(expectation).map { _ in expectation } } @@ -16,7 +16,7 @@ public extension Future { } public extension Future where Expectation: OptionalType { - public func `nil`(or error: @autoclosure @escaping () -> Error) -> Future { + func `nil`(or error: @autoclosure @escaping () -> Error) -> Future { return map(to: Void.self) { optional in guard optional.wrapped == nil else { throw error() @@ -26,7 +26,7 @@ public extension Future where Expectation: OptionalType { } public extension Future where Expectation: Equatable { - public func equal( + func equal( _ expected: Expectation, or error: @autoclosure @escaping () -> Error ) -> Future { diff --git a/Sources/Sugar/Helpers/Leaf/LeafTagConfig.swift b/Sources/Sugar/Helpers/Leaf/LeafTagConfig.swift index 38cebea..249de4e 100644 --- a/Sources/Sugar/Helpers/Leaf/LeafTagConfig.swift +++ b/Sources/Sugar/Helpers/Leaf/LeafTagConfig.swift @@ -4,7 +4,7 @@ public extension LeafTagConfig { /// Register multiple tags using the keys as their names. /// /// - Parameter list: Map of names to tags. - public mutating func use(_ list: [String: TagRenderer]) { + mutating func use(_ list: [String: TagRenderer]) { for item in list { self.use(item.value, as: item.key) } diff --git a/Sources/Sugar/Helpers/Model.swift b/Sources/Sugar/Helpers/Model.swift index bc028d6..ef0e00d 100644 --- a/Sources/Sugar/Helpers/Model.swift +++ b/Sources/Sugar/Helpers/Model.swift @@ -2,7 +2,7 @@ import Fluent import Vapor public extension Model { - public static func requireFind( + static func requireFind( _ id: ID, on worker: DatabaseConnectable ) -> Future { @@ -11,7 +11,7 @@ public extension Model { .unwrap(or: Abort(.notFound, reason: "\(Self.self) with id \(id) not found")) } - public func saveOrUpdate ( + func saveOrUpdate ( given filters: [FilterOperator], withSoftDeleted: Bool = false, restore: Bool = false, diff --git a/Sources/Sugar/Helpers/SecondsConverter.swift b/Sources/Sugar/Helpers/SecondsConverter.swift index 38f171e..6819c76 100644 --- a/Sources/Sugar/Helpers/SecondsConverter.swift +++ b/Sources/Sugar/Helpers/SecondsConverter.swift @@ -2,19 +2,19 @@ // See https://nshipster.com/timeinterval-date-dateinterval/ for more information. // Instead these helpers should be used for e.g. setting a expiration time of something. public extension Numeric { - public var minsInSecs: Self { + var minsInSecs: Self { return self * 60 } - public var hoursInSecs: Self { + var hoursInSecs: Self { return self.minsInSecs * 60 } - public var daysInSecs: Self { + var daysInSecs: Self { return self.hoursInSecs * 24 } - public var weeksInSecs: Self { + var weeksInSecs: Self { return self.daysInSecs * 7 } } diff --git a/Sources/Sugar/Helpers/String.swift b/Sources/Sugar/Helpers/String.swift index 21360b3..3bfa4e1 100644 --- a/Sources/Sugar/Helpers/String.swift +++ b/Sources/Sugar/Helpers/String.swift @@ -2,7 +2,7 @@ import Crypto import COperatingSystem public extension String { - public static func randomAlphaNumericString(_ length: Int = 64) -> String { + static func randomAlphaNumericString(_ length: Int = 64) -> String { func makeRandom(min: Int, max: Int) -> Int { let top = max - min + 1 #if os(Linux) diff --git a/Sources/Sugar/Helpers/TimeInterval.swift b/Sources/Sugar/Helpers/TimeInterval.swift index d40532b..a8b0af3 100644 --- a/Sources/Sugar/Helpers/TimeInterval.swift +++ b/Sources/Sugar/Helpers/TimeInterval.swift @@ -1,7 +1,7 @@ import Foundation public extension Optional where Wrapped == TimeInterval { - public var dateRelativeTo1970: Date? { + var dateRelativeTo1970: Date? { guard let date = self else { return nil } @@ -11,7 +11,7 @@ public extension Optional where Wrapped == TimeInterval { } public extension TimeInterval { - public var dateRelativeTo1970: Date { + var dateRelativeTo1970: Date { return Date(timeIntervalSince1970: self) } } diff --git a/Sources/Sugar/Helpers/URL.swift b/Sources/Sugar/Helpers/URL.swift index 4c2c5c8..17664db 100644 --- a/Sources/Sugar/Helpers/URL.swift +++ b/Sources/Sugar/Helpers/URL.swift @@ -1,7 +1,7 @@ import Foundation public extension URL { - public func addQueryItems(_ item: [URLQueryItem]) -> URL { + func addQueryItems(_ item: [URLQueryItem]) -> URL { guard var components = URLComponents(url: self, resolvingAgainstBaseURL: false) else { return self } @@ -11,7 +11,7 @@ public extension URL { return components.url ?? self } - public func addQueryItems(from url: URL) -> URL { + func addQueryItems(from url: URL) -> URL { guard let items = URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems else { diff --git a/Sources/Sugar/Validation/StrongPasswordValidator.swift b/Sources/Sugar/Validation/StrongPasswordValidator.swift index c62235a..602efd3 100644 --- a/Sources/Sugar/Validation/StrongPasswordValidator.swift +++ b/Sources/Sugar/Validation/StrongPasswordValidator.swift @@ -71,7 +71,7 @@ fileprivate struct StrongPasswordValidator: ValidatorType { } fileprivate extension Sequence where Iterator.Element == PasswordRegex { - fileprivate var requirements: String { + var requirements: String { return self.map { $0.description }.joined(separator: ", ") } }