IBM-Swift/Kitura

View on GitHub

Showing 850 of 850 total issues

Function DefaultMenu has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    var DefaultMenu = function() {
        "use strict";
        var s = Menu.prototype;
        function DefaultMenu() {
            Menu.apply(this, [].slice.call(arguments, 0));

    Function testErrorOverridesBody has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        func testErrorOverridesBody() {
            let status = Status("This should not be sent")
            router.get("/status") { (id: Int, respondWith: (Status?, RequestError?) -> Void) in respondWith(status, .conflict) }
            router.post("/status") { (status: Status, respondWith: (Status?, RequestError?) -> Void) in respondWith(status, .conflict) }
            router.put("/status") { (id: Int, status: Status, respondWith: (Status?, RequestError?) -> Void) in respondWith(status, .conflict) }
    Severity: Minor
    Found in Tests/KituraTests/TestCodableRouter.swift - About 1 hr to fix

      Function DefaultMenu has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          var DefaultMenu = function() {
              "use strict";
              var s = Menu.prototype;
              function DefaultMenu() {
                  Menu.apply(this, [].slice.call(arguments, 0));
      Severity: Minor
      Found in docs/js/typeahead.jquery.js - About 1 hr to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    if let nameRange = line.range(of: "name=", options: caseInsensitiveSearch, range: labelRange.upperBound..<line.endIndex) {
                        let valueStartIndex = line.index(after: nameRange.upperBound)
                        let valueEndIndex = line.range(of: "\"", range: valueStartIndex..<line.endIndex)
                        part.name = String(line[valueStartIndex..<(valueEndIndex?.lowerBound ?? line.endIndex)])
                    }
        Severity: Major
        Found in Sources/Kitura/bodyParser/MultiPartBodyParser.swift and 1 other location - About 1 hr to fix
        Sources/Kitura/bodyParser/MultiPartBodyParser.swift on lines 99..103

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 108.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    if let filenameRange = line.range(of: "filename=", options: caseInsensitiveSearch, range: labelRange.upperBound..<line.endIndex) {
                        let valueStartIndex = line.index(after: filenameRange.upperBound)
                        let valueEndIndex = line.range(of: "\"", range: valueStartIndex..<line.endIndex)
                        part.filename = String(line[valueStartIndex..<(valueEndIndex?.lowerBound ?? line.endIndex)])
                    }
        Severity: Major
        Found in Sources/Kitura/bodyParser/MultiPartBodyParser.swift and 1 other location - About 1 hr to fix
        Sources/Kitura/bodyParser/MultiPartBodyParser.swift on lines 94..98

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 108.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                get(route) { request, response, next in
                    Log.verbose("Received GET (plural) type-safe request with Query Parameters")
                    Log.verbose("Query Parameters: \(request.queryParameters)")
                    do {
                        let query: Q = try QueryDecoder(dictionary: request.queryParameters).decode(Q.self)
        Severity: Major
        Found in Sources/Kitura/CodableRouter.swift and 2 other locations - About 1 hr to fix
        Sources/Kitura/CodableRouter.swift on lines 476..488
        Sources/Kitura/CodableRouter.swift on lines 580..591

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 106.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                delete(route) { request, response, next in
                    Log.verbose("Received DELETE type-safe request with Query Parameters")
                    Log.verbose("Query Parameters: \(request.queryParameters)")
                    do {
                        let query: Q = try QueryDecoder(dictionary: request.queryParameters).decode(Q.self)
        Severity: Major
        Found in Sources/Kitura/CodableRouter.swift and 2 other locations - About 1 hr to fix
        Sources/Kitura/CodableRouter.swift on lines 459..470
        Sources/Kitura/CodableRouter.swift on lines 476..488

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 106.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                performServerTest(router, asyncTasks: { expectation in
                    self.performRequest("get", path:"/help/contact", callback: { response in
                        XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                        XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                        do {
        Severity: Major
        Found in Tests/KituraTests/TestStaticFileServer.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestStaticFileServer.swift on lines 687..699

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 106.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                performServerTest(router, asyncTasks: { expectation in
                    self.performRequest("get", path:"/help/contact/details", callback: { response in
                        XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                        XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                        do {
        Severity: Major
        Found in Tests/KituraTests/TestStaticFileServer.swift and 1 other location - About 1 hr to fix
        Tests/KituraTests/TestStaticFileServer.swift on lines 654..666

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 106.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                get(route) { request, response, next in
                    Log.verbose("Received GET (singular) type-safe request with Query Parameters")
                    Log.verbose("Query Parameters: \(request.queryParameters)")
                    // Define result handler
                    do {
        Severity: Major
        Found in Sources/Kitura/CodableRouter.swift and 2 other locations - About 1 hr to fix
        Sources/Kitura/CodableRouter.swift on lines 459..470
        Sources/Kitura/CodableRouter.swift on lines 580..591

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 106.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Function addCookie has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public func addCookie(name: String, value: String, domain: String, path: String, otherAttributes: [AdditionalCookieAttribute]? = nil ) {
                var cookieProperties = [HTTPCookiePropertyKey: Any]()
                cookieProperties[HTTPCookiePropertyKey.name] = name
                cookieProperties[HTTPCookiePropertyKey.value] = value
                cookieProperties[HTTPCookiePropertyKey.domain] = domain
        Severity: Minor
        Found in Sources/Kitura/RouterResponse.swift - About 1 hr to fix

          Function cookieToServer has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              private func cookieToServer(separator: String, quoteValue: Bool) {
                  performServerTest(router, asyncTasks: { expectation in
                      let cookieMap = [" Plover ": " value with spaces ",
                                     "Zxcv": "(E = mc^2)",
                                     "value with one quote": "\"",
          Severity: Minor
          Found in Tests/KituraTests/TestCookies.swift - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Similar blocks of code found in 4 locations. Consider refactoring.
          Open

                  get(route) { request, response, next in
                      Log.verbose("Received GET(Array) typed middleware request")
                      self.handleMiddleware(T1.self, T2.self, T3.self, request: request, response: response) { typeSafeMiddleware1, typeSafeMiddleware2, typeSafeMiddleware3 in
                          guard let typeSafeMiddleware1 = typeSafeMiddleware1, let typeSafeMiddleware2 = typeSafeMiddleware2, let typeSafeMiddleware3 = typeSafeMiddleware3 else {
                              return next()
          Severity: Major
          Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 3 other locations - About 1 hr to fix
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 127..135
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 475..483
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1031..1039

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 105.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 4 locations. Consider refactoring.
          Open

                  get(route) { request, response, next in
                      Log.verbose("Received GET(Single) typed middleware request")
                      self.handleMiddleware(T1.self, T2.self, T3.self, request: request, response: response) { typeSafeMiddleware1, typeSafeMiddleware2, typeSafeMiddleware3 in
                          guard let typeSafeMiddleware1 = typeSafeMiddleware1, let typeSafeMiddleware2 = typeSafeMiddleware2, let typeSafeMiddleware3 = typeSafeMiddleware3 else {
                              return next()
          Severity: Major
          Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 3 other locations - About 1 hr to fix
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 237..245
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 475..483
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1031..1039

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 105.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Function setParameters has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              private func setParameters(forRequest request: RouterRequest, fromUrlPath urlPath: NSString, match: NSTextCheckingResult) {
                  var parameters = mergeParameters ? request.parameters : [:]
          
                  if let keys = keys {
                      for index in 0..<keys.count {
          Severity: Minor
          Found in Sources/Kitura/RouterElement.swift - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Similar blocks of code found in 4 locations. Consider refactoring.
          Open

                  get(route) { request, response, next in
                      Log.verbose("Received GET(Array) with identifier typed middleware request")
                      self.handleMiddleware(T1.self, T2.self, T3.self, request: request, response: response) { typeSafeMiddleware1, typeSafeMiddleware2, typeSafeMiddleware3 in
                          guard let typeSafeMiddleware1 = typeSafeMiddleware1, let typeSafeMiddleware2 = typeSafeMiddleware2, let typeSafeMiddleware3 = typeSafeMiddleware3 else {
                              return next()
          Severity: Major
          Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 3 other locations - About 1 hr to fix
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 127..135
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 237..245
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1031..1039

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 105.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 4 locations. Consider refactoring.
          Open

                  delete(route) { request, response, next in
                      Log.verbose("Received DELETE (plural with middleware) type-safe request")
                      self.handleMiddleware(T1.self, T2.self, T3.self, request: request, response: response) { typeSafeMiddleware1, typeSafeMiddleware2, typeSafeMiddleware3 in
                          guard let typeSafeMiddleware1 = typeSafeMiddleware1, let typeSafeMiddleware2 = typeSafeMiddleware2, let typeSafeMiddleware3 = typeSafeMiddleware3 else {
                              return next()
          Severity: Major
          Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 3 other locations - About 1 hr to fix
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 127..135
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 237..245
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 475..483

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 105.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Function testRangeRequestsWithMultipleRanges has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              func testRangeRequestsWithMultipleRanges() {
                  performServerTest(router) { expectation in
                      self.performRequest("get", path: "/qwer/index.html", callback: { response in
                          defer {
                              expectation.fulfill()
          Severity: Minor
          Found in Tests/KituraTests/TestStaticFileServer.swift - About 1 hr to fix

            Function testSubdomains has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                func testSubdomains() {
                    performServerTest(router) { expectation in
                        self.performRequest("get", path: "/subdomains", callback: { response in
                            XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                            XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
            Severity: Minor
            Found in Tests/KituraTests/TestResponse.swift - About 1 hr to fix

              Function testBasicPatch has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  func testBasicPatch() {
                      router.patch("/users") { (id: Int, patchUser: OptionalUser, respondWith: (User?, RequestError?) -> Void) -> Void in
                          print("PATCH on /users/\(id)")
                          guard let existingUser = self.userStore[id] else {
                              respondWith(nil, .notFound)
              Severity: Minor
              Found in Tests/KituraTests/TestCodableRouter.swift - About 1 hr to fix
                Severity
                Category
                Status
                Source
                Language