matteozambon89/trailpack-koa

View on GitHub

Showing 84 of 84 total issues

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

    response.then(elements => {
      if (!elements) {
        throw Boom.notFound('Not Found')
      }
      ctx.body = elements || {}
Severity: Major
Found in api/controllers/FootprintController.js and 1 other location - About 6 hrs to fix
api/controllers/FootprintController.js on lines 210..226

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

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

    response.then(elements => {
      if (!elements) {
        throw Boom.notFound('Not Found')
      }
      ctx.body = elements || {}
Severity: Major
Found in api/controllers/FootprintController.js and 1 other location - About 6 hrs to fix
api/controllers/FootprintController.js on lines 67..83

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

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 4 locations. Consider refactoring.
Open

    response.then(elements => {
      ctx.body = elements || {}
      next()
    }).catch(err => {
      if (err.code == 'E_VALIDATION') {
Severity: Major
Found in api/controllers/FootprintController.js and 3 other locations - About 5 hrs to fix
api/controllers/FootprintController.js on lines 136..149
api/controllers/FootprintController.js on lines 261..274
api/controllers/FootprintController.js on lines 305..318

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

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 4 locations. Consider refactoring.
Open

    response.then(elements => {
      ctx.body = elements || {}
      next()
    }).catch(err => {
      if (err.code == 'E_VALIDATION') {
Severity: Major
Found in api/controllers/FootprintController.js and 3 other locations - About 5 hrs to fix
api/controllers/FootprintController.js on lines 106..119
api/controllers/FootprintController.js on lines 261..274
api/controllers/FootprintController.js on lines 305..318

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

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 4 locations. Consider refactoring.
Open

    response.then(elements => {
      ctx.body = elements || {}
      next()
    }).catch(err => {
      if (err.code == 'E_VALIDATION') {
Severity: Major
Found in api/controllers/FootprintController.js and 3 other locations - About 5 hrs to fix
api/controllers/FootprintController.js on lines 106..119
api/controllers/FootprintController.js on lines 136..149
api/controllers/FootprintController.js on lines 305..318

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

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 4 locations. Consider refactoring.
Open

    response.then(elements => {
      ctx.body = elements || {}
      next()
    }).catch(err => {
      if (err.code == 'E_VALIDATION') {
Severity: Major
Found in api/controllers/FootprintController.js and 3 other locations - About 5 hrs to fix
api/controllers/FootprintController.js on lines 106..119
api/controllers/FootprintController.js on lines 136..149
api/controllers/FootprintController.js on lines 261..274

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

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 _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

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

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

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

      findAssociation(ctx, next) {
        const criteria = this.app.packs.koa.getCriteriaFromQuery(this.query)
        if (ctx.params.childId && !_.isEmpty(criteria)) {
          throw Boom.preconditionFailed(this.__('errors.footprints.find.mutex'))
        }
    Severity: Major
    Found in api/policies/FootprintPolicy.js and 1 other location - About 3 hrs to fix
    api/policies/FootprintPolicy.js on lines 41..49

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

    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

    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

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

        find(ctx, next) {
          const criteria = this.app.packs.koa.getCriteriaFromQuery(this.query)
      
          if (ctx.params.id && !_.isEmpty(criteria)) {
            throw Boom.preconditionFailed(this.__('errors.footprints.find.mutex'))
      Severity: Major
      Found in api/policies/FootprintPolicy.js and 1 other location - About 3 hrs to fix
      api/policies/FootprintPolicy.js on lines 93..100

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

      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 _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

        File FootprintController.js has 278 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        /**
         * @Author: Matteo Zambon <Matteo>
         * @Date:   2018-02-12 11:41:41
         * @Last modified by:   Matteo
         * @Last modified time: 2018-02-18 01:20:29
        Severity: Minor
        Found in api/controllers/FootprintController.js - About 2 hrs to fix

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

            missingAppPath (path, app, reject) {
              path = path || '???'
              reject = reject || Promise.reject
          
              const message = lib.Utils.message('error-missing-app-path', path)
          Severity: Major
          Found in lib/error.js and 1 other location - About 2 hrs to fix
          lib/error.js on lines 77..86

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

          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

            missingSchemaPath (path, app, reject) {
              path = path || '???'
              reject = reject || Promise.reject
          
              const message = lib.Utils.message('error-missing-schema-path', path)
          Severity: Major
          Found in lib/error.js and 1 other location - About 2 hrs to fix
          lib/error.js on lines 58..67

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

          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

          Severity
          Category
          Status
          Source
          Language