tunnckoCore/koa-better-router

View on GitHub

Showing 4 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

      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