NodeBB/NodeBB

View on GitHub

Showing 537 of 553 total issues

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

    method: async function () {
        const groupsAPI = require('../../groups');
        const privilegesAPI = require('../../privileges');

        const cids = await db.getSortedSetRange('categories:cid', 0, -1);
Severity: Minor
Found in src/upgrades/1.2.0/edit_delete_deletetopic_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 openChangeModal has 85 lines of code (exceeds 75 allowed). Consider refactoring.
Open

    Picture.openChangeModal = () => {
        socket.emit('user.getProfilePictures', {
            uid: ajaxify.data.uid,
        }, function (err, pictures) {
            if (err) {
Severity: Major
Found in public/src/modules/accounts/picture.js - About 1 hr to fix

    Function processRender has 84 lines of code (exceeds 75 allowed). Consider refactoring.
    Open

        middleware.processRender = function processRender(req, res, next) {
            // res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687
            const { render } = res;
    
            res.render = async function renderOverride(template, options, fn) {
    Severity: Major
    Found in src/middleware/render.js - About 1 hr to fix

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

      module.exports = function (module) {
          const helpers = require('./helpers');
      
          module.listPrepend = async function (key, value) {
              if (!key) {
      Severity: Major
      Found in src/database/mongo/list.js - About 1 hr to fix

        Function create has 84 lines of code (exceeds 75 allowed). Consider refactoring.
        Open

            Categories.create = async function (data) {
                const parentCid = data.parentCid ? data.parentCid : 0;
                const [cid, firstChild] = await Promise.all([
                    db.incrObjectField('global', 'nextCid'),
                    db.getSortedSetRangeWithScores(`cid:${parentCid}:children`, 0, 0),
        Severity: Major
        Found in src/categories/create.js - About 1 hr to fix

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

          define('forum/account/bookmarks', ['forum/account/header', 'forum/account/posts'], function (header, posts) {
              const Bookmarks = {};
          
              Bookmarks.init = function () {
                  header.init();
          Severity: Major
          Found in public/src/client/account/bookmarks.js and 3 other locations - About 1 hr to fix
          public/src/client/account/best.js on lines 4..16
          public/src/client/account/downvoted.js on lines 4..16
          public/src/client/account/upvoted.js on lines 4..16

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

          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 4 locations. Consider refactoring.
          Open

          define('forum/account/best', ['forum/account/header', 'forum/account/posts'], function (header, posts) {
              const Best = {};
          
              Best.init = function () {
                  header.init();
          Severity: Major
          Found in public/src/client/account/best.js and 3 other locations - About 1 hr to fix
          public/src/client/account/bookmarks.js on lines 4..16
          public/src/client/account/downvoted.js on lines 4..16
          public/src/client/account/upvoted.js on lines 4..16

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

          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 4 locations. Consider refactoring.
          Open

          define('forum/account/downvoted', ['forum/account/header', 'forum/account/posts'], function (header, posts) {
              const Downvoted = {};
          
              Downvoted.init = function () {
                  header.init();
          Severity: Major
          Found in public/src/client/account/downvoted.js and 3 other locations - About 1 hr to fix
          public/src/client/account/best.js on lines 4..16
          public/src/client/account/bookmarks.js on lines 4..16
          public/src/client/account/upvoted.js on lines 4..16

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

          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 4 locations. Consider refactoring.
          Open

          define('forum/account/upvoted', ['forum/account/header', 'forum/account/posts'], function (header, posts) {
              const Upvoted = {};
          
              Upvoted.init = function () {
                  header.init();
          Severity: Major
          Found in public/src/client/account/upvoted.js and 3 other locations - About 1 hr to fix
          public/src/client/account/best.js on lines 4..16
          public/src/client/account/bookmarks.js on lines 4..16
          public/src/client/account/downvoted.js on lines 4..16

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

          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

          Consider simplifying this complex logical expression.
          Open

                  if (pids.length) {
                      ({ pids } = await plugins.hooks.fire('filter:account.profile.getPids', {
                          uid: callerUid,
                          userData,
                          setSuffix,
          Severity: Critical
          Found in src/controllers/accounts/profile.js - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

                    if (!room ||
                        (!room.public && !inRoom) ||
                        (room.public && (
                            Array.isArray(room.groups) && room.groups.length && !isAdmin && !(await groups.isMemberOfAny(uid, room.groups)))
                        )
            Severity: Critical
            Found in src/messaging/rooms.js - About 1 hr to fix

              Function init has 83 lines of code (exceeds 75 allowed). Consider refactoring.
              Open

                  Register.init = function () {
                      const username = $('#username');
                      const password = $('#password');
                      const password_confirm = $('#password-confirm');
                      const register = $('#register');
              Severity: Major
              Found in public/src/client/register.js - About 1 hr to fix

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

                privsAdmin.rescind = async function (privileges, groupName) {
                    await helpers.giveOrRescind(groups.leave, privileges, 0, groupName);
                    plugins.hooks.fire('action:privileges.admin.rescind', {
                        privileges: privileges,
                        groupNames: Array.isArray(groupName) ? groupName : [groupName],
                Severity: Major
                Found in src/privileges/admin.js and 3 other locations - About 1 hr to fix
                src/privileges/admin.js on lines 196..202
                src/privileges/global.js on lines 128..134
                src/privileges/global.js on lines 136..142

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

                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 4 locations. Consider refactoring.
                Open

                privsGlobal.give = async function (privileges, groupName) {
                    await helpers.giveOrRescind(groups.join, privileges, 0, groupName);
                    plugins.hooks.fire('action:privileges.global.give', {
                        privileges: privileges,
                        groupNames: Array.isArray(groupName) ? groupName : [groupName],
                Severity: Major
                Found in src/privileges/global.js and 3 other locations - About 1 hr to fix
                src/privileges/admin.js on lines 196..202
                src/privileges/admin.js on lines 204..210
                src/privileges/global.js on lines 136..142

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

                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

                    function showPostsSelected() {
                        if (postSelect.pids.length) {
                            forkModal.find('#fork-pids').translateHtml('[[topic:fork-pid-count, ' + postSelect.pids.length + ']]');
                        } else {
                            forkModal.find('#fork-pids').translateHtml('[[topic:fork-no-pids]]');
                Severity: Major
                Found in public/src/client/topic/fork.js and 2 other locations - About 1 hr to fix
                public/src/client/topic/change-owner.js on lines 47..53
                public/src/client/topic/delete-posts.js on lines 63..69

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

                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 5 locations. Consider refactoring.
                Open

                                {
                                    label: translations[1],
                                    fill: 'origin',
                                    tension: tension,
                                    backgroundColor: '#ab464233',
                Severity: Major
                Found in public/src/admin/dashboard.js and 4 other locations - About 1 hr to fix
                public/src/admin/dashboard.js on lines 182..193
                public/src/admin/dashboard.js on lines 206..217
                public/src/admin/dashboard.js on lines 218..229
                public/src/admin/dashboard.js on lines 230..241

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

                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 5 locations. Consider refactoring.
                Open

                                {
                                    label: translations[3],
                                    fill: 'origin',
                                    tension: tension,
                                    backgroundColor: '#f7ca8833',
                Severity: Major
                Found in public/src/admin/dashboard.js and 4 other locations - About 1 hr to fix
                public/src/admin/dashboard.js on lines 182..193
                public/src/admin/dashboard.js on lines 194..205
                public/src/admin/dashboard.js on lines 206..217
                public/src/admin/dashboard.js on lines 230..241

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

                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 4 locations. Consider refactoring.
                Open

                privsGlobal.rescind = async function (privileges, groupName) {
                    await helpers.giveOrRescind(groups.leave, privileges, 0, groupName);
                    plugins.hooks.fire('action:privileges.global.rescind', {
                        privileges: privileges,
                        groupNames: Array.isArray(groupName) ? groupName : [groupName],
                Severity: Major
                Found in src/privileges/global.js and 3 other locations - About 1 hr to fix
                src/privileges/admin.js on lines 196..202
                src/privileges/admin.js on lines 204..210
                src/privileges/global.js on lines 128..134

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

                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

                    function showPostsSelected() {
                        if (postSelect.pids.length) {
                            modal.find('#pids').translateHtml('[[topic:fork-pid-count, ' + postSelect.pids.length + ']]');
                        } else {
                            modal.find('#pids').translateHtml('[[topic:fork-no-pids]]');
                Severity: Major
                Found in public/src/client/topic/delete-posts.js and 2 other locations - About 1 hr to fix
                public/src/client/topic/change-owner.js on lines 47..53
                public/src/client/topic/fork.js on lines 98..104

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

                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

                    function showPostsSelected() {
                        if (postSelect.pids.length) {
                            modal.find('#pids').translateHtml('[[topic:fork-pid-count, ' + postSelect.pids.length + ']]');
                        } else {
                            modal.find('#pids').translateHtml('[[topic:fork-no-pids]]');
                Severity: Major
                Found in public/src/client/topic/change-owner.js and 2 other locations - About 1 hr to fix
                public/src/client/topic/delete-posts.js on lines 63..69
                public/src/client/topic/fork.js on lines 98..104

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

                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

                Severity
                Category
                Status
                Source
                Language