NodeBB/NodeBB

View on GitHub
src/controllers/helpers.js

Summary

Maintainability
B
6 hrs
Test Coverage

File helpers.js has 522 lines of code (exceeds 500 allowed). Consider refactoring.
Open

'use strict';

const nconf = require('nconf');
const validator = require('validator');
const querystring = require('querystring');
Severity: Major
Found in src/controllers/helpers.js - About 2 hrs to fix

    Function formatApiResponse has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
    Open

    helpers.formatApiResponse = async (statusCode, res, payload) => {
        if (res.req.method === 'HEAD') {
            return res.sendStatus(statusCode);
        }
    
    
    Severity: Minor
    Found in src/controllers/helpers.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 notAllowed has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

    helpers.notAllowed = async function (req, res, error) {
        ({ error } = await plugins.hooks.fire('filter:helpers.notAllowed', { req, res, error }));
    
        await plugins.hooks.fire('response:helpers.notAllowed', { req, res, error });
        if (res.headersSent) {
    Severity: Minor
    Found in src/controllers/helpers.js - About 55 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

    Function getCategoryData has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    async function getCategoryData(cids, uid, selectedCid, states, privilege) {
    Severity: Minor
    Found in src/controllers/helpers.js - About 35 mins to fix

      Function redirect has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
      Open

      helpers.redirect = function (res, url, permanent) {
          // this is used by sso plugins to redirect to the auth route
          // { external: '/auth/sso' } or { external: 'https://domain/auth/sso' }
          if (url.hasOwnProperty('external')) {
              const redirectUrl = encodeURI(prependRelativePath(url.external));
      Severity: Minor
      Found in src/controllers/helpers.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

      There are no issues that match your filters.

      Category
      Status