Showing 54 of 94 total issues
Function applyMiddleware
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
router.applyMiddleware = () => {
app = app || jsonApi._apiConfig.router || express()
app.use((req, res, next) => {
res.set({
'Content-Type': 'application/vnd.api+json',
Function _addBasicPaths
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
swaggerPaths._addBasicPaths = (paths, resourceName, resourceConfig) => {
const genericPaths = { }
const specificPaths = { }
paths[`/${resourceName}`] = genericPaths
paths[`/${resourceName}/{id}`] = specificPaths
Function register
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
searchRoute.register = () => {
router.bindRoute({
verb: 'get',
path: ':type'
}, (request, resourceConfig, res) => {
Function generatePageLinks
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
pagination.generatePageLinks = (request, handlerTotal) => {
const pageData = request.params.page
if (!handlerTotal || !pageData) {
return { }
}
- 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 iterate
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
const iterate = (text, node, filter) => {
if (text.length === 0) return null
const parts = text.split('.')
const first = parts.shift()
const rest = parts.join('.')
Function define
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
jsonApi.define = resourceConfig => {
if (!resourceConfig.resource.match(/^[A-Za-z0-9_]*$/)) {
throw new Error(`Resource '${resourceConfig.resource}' contains illegal characters!`)
}
resourceConfig.namespace = resourceConfig.namespace || 'default'
Function register
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
findRoute.register = () => {
router.bindRoute({
verb: 'get',
path: ':type/:id'
}, (request, resourceConfig, res) => {
Function _generateLink
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
responseHelper._generateLink = (item, schemaProperty, linkProperty) => {
const link = {
meta: {
relation: 'primary',
// type: schemaProperty._settings.__many || schemaProperty._settings.__one,
- 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 createReadType
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
readTypes.createReadType = (resourceConfig, otherTypes, allUnionTypes) => {
const someType = {
name: resourceConfig.resource,
description: resourceConfig.description,
args: filterArgs.generate(resourceConfig.resource),
Function _fetchRelatedResources
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
postProcess._fetchRelatedResources = (request, mainResource, callback) => {
// Fetch the other objects
let dataItems = mainResource[request.params.relation]
if (!dataItems) return callback(null, [ null ])
Function generatePageLinks
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
pagination.generatePageLinks = (request, handlerTotal) => {
const pageData = request.params.page
if (!handlerTotal || !pageData) {
return { }
}
Function parseAndValidate
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
filter.parseAndValidate = request => {
if (!request.params.filter) return null
const resourceConfig = request.resourceConfig
- 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 simpleAttribute
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
joiConverter.simpleAttribute = joiScheme => {
let type = joiScheme._type
if (type === 'any') {
// { _valids: { _set: [ 'M', 'F' ] } }
type = typeof (joiScheme._valids._set || [ ])[0]
- 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 route
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
rerouter.route = (newRequest, callback) => {
const validRoutes = router._routes[newRequest.method.toLowerCase()]
const path = rerouter._generateSanePath(newRequest)
const route = rerouter._pickFirstMatchingRoute(validRoutes, path)
Function _getParams
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
router._getParams = req => {
let urlParts = req.url.split(jsonApi._apiConfig.base)
urlParts.shift()
urlParts = urlParts.join(jsonApi._apiConfig.base).split('?')
Function action
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
fields.action = (request, response, callback) => {
const resourceList = request.params.fields
if (!resourceList || !(resourceList instanceof Object)) return callback()
const allDataItems = response.included.concat(response.data)
Function generateWriteSchema
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
jsonApiGraphQL.generateWriteSchema = (allReadTypes, allResourceConfig, allWriteTypes) => {
const result = { }
Object.keys(allResourceConfig).forEach(resource => {
const resourceConfig = allResourceConfig[resource]
Function verifyRequest
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
helper.verifyRequest = (request, resourceConfig, res, handlerRequest, callback) => {
if (!resourceConfig) {
return helper.handleError(request, res, {
status: '404',
code: 'ENOTFOUND',
Function action
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
fields.action = (request, response, callback) => {
const resourceList = request.params.fields
if (!resourceList || !(resourceList instanceof Object)) return callback()
const allDataItems = response.included.concat(response.data)
- 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 validate
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
schemaValidator.validate = function (resources) {
Object.keys(resources).forEach(resource => {
Object.keys(resources[resource].attributes).forEach(attribute => {
const joiSchema = resources[resource].attributes[attribute]
if (!joiSchema._settings) return
- 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"