NodeBB/NodeBB

View on GitHub

Showing 536 of 552 total issues

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

function modifyGroup(group, fields) {
    if (group) {
        db.parseIntFields(group, intFields, fields);

        escapeGroupData(group);
Severity: Minor
Found in src/groups/data.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 exports has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
Open

module.exports = function (Groups) {
    Groups.search = async function (query, options) {
        if (!query) {
            return [];
        }
Severity: Minor
Found in src/groups/search.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 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 exports has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
Open

module.exports = function (User) {
    User.startJobs = function () {
        winston.verbose('[user/jobs] (Re-)starting jobs...');

        let { digestHour } = meta.config;
Severity: Minor
Found in src/user/jobs.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 method has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
Open

    method: function (callback) {
        db.getSortedSetRange('categories:cid', 0, -1, (err, cids) => {
            if (err) {
                return callback(err);
            }
Severity: Minor
Found in src/upgrades/1.8.0/give_spiders_privileges.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 init has 89 lines of code (exceeds 75 allowed). Consider refactoring.
Open

    Groups.init = function () {
        const groupIcon = $('#group-icon');
        const changeGroupUserTitle = $('#change-group-user-title');
        const changeGroupLabelColor = $('#change-group-label-color');
        const changeGroupTextColor = $('#change-group-text-color');
Severity: Major
Found in public/src/admin/manage/group.js - About 1 hr to fix

    Function exports has 89 lines of code (exceeds 75 allowed). Consider refactoring.
    Open

    module.exports = function (SocketTopics) {
        SocketTopics.isTagAllowed = async function (socket, data) {
            if (!data || !utils.isNumber(data.cid) || !data.tag) {
                throw new Error('[[error:invalid-data]]');
            }
    Severity: Major
    Found in src/socket.io/topics/tags.js - About 1 hr to fix

      Function exports has 89 lines of code (exceeds 75 allowed). Consider refactoring.
      Open

      module.exports = function (middleware) {
          middleware.addHeaders = helpers.try((req, res, next) => {
              const headers = {
                  'X-Powered-By': encodeURI(meta.config['powered-by'] || 'NodeBB'),
                  'Access-Control-Allow-Methods': encodeURI(meta.config['access-control-allow-methods'] || ''),
      Severity: Major
      Found in src/middleware/headers.js - About 1 hr to fix

        Function list has 87 lines of code (exceeds 75 allowed). Consider refactoring.
        Open

        modsController.flags.list = async function (req, res) {
            const validFilters = ['assignee', 'state', 'reporterId', 'type', 'targetUid', 'cid', 'quick', 'page', 'perPage'];
            const validSorts = ['newest', 'oldest', 'reports', 'upvotes', 'downvotes', 'replies'];
        
            const results = await Promise.all([
        Severity: Major
        Found in src/controllers/mods.js - About 1 hr to fix

          Function exports has 87 lines of code (exceeds 75 allowed). Consider refactoring.
          Open

          module.exports = function (User) {
              User.blocks = {
                  _cache: cacheCreate({
                      name: 'user:blocks',
                      max: 100,
          Severity: Major
          Found in src/user/blocks.js - About 1 hr to fix

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                async function renderAdminFooter(req, res, options, headerFooterData) {
                    const hookReturn = await plugins.hooks.fire('filter:middleware.renderAdminFooter', {
                        req,
                        res,
                        templateValues: headerFooterData, // TODO: deprecate
            Severity: Major
            Found in src/middleware/render.js and 2 other locations - About 1 hr to fix
            src/middleware/render.js on lines 318..328
            src/middleware/render.js on lines 350..360

            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 84.

            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

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                async function renderHeader(req, res, options, headerFooterData) {
                    const hookReturn = await plugins.hooks.fire('filter:middleware.renderHeader', {
                        req: req,
                        res: res,
                        templateValues: headerFooterData, // TODO: deprecate
            Severity: Major
            Found in src/middleware/render.js and 2 other locations - About 1 hr to fix
            src/middleware/render.js on lines 350..360
            src/middleware/render.js on lines 362..372

            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 84.

            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

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                async function renderAdminHeader(req, res, options, headerFooterData) {
                    const hookReturn = await plugins.hooks.fire('filter:middleware.renderAdminHeader', {
                        req,
                        res,
                        templateValues: headerFooterData, // TODO: deprecate
            Severity: Major
            Found in src/middleware/render.js and 2 other locations - About 1 hr to fix
            src/middleware/render.js on lines 318..328
            src/middleware/render.js on lines 362..372

            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 84.

            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

            Further Reading

            Function getAll has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
            Open

            SocketRooms.getAll = async function () {
                const sockets = await io.server.fetchSockets();
            
                totals.onlineGuestCount = 0;
                totals.onlineRegisteredCount = 0;
            Severity: Minor
            Found in src/socket.io/admin/rooms.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 exports has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
            Open

            module.exports = function (module) {
                const helpers = require('./helpers');
            
                module.setAdd = async function (key, value) {
                    if (!Array.isArray(value)) {
            Severity: Minor
            Found in src/database/redis/sets.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 list has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
            Open

            modsController.flags.list = async function (req, res) {
                const validFilters = ['assignee', 'state', 'reporterId', 'type', 'targetUid', 'cid', 'quick', 'page', 'perPage'];
                const validSorts = ['newest', 'oldest', 'reports', 'upvotes', 'downvotes', 'replies'];
            
                const results = await Promise.all([
            Severity: Minor
            Found in src/controllers/mods.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 mergeBatch has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
            Open

            helpers.mergeBatch = function (batchData, start, stop, sort) {
                function getFirst() {
                    let selectedArray = batchData[0];
                    for (let i = 1; i < batchData.length; i++) {
                        if (batchData[i].length && (
            Severity: Minor
            Found in src/database/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 exports has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
            Open

            module.exports = function (Messaging) {
                Messaging.getUnreadCount = async (uid) => {
                    if (!(parseInt(uid, 10) > 0)) {
                        return 0;
                    }
            Severity: Minor
            Found in src/messaging/unread.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 join has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
            Open

            groupsAPI.join = async function (caller, data) {
                if (!data) {
                    throw new Error('[[error:invalid-data]]');
                }
                if (caller.uid <= 0 || !data.uid) {
            Severity: Minor
            Found in src/api/groups.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 listen has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
            Open

            async function listen() {
                let port = nconf.get('port');
                const isSocket = isNaN(port) && !Array.isArray(port);
                const socketPath = isSocket ? nconf.get('port') : '';
            
            
            Severity: Minor
            Found in src/webserver.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

            Severity
            Category
            Status
            Source
            Language