matteozambon89/trailpack-koa

View on GitHub
lib/server.js

Summary

Maintainability
F
5 days
Test Coverage

Function _generateKoaRoute has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

  _generateKoaRoute (app, koa, router, route) {
    // Make sure url params are defined as:
    // :x
    // instead of
    // {x}
Severity: Minor
Found in lib/server.js - About 3 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 _createWebServer has 84 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  _createWebServer(app, koa) {
    return new Promise((resolve, reject) => {
      let nativeServer
      let serverType

Severity: Major
Found in lib/server.js - About 3 hrs to fix

    File server.js has 300 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /**
     * @Author: Matteo Zambon <Matteo>
     * @Date:   2018-02-15 09:55:24
     * @Last modified by:   Matteo
     * @Last modified time: 2018-02-18 04:43:44
    Severity: Minor
    Found in lib/server.js - About 3 hrs to fix

      Function _generateKoaRoute has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _generateKoaRoute (app, koa, router, route) {
          // Make sure url params are defined as:
          // :x
          // instead of
          // {x}
      Severity: Major
      Found in lib/server.js - About 2 hrs to fix

        Function registerFeatures has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

          registerFeatures (app, koa) {
            // Set onError handler, if function is specified
            if (typeof app.config.web.onError === 'function') {
              koa.context.onerror = app.config.web.onError
            }
        Severity: Minor
        Found in lib/server.js - 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 registerFeatures has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          registerFeatures (app, koa) {
            // Set onError handler, if function is specified
            if (typeof app.config.web.onError === 'function') {
              koa.context.onerror = app.config.web.onError
            }
        Severity: Minor
        Found in lib/server.js - About 1 hr to fix

          Function _registerRoutes has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _registerRoutes(app, koa) {
              // Reverse routes to have parametrized routes first
              const routes = app.routes.reverse()
          
              const router = new KoaRouter()
          Severity: Minor
          Found in lib/server.js - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                    if (!customMiddlewares) {
                      return
                    }
            Severity: Major
            Found in lib/server.js - About 45 mins to fix

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

                  if (app.config.web.respond && !app.config.web.middlewares.respond) {
                    app.config.web.middlewares.respond = require('koa-respond')(
                      typeof app.config.web.respond === 'object' ?
                        app.config.web.respond : {}
                    )
              Severity: Major
              Found in lib/server.js and 3 other locations - About 3 hrs to fix
              lib/server.js on lines 117..122
              lib/server.js on lines 125..130
              lib/server.js on lines 142..147

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

              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

                  if (app.config.web.bodyparser && !app.config.web.middlewares.bodyparser) {
                    app.config.web.middlewares.bodyparser = require('koa-bodyparser')(
                      typeof app.config.web.bodyparser === 'object' ?
                        app.config.web.bodyparser : {}
                    )
              Severity: Major
              Found in lib/server.js and 3 other locations - About 3 hrs to fix
              lib/server.js on lines 117..122
              lib/server.js on lines 125..130
              lib/server.js on lines 150..155

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

              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

                  if (app.config.web.cors && !app.config.web.middlewares.cors) {
                    app.config.web.middlewares.cors = require('@koa/cors')(
                      typeof app.config.web.cors === 'object' ?
                        app.config.web.cors : {}
                    )
              Severity: Major
              Found in lib/server.js and 3 other locations - About 3 hrs to fix
              lib/server.js on lines 117..122
              lib/server.js on lines 142..147
              lib/server.js on lines 150..155

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

              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

                  if (app.config.web.compress && !app.config.web.middlewares.compress) {
                    app.config.web.middlewares.compress = require('koa-compress')(
                      typeof app.config.web.compress === 'object' ?
                        app.config.web.compress : {}
                    )
              Severity: Major
              Found in lib/server.js and 3 other locations - About 3 hrs to fix
              lib/server.js on lines 125..130
              lib/server.js on lines 142..147
              lib/server.js on lines 150..155

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

              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 (app.config.web.spdy && app.config.web.ssl) {
                      const spdyParams = _.merge(
                        app.config.web.spdy,
                        app.config.web.ssl
                      )
              Severity: Major
              Found in lib/server.js and 1 other location - About 1 hr to fix
              lib/server.js on lines 224..241

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

              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

                    else if (app.config.web.https && app.config.web.ssl) {
                      const httpsParams = _.merge(
                        app.config.web.https,
                        app.config.web.ssl
                      )
              Severity: Major
              Found in lib/server.js and 1 other location - About 1 hr to fix
              lib/server.js on lines 215..241

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

              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

                    if (result.error) {
                      const message = lib.Utils.message('warn-malformed-route-cors', route.path)
                      app.logger.warn(message)
                      app.logger.verbose('warn-malformed-route-cors', route, result)
                    }
              Severity: Major
              Found in lib/server.js and 2 other locations - About 1 hr to fix
              lib/server.js on lines 475..488
              lib/server.js on lines 496..507

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

              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

                      if (result.error) {
                        const message = lib.Utils.message('warn-malformed-route-redirect', route.path)
                        app.logger.warn(message)
                        app.logger.verbose('warn-malformed-route-redirect', route, result)
                      }
              Severity: Major
              Found in lib/server.js and 2 other locations - About 1 hr to fix
              lib/server.js on lines 452..459
              lib/server.js on lines 475..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 60.

              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

                      if (result.error) {
                        const message = lib.Utils.message('warn-malformed-route-serve', route.path)
                        app.logger.warn(message)
                        app.logger.verbose('warn-malformed-route-serve', route, result)
                      }
              Severity: Major
              Found in lib/server.js and 2 other locations - About 1 hr to fix
              lib/server.js on lines 452..459
              lib/server.js on lines 496..507

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

              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

              Parsing error: The keyword 'const' is reserved
              Open

              const http = require('http')
              Severity: Minor
              Found in lib/server.js by eslint

              For more information visit Source: http://eslint.org/docs/rules/

              There are no issues that match your filters.

              Category
              Status