Explorar el Código

Run Swiftlint

Julien Chaumond hace 10 años
padre
commit
10608d566b

+ 1 - 1
Package.swift

@@ -2,4 +2,4 @@ import PackageDescription
 
 let package = Package(
     name: "Swifter"
-)
+)

+ 2 - 2
Sources/Swifter/DemoServer.swift

@@ -48,7 +48,7 @@ public func demoServer(publicDir: String?) -> HttpServer {
     }
     
     server["/json"] = { request in
-        return .OK(.Json(["posts" : [[ "id" : 1, "message" : "hello world"],[ "id" : 2, "message" : "sample message"]], "new_updates" : false]))
+        return .OK(.Json(["posts": [["id": 1, "message": "hello world"], ["id": 2, "message": "sample message"]], "new_updates": false]))
     }
     
     server["/redirect"] = { request in
@@ -62,4 +62,4 @@ public func demoServer(publicDir: String?) -> HttpServer {
     }
 
     return server
-}
+}

+ 5 - 5
Sources/Swifter/HttpHandlers.swift

@@ -12,7 +12,7 @@ public class HttpHandlers {
     
     private static let cache = NSCache()
     
-    public class func directory(dir: String) -> ( HttpRequest -> HttpResponse ) {
+    public class func directory(dir: String) -> (HttpRequest -> HttpResponse) {
         return { request in
             
             guard let localPath = request.params.first else {
@@ -78,16 +78,16 @@ public class HttpHandlers {
             if let (_, value) = r.params.first {
                 let filePath = dir + "/" + value
                 let fileManager = NSFileManager.defaultManager()
-                var isDir: ObjCBool = false;
-                if ( fileManager.fileExistsAtPath(filePath, isDirectory: &isDir) ) {
-                    if ( isDir ) {
+                var isDir: ObjCBool = false
+                if fileManager.fileExistsAtPath(filePath, isDirectory: &isDir) {
+                    if isDir {
                         do {
                             let files = try fileManager.contentsOfDirectoryAtPath(filePath)
                             var response = "<h3>\(filePath)</h3></br><table>"
                             response += files.map({ "<tr><td><a href=\"\(r.url)/\($0)\">\($0)</a></td></tr>"}).joinWithSeparator("")
                             response += "</table>"
                             return HttpResponse.OK(.Html(response))
-                        } catch  {
+                        } catch {
                             return HttpResponse.NotFound
                         }
                     } else {

+ 3 - 3
Sources/Swifter/HttpParser.swift

@@ -11,7 +11,7 @@
 #endif
 
 
-enum HttpParserError : ErrorType {
+enum HttpParserError: ErrorType {
     case ReadBodyFailed(String)
     case InvalidStatusLine(String)
 }
@@ -51,14 +51,14 @@ class HttpParser {
     
     private func readBody(socket: Socket, size: Int) throws -> String {
         var body = ""
-        var counter = 0;
+        var counter = 0
         while counter < size {
             let c = socket.read()
             if c < 0 {
                 throw HttpParserError.ReadBodyFailed(String.fromCString(UnsafePointer(strerror(errno))) ?? "Error: \(errno)")
             }
             body.append(UnicodeScalar(c))
-            counter++;
+            counter++
         }
         return body
     }

+ 5 - 5
Sources/Swifter/HttpResponse.swift

@@ -16,7 +16,7 @@ public protocol Serializer {
     func serialize(object: Any) throws -> String
 }
 
-public class JSONSerializer : Serializer {
+public class JSONSerializer: Serializer {
     public func serialize(object: Any) throws -> String {
         guard let obj = object as? AnyObject where NSJSONSerialization.isValidJSONObject(obj) else {
             throw SerializationError.InvalidObject
@@ -127,7 +127,7 @@ public enum HttpResponse {
         case .Forbidden             : return 403
         case .NotFound              : return 404
         case .InternalServerError   : return 500
-        case .RAW(let code,_,_,_)   : return code
+        case .RAW(let code, _ , _, _)   : return code
         }
     }
     
@@ -142,7 +142,7 @@ public enum HttpResponse {
         case .Forbidden             : return "Forbidden"
         case .NotFound              : return "Not Found"
         case .InternalServerError   : return "Internal Server Error"
-        case .RAW(_,let pharse,_,_) : return pharse
+        case .RAW(_, let phrase, _, _) : return phrase
         }
     }
     
@@ -164,7 +164,7 @@ public enum HttpResponse {
                 default:break
             }
         case .MovedPermanently(let location): headers["Location"] = location
-        case .RAW(_,_, let rawHeaders,_):
+        case .RAW(_, _, let rawHeaders, _):
             if let rawHeaders = rawHeaders {
                 for (k, v) in rawHeaders {
                     headers.updateValue(v, forKey: k)
@@ -178,7 +178,7 @@ public enum HttpResponse {
     func body() -> [UInt8]? {
         switch self {
         case .OK(let body)          : return body.data()
-        case .RAW(_,_,_, let data)  : return data
+        case .RAW(_, _, _, let data)  : return data
         default                     : return nil
         }
     }

+ 1 - 1
Sources/Swifter/HttpRouter.swift

@@ -59,4 +59,4 @@ public class HttpRouter {
         }
         return params
     }
-}
+}

+ 0 - 1
Sources/Swifter/HttpServer.swift

@@ -110,4 +110,3 @@ public class HttpServer {
         }
     }
 }
-

+ 5 - 5
Sources/Swifter/Socket.swift

@@ -25,7 +25,7 @@ enum SocketError: ErrorType {
     case RecvFailed(String)
 }
 
-public class Socket : Hashable, Equatable {
+public class Socket: Hashable, Equatable {
     
     public class func tcpSocketForListen(port: in_port_t = 8080, maxPendingConnection: Int32 = SOMAXCONN) throws -> Socket {
         
@@ -133,7 +133,7 @@ public class Socket : Hashable, Equatable {
     }
     
     public func read() -> Int {
-        var buffer = [UInt8](count: 1, repeatedValue: 0);
+        var buffer = [UInt8](count: 1, repeatedValue: 0)
         let next = recv(self.socketFileDescriptor as Int32, &buffer, Int(buffer.count), 0)
         if next <= 0 {
             return next
@@ -146,7 +146,7 @@ public class Socket : Hashable, Equatable {
         var n = 0
         repeat {
             n = self.read()
-            if ( n > 13 /* CR */ ) { characters.append(Character(UnicodeScalar(n))) }
+            if n > 13 /* CR */ { characters.append(Character(UnicodeScalar(n))) }
         } while n > 0 && n != 10 /* NL */
         if n == -1 {
             throw SocketError.RecvFailed(Socket.descriptionOfLastError())
@@ -179,8 +179,8 @@ public class Socket : Hashable, Equatable {
             // or use signal(SIGPIPE, SIG_IGN) to make your entire application ignore SIGPIPE.
         #else
             // Prevents crashes when blocking calls are pending and the app is paused ( via Home button ).
-            var no_sig_pipe: Int32 = 1;
-            setsockopt(socket, SOL_SOCKET, SO_NOSIGPIPE, &no_sig_pipe, socklen_t(sizeof(Int32)));
+            var no_sig_pipe: Int32 = 1
+            setsockopt(socket, SOL_SOCKET, SO_NOSIGPIPE, &no_sig_pipe, socklen_t(sizeof(Int32)))
         #endif
     }
     

+ 9 - 9
Sources/Swifter/String+Misc.swift

@@ -31,7 +31,7 @@ extension String {
                 buffer.append(Character(scalar))
                 continue
             }
-            if ( scalar == "%" ) {
+            if scalar == "%" {
                 let first = scalars.popFirst()
                 let secon = scalars.popFirst()
                 if let first = unicodeScalarToUInt32Hex(first), secon = unicodeScalarToUInt32Hex(secon) {
@@ -53,11 +53,11 @@ extension String {
     
     private func unicodeScalarToUInt32Whitespace(x: UnicodeScalar?) -> UInt32? {
         if let x = x {
-            if (x.value >= 9 && x.value <= 13) {
-                return x.value;
+            if x.value >= 9 && x.value <= 13 {
+                return x.value
             }
-            if (x.value == 32) {
-                return x.value;
+            if x.value == 32 {
+                return x.value
             }
         }
         return nil
@@ -65,16 +65,16 @@ extension String {
     
     private func unicodeScalarToUInt32Hex(x: UnicodeScalar?) -> UInt32? {
         if let x = x {
-            if (x.value >= 48 && x.value <= 57) {
+            if x.value >= 48 && x.value <= 57 {
                 return x.value - 48
             }
-            if (x.value >= 97 && x.value <= 102) {
+            if x.value >= 97 && x.value <= 102 {
                 return x.value - 97
             }
-            if (x.value >= 65 && x.value <= 70) {
+            if x.value >= 65 && x.value <= 70 {
                 return x.value - 65
             }
         }
         return nil
     }
-}
+}

+ 2 - 3
SwifterSampleiOS/ViewController.swift

@@ -28,8 +28,7 @@ class ViewController: UIViewController {
     }
     
     @IBAction func likedThis(sender: UIButton) {
-        self.server?.stop();
-        self.server = nil;
+        self.server?.stop()
+        self.server = nil
     }
 }
-