zacanger/koa-modern-router

View on GitHub

Showing 18 of 22 total issues

Function allowedMethods has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

Router.prototype.allowedMethods = function (options) {
  options = options || {}
  const implemented = this.methods

  return function allowedMethods (ctx, next) {
Severity: Minor
Found in lib/router.js - About 6 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 router.js has 300 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable max-lines, func-style */

/**
 * RESTful resource routing middleware for koa.
 *
Severity: Minor
Found in lib/router.js - About 3 hrs to fix

    Function match has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    Router.prototype.match = function (path, method) {
      const layers = this.stack
      let layer
      let maxMatchLength = -1
      let maxMatchPathLength = -1
    Severity: Minor
    Found in lib/router.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 allowedMethods has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Router.prototype.allowedMethods = function (options) {
      options = options || {}
      const implemented = this.methods
    
      return function allowedMethods (ctx, next) {
    Severity: Minor
    Found in lib/router.js - About 1 hr to fix

      Function allowedMethods has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        return function allowedMethods (ctx, next) {
          return next().then(function () {
            const allowed = {}
      
            if (!ctx.status || ctx.status === 404) {
      Severity: Minor
      Found in lib/router.js - About 1 hr to fix

        Function url has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          url (params, options) {
            const toPath = pathToRegExp.compile(this.plainPath)
        
            let args = params
        
        
        Severity: Minor
        Found in lib/layer.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 use has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Router.prototype.use = function () {
          const router = this
          const middleware = Array.prototype.slice.call(arguments)
          let path
        
        
        Severity: Minor
        Found in lib/router.js - About 1 hr to fix

          Function match has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          Router.prototype.match = function (path, method) {
            const layers = this.stack
            let layer
            let maxMatchLength = -1
            let maxMatchPathLength = -1
          Severity: Minor
          Found in lib/router.js - About 1 hr to fix

            Function sortByMostSpecificLayer has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            const sortByMostSpecificLayer = (a, b) => {
              const wildA = a.path.endsWith('(.*)')
              const wildB = b.path.endsWith('(.*)')
              if (wildA && wildB) return a.path.length - b.path.length
              const pathA = wildA ? a.path.slice(0, -4) : a.path
            Severity: Minor
            Found in lib/router.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 constructor has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              constructor (path, methods, middleware, opts = {}) {
                this.opts = opts
                this.name = this.opts.name || null
                this.methods = []
                this.paramNames = []
            Severity: Minor
            Found in lib/layer.js - About 1 hr to fix

              Function middleware has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              Router.prototype.routes = Router.prototype.middleware = function () {
                const router = this
              
                const dispatch = function dispatch (ctx, next) {
                  const path = router.opts.routerPath || ctx.routerPath || ctx.path
              Severity: Minor
              Found in lib/router.js - About 1 hr to fix

                Function url has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  url (params, options) {
                    const toPath = pathToRegExp.compile(this.plainPath)
                
                    let args = params
                
                
                Severity: Minor
                Found in lib/layer.js - About 1 hr to fix

                  Function dispatch has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    const dispatch = function dispatch (ctx, next) {
                      const path = router.opts.routerPath || ctx.routerPath || ctx.path
                      const matched = router.match(path, ctx.method)
                  
                      if (ctx.matched) {
                  Severity: Minor
                  Found in lib/router.js - About 1 hr to fix

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

                    Router.prototype.routes = Router.prototype.middleware = function () {
                      const router = this
                    
                      const dispatch = function dispatch (ctx, next) {
                        const path = router.opts.routerPath || ctx.routerPath || ctx.path
                    Severity: Minor
                    Found in lib/router.js - About 45 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

                    Avoid deeply nested control flow statements.
                    Open

                                if (options.throw) {
                                  let notAllowedThrowable
                                  if (typeof options.methodNotAllowed === 'function') {
                                    notAllowedThrowable = options.methodNotAllowed() // set whatever the user returns from their function
                                  } else {
                    Severity: Major
                    Found in lib/router.js - About 45 mins to fix

                      Function params has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        params (path, captures, existingParams) {
                          const params = existingParams || {}
                      
                          for (let len = captures.length, i = 0; i < len; i++) {
                            if (this.paramNames[i]) {
                      Severity: Minor
                      Found in lib/layer.js - About 35 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

                      Avoid too many return statements within this function.
                      Open

                        if (wildB) return 1
                      Severity: Major
                      Found in lib/router.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                          return 0
                        Severity: Major
                        Found in lib/router.js - About 30 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language