Showing 22 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
} else if (!allowed[ctx.method]) {
if (options.throw) {
let notAllowedThrowable
if (typeof options.methodNotAllowed === 'function') {
notAllowedThrowable = options.methodNotAllowed() // set whatever the user returns from their function
- Read upRead up
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 109.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!~implemented.indexOf(ctx.method)) {
if (options.throw) {
let notImplementedThrowable
if (typeof options.notImplemented === 'function') {
notImplementedThrowable = options.notImplemented() // set whatever the user returns from their function
- Read upRead up
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 109.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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.
*
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (typeof path === 'string' || path instanceof RegExp || Array.isArray(path)) {
middleware = Array.prototype.slice.call(arguments, 2)
} else {
middleware = Array.prototype.slice.call(arguments, 1)
path = name
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (typeof path === 'string' || path instanceof RegExp || Array.isArray(path)) {
middleware = Array.prototype.slice.call(arguments, 2)
} else {
middleware = Array.prototype.slice.call(arguments, 1)
path = name
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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"