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) {
- Read upRead up
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.
*
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
- Read upRead up
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) {
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) {
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
- Read upRead up
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
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
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
- Read upRead up
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 = []
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
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
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) {
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
- Read upRead up
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 {
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]) {
- Read upRead up
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
Avoid too many return
statements within this function. Open
return 0