tunnckoCore/koa-better-router

View on GitHub

Showing 9 of 9 total issues

File test.js has 329 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*!
 * koa-better-router <https://github.com/tunnckoCore/koa-better-router>
 *
 * Copyright (c) 2016 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
 * Released under the MIT license.
Severity: Minor
Found in test.js - About 3 hrs to fix

    Function createRoute has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    KoaBetterRouter.prototype.createRoute = function createRoute (method, route, fns) {
      let args = [].slice.call(arguments, 3)
      let middlewares = utils.arrayify(fns).concat(args)
    
      if (typeof method !== 'string') {
    Severity: Minor
    Found in index.js - About 1 hr to fix

      Function middleware has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      KoaBetterRouter.prototype.middleware = function middleware () {
        return (ctx, next) => {
          for (let route of this.routes) {
            if (ctx.method !== route.method) {
              continue
      Severity: Minor
      Found in index.js - 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 2 locations. Consider refactoring.
      Open

        api.get('/profiles/new', function (ctx, next) {
          ctx.body = `Create new profile. Route path: ${ctx.route.path}`
          return next()
        })
        .addRoute('GET /profiles/:profile', function * (next) {
      Severity: Major
      Found in test.js and 1 other location - About 1 hr to fix
      recipes/grouping/cats-router.js on lines 5..12

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

      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

      module.exports = catsRouter.get('/cats', function (ctx, next) {
        ctx.body = `List your cute cats! ${ctx.route.path}`
        return next()
      })
      .get('/cats/new', (ctx, next) => {
      Severity: Major
      Found in recipes/grouping/cats-router.js and 1 other location - About 1 hr to fix
      test.js on lines 191..198

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

      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

      let baz = router.createRoute('GET /baz/qux', (ctx, next) => {
        ctx.body = `Woo hoo, this is ${ctx.route.path}!`
        return next()
      })
      Severity: Major
      Found in recipes/grouping/example1.js and 2 other locations - About 50 mins to fix
      recipes/adding-a-route/example3.js on lines 6..9
      recipes/grouping/users-router.js on lines 5..9

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

      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

      router
        .get('/users', (ctx, next) => {
          ctx.body = `List awesome users! ${ctx.route.path}`
          return next()
        })
      Severity: Major
      Found in recipes/grouping/users-router.js and 2 other locations - About 50 mins to fix
      recipes/adding-a-route/example3.js on lines 6..9
      recipes/grouping/example1.js on lines 12..15

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

      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

      router.addRoute('GET /users', (ctx, next) => {
        ctx.body = `Route is ${ctx.route.path}`
        return next()
      })
      Severity: Major
      Found in recipes/adding-a-route/example3.js and 2 other locations - About 50 mins to fix
      recipes/grouping/example1.js on lines 12..15
      recipes/grouping/users-router.js on lines 5..9

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

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

      KoaBetterRouter.prototype.getRoute = function getRoute (name) {
        if (typeof name !== 'string') {
          throw new TypeError('.getRoute: expect `name` to be a string')
        }
        let res = null
      Severity: Minor
      Found in index.js - About 25 mins 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