IBM-Swift/Kitura

View on GitHub

Showing 850 of 850 total issues

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 middleware and Query Parameters")
            Log.verbose("Query Parameters: \(request.queryParameters)")
            self.handleMiddleware(T1.self, T2.self, request: request, response: response) { typeSafeMiddleware1, typeSafeMiddleware2 in
                guard let typeSafeMiddleware1 = typeSafeMiddleware1, let typeSafeMiddleware2 = typeSafeMiddleware2 else {
Severity: Major
Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 2 other locations - About 2 hrs to fix
Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 566..584
Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 769..785

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 158.

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

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

if ("katex" in window) {
  $($('.math').each( (_, element) => {
    katex.render(element.textContent, element, {
      displayMode: $(element).hasClass('m-block'),
      throwOnError: false,
docs/js/jazzy.js on lines 62..70

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 84.

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

    func testStar() {
        performServerTest(router, asyncTasks: { expectation in
            self.performRequest("get", path: "/2/star", callback: {response in
                    XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "Star route did not match single path request")
                  expectation.fulfill()
Severity: Major
Found in Tests/KituraTests/TestMultiplicity.swift and 3 other locations - About 2 hrs to fix
Tests/KituraTests/TestMultiplicity.swift on lines 35..52
Tests/KituraTests/TestMultiplicity.swift on lines 73..90
Tests/KituraTests/TestMultiplicity.swift on lines 92..109

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 157.

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

    func testCombined() {
        performServerTest(router, asyncTasks: { expectation in
            self.performRequest("get", path: "/4/question/plus", callback: {response in
                    XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "Complex route did not match dropped star ending")
                  expectation.fulfill()
Severity: Major
Found in Tests/KituraTests/TestMultiplicity.swift and 3 other locations - About 2 hrs to fix
Tests/KituraTests/TestMultiplicity.swift on lines 35..52
Tests/KituraTests/TestMultiplicity.swift on lines 54..71
Tests/KituraTests/TestMultiplicity.swift on lines 73..90

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 157.

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

    func testQuestion() {
        performServerTest(router, asyncTasks: { expectation in
            self.performRequest("get", path: "/3/question", callback: {response in
                    XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "Question route did not match single path request")
                  expectation.fulfill()
Severity: Major
Found in Tests/KituraTests/TestMultiplicity.swift and 3 other locations - About 2 hrs to fix
Tests/KituraTests/TestMultiplicity.swift on lines 35..52
Tests/KituraTests/TestMultiplicity.swift on lines 54..71
Tests/KituraTests/TestMultiplicity.swift on lines 92..109

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 157.

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

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

if ("katex" in window) {
  $($('.math').each( (_, element) => {
    katex.render(element.textContent, element, {
      displayMode: $(element).hasClass('m-block'),
      throwOnError: false,
Severity: Major
Found in docs/js/jazzy.js and 1 other location - About 2 hrs to fix
docs/docsets/Kitura.docset/Contents/Resources/Documents/js/jazzy.js on lines 62..70

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 84.

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

    func testPlus() {
        performServerTest(router, asyncTasks: { expectation in
            self.performRequest("get", path: "/1/plus", callback: {response in
                XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "Plus route did not match single path request")
                expectation.fulfill()
Severity: Major
Found in Tests/KituraTests/TestMultiplicity.swift and 3 other locations - About 2 hrs to fix
Tests/KituraTests/TestMultiplicity.swift on lines 54..71
Tests/KituraTests/TestMultiplicity.swift on lines 73..90
Tests/KituraTests/TestMultiplicity.swift on lines 92..109

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 157.

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 testBuildRegexFromPattern has 61 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    func testBuildRegexFromPattern() {
        var regex: NSRegularExpression?

        var isSimpleString = false
        var strings: [String]?
Severity: Major
Found in Tests/KituraTests/TestRouteRegex.swift - About 2 hrs to fix

    Function handle has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        public func handle(request: ServerRequest, response: ServerResponse) {
            var decoder: (() -> BodyDecoder)?
            if let contentType = request.headers["Content-Type"]?[0], let mediaType = MediaType(contentTypeHeader: contentType) {
                decoder = decoders[mediaType]
            }
    Severity: Minor
    Found in Sources/Kitura/Router.swift - About 2 hrs 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

    Function performSimpleMatch has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        private func performSimpleMatch(path: String, request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) {
            guard let pattern = pattern else {
                next()
                return
            }
    Severity: Minor
    Found in Sources/Kitura/RouterElement.swift - About 2 hrs 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

    Function testCustomCoderGet has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        func testCustomCoderGet() {
            struct SimpleQuery: QueryParams {
                let string: String
            }
            let jsonEncoder: () -> BodyEncoder = {
    Severity: Major
    Found in Tests/KituraTests/TestTypeSafeMiddleware.swift - About 2 hrs to fix

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

              performServerTest(router, asyncTasks: { expectation in
                  self.performRequest("get", path: "/root1/123/sub1/456/subsub1/789", callback: { response in
                      XCTAssertEqual(response?.statusCode, .OK)
      
                      var data = Data()
      Severity: Major
      Found in Tests/KituraTests/TestSubrouter.swift and 1 other location - About 2 hrs to fix
      Tests/KituraTests/TestSubrouter.swift on lines 193..212

      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 153.

      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

              }, { expectation in
                  self.performRequest("get", path: "/root1/123/sub1/456/subsub2/passthrough", callback: { response in
                      XCTAssertEqual(response?.statusCode, .OK)
      
                      var data = Data()
      Severity: Major
      Found in Tests/KituraTests/TestSubrouter.swift and 1 other location - About 2 hrs to fix
      Tests/KituraTests/TestSubrouter.swift on lines 174..193

      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 153.

      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

              buildServerTest(router, timeout: 30)
                  .request("put", path: "/users/1", data: user)
                  .hasStatus(.OK)
                  .hasContentType(withPrefix: "application/json")
                  .hasData(user)
      Severity: Major
      Found in Tests/KituraTests/TestCodableRouter.swift and 1 other location - About 2 hrs to fix
      Tests/KituraTests/TestCodableRouter.swift on lines 575..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 152.

      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

              buildServerTest(router, timeout: 30)
                  .request("patch", path: "/users/2", data: user)
                  .hasStatus(.OK)
                  .hasContentType(withPrefix: "application/json")
                  .hasData(user)
      Severity: Major
      Found in Tests/KituraTests/TestCodableRouter.swift and 1 other location - About 2 hrs to fix
      Tests/KituraTests/TestCodableRouter.swift on lines 476..492

      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 152.

      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 testMergeParams has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          func testMergeParams() {
              let simpleHandler = { (req: RouterRequest, res: RouterResponse, next: () -> Void) throws in
                  next()
              }
      
      
      Severity: Major
      Found in Tests/KituraTests/TestSubrouter.swift - About 2 hrs to fix

        Function testParameters has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            func testParameters() {
                let router = Router()
        
                router.parameter("user") { request, response, value, next in
                    XCTAssertNotNil(value)
        Severity: Major
        Found in Tests/KituraTests/TestRequests.swift - About 2 hrs to fix

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

                  delete(appendId(path: route)) { request, response, next in
                      Log.verbose("Received DELETE (singular 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 1 other location - About 2 hrs to fix
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 362..373

          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 145.

          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 middleware and Query Parameters")
                      Log.verbose("Query Parameters: \(request.queryParameters)")
                      self.handleMiddleware(T.self, request: request, response: response) { typeSafeMiddleware in
                          guard let typeSafeMiddleware = typeSafeMiddleware else {
          Severity: Major
          Found in Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift and 2 other locations - About 2 hrs to fix
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 518..536
          Sources/Kitura/CodableRouter+TypeSafeMiddleware.swift on lines 1194..1210

          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 145.

          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 handleMatch has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

                  private static func handleMatch(rawHeaderValue: String, type: String, matchAllPattern: String,
                                                  criteriaMatches: inout CriteriaMatches, headerOrder: Int) {
                      let parsedHeaderValue = parse(mediaType: rawHeaderValue)
                      let headerType = parsedHeaderValue.type
                      guard !headerType.isEmpty && parsedHeaderValue.qValue > 0.0 else {
          Severity: Minor
          Found in Sources/Kitura/MimeTypeAcceptor.swift - About 2 hrs 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

          Severity
          Category
          Status
          Source
          Language