NodeBB/NodeBB

View on GitHub

Showing 589 of 606 total issues

Function exports has a Cognitive Complexity of 33 (exceeds 10 allowed). Consider refactoring.
Open

module.exports = function (User) {
    const filterFnMap = {
        online: user => user.status !== 'offline' && (Date.now() - user.lastonline < 300000),
        flagged: user => parseInt(user.flags, 10) > 0,
        verified: user => !!user['email:confirmed'],
Severity: Minor
Found in src/user/search.js - About 4 hrs 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 126 lines of code (exceeds 50 allowed). Consider refactoring.
Open

module.exports = function (User) {
    new cronJob('0 * * * *', (() => {
        User.autoApprove();
    }), null, true);

Severity: Major
Found in src/user/approval.js - About 4 hrs to fix

    Function exports has 125 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    module.exports = function (Topics) {
        Topics.delete = async function (tid, uid) {
            await Promise.all([
                Topics.setTopicFields(tid, {
                    deleted: 1,
    Severity: Major
    Found in src/topics/delete.js - About 4 hrs to fix

      Consider simplifying this complex logical expression.
      Open

                  if (post) {
                      post.topicOwnerPost = parseInt(topicData.uid, 10) === parseInt(post.uid, 10);
                      post.display_edit_tools = topicPrivileges.isAdminOrMod || (post.selfPost && topicPrivileges['posts:edit']);
                      post.display_delete_tools = topicPrivileges.isAdminOrMod || (post.selfPost && topicPrivileges['posts:delete']);
                      post.display_moderator_tools = post.display_edit_tools || post.display_delete_tools;
      Severity: Critical
      Found in src/topics/posts.js - About 4 hrs to fix

        Function exports has 123 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        module.exports = function (module) {
            const helpers = require('./helpers');
            module.flushdb = async function () {
                await module.client.dropDatabase();
            };
        Severity: Major
        Found in src/database/mongo/main.js - About 3 hrs to fix

          Function getUsers has a Cognitive Complexity of 32 (exceeds 10 allowed). Consider refactoring.
          Open

          async function getUsers(req, res) {
              const sortDirection = req.query.sortDirection || 'desc';
              const reverse = sortDirection === 'desc';
          
              const page = parseInt(req.query.page, 10) || 1;
          Severity: Minor
          Found in src/controllers/admin/users.js - About 3 hrs 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 32 (exceeds 10 allowed). Consider refactoring.
          Open

          module.exports = function (module) {
              const helpers = require('./helpers');
              module.flushdb = async function () {
                  await module.client.dropDatabase();
              };
          Severity: Minor
          Found in src/database/mongo/main.js - About 3 hrs 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 122 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          module.exports = function (Topics) {
              Topics.createTopicFromPosts = async function (uid, title, pids, fromTid) {
                  if (title) {
                      title = title.trim();
                  }
          Severity: Major
          Found in src/topics/fork.js - About 3 hrs to fix

            File sorted.js has 578 lines of code (exceeds 500 allowed). Consider refactoring.
            Open

            'use strict';
            
            module.exports = function (module) {
                const helpers = require('./helpers');
                const util = require('util');
            Severity: Major
            Found in src/database/postgres/sorted.js - About 3 hrs to fix

              Function exports has 121 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              module.exports = function (SocketUser) {
                  SocketUser.changeUsernameEmail = async function (socket, data) {
                      sockets.warnDeprecated(socket, 'PUT /api/v3/users/:uid');
              
                      if (!data || !data.uid || !socket.uid) {
              Severity: Major
              Found in src/socket.io/user/profile.js - About 3 hrs to fix

                Function exports has 121 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                module.exports = function (User) {
                    const filterFnMap = {
                        online: user => user.status !== 'offline' && (Date.now() - user.lastonline < 300000),
                        flagged: user => parseInt(user.flags, 10) > 0,
                        verified: user => !!user['email:confirmed'],
                Severity: Major
                Found in src/user/search.js - About 3 hrs to fix

                  Function exports has a Cognitive Complexity of 31 (exceeds 10 allowed). Consider refactoring.
                  Open

                  module.exports = function (Topics) {
                      Topics.toggleFollow = async function (tid, uid) {
                          const exists = await Topics.exists(tid);
                          if (!exists) {
                              throw new Error('[[error:no-topic]]');
                  Severity: Minor
                  Found in src/topics/follow.js - About 3 hrs 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 31 (exceeds 10 allowed). Consider refactoring.
                  Open

                  module.exports = function (module) {
                      const helpers = require('../helpers');
                      const utils = require('../../../utils');
                  
                      module.sortedSetAdd = async function (key, score, value) {
                  Severity: Minor
                  Found in src/database/postgres/sorted/add.js - About 3 hrs 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 118 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  module.exports = function (module) {
                      const helpers = require('../helpers');
                      const utils = require('../../../utils');
                  
                      module.sortedSetAdd = async function (key, score, value) {
                  Severity: Major
                  Found in src/database/postgres/sorted/add.js - About 3 hrs to fix

                    Function init has 117 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                        ThreadTools.init = function (tid, topicContainer) {
                            renderMenu(topicContainer);
                    
                            // function topicCommand(method, path, command, onComplete) {
                            topicContainer.on('click', '[component="topic/delete"]', function () {
                    Severity: Major
                    Found in public/src/client/topic/threadTools.js - About 3 hrs to fix

                      Function init has 115 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

                          AdminsMods.init = function () {
                              autocomplete.user($('#admin-search'), function (ev, ui) {
                                  socket.emit('admin.user.makeAdmins', [ui.item.user.uid], function (err) {
                                      if (err) {
                                          return app.alertError(err.message);
                      Severity: Major
                      Found in public/src/admin/manage/admins-mods.js - About 3 hrs to fix

                        Function enableTopicSearch has 115 lines of code (exceeds 50 allowed). Consider refactoring.
                        Open

                            app.enableTopicSearch = function (options) {
                                if (!config.searchEnabled || !app.user.privileges['search:content']) {
                                    return;
                                }
                                /* eslint-disable-next-line */
                        Severity: Major
                        Found in public/src/app.js - About 3 hrs to fix

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

                                                  function (next) {
                                                      async.eachSeries(users, (user, next) => {
                                                          if (user.privileges['topics:create']) {
                                                              return groupsAPI.join(`cid:${cid}:privileges:topics:delete`, user.uid, (err) => {
                                                                  if (!err) {
                          Severity: Major
                          Found in src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js and 2 other locations - About 3 hrs to fix
                          src/upgrades/1.1.0/assign_topic_read_privilege.js on lines 30..44
                          src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js on lines 48..62

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

                          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 (next) {
                                                      async.eachSeries(groups, (group, next) => {
                                                          if (group.privileges['groups:read']) {
                                                              return groupsAPI.join(`cid:${cid}:privileges:groups:topics:read`, group.name, (err) => {
                                                                  if (!err) {
                          Severity: Major
                          Found in src/upgrades/1.1.0/assign_topic_read_privilege.js and 2 other locations - About 3 hrs to fix
                          src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js on lines 48..62
                          src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js on lines 81..95

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

                          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 (next) {
                                                      async.eachSeries(groups, (group, next) => {
                                                          if (group.privileges['groups:topics:create']) {
                                                              return groupsAPI.join(`cid:${cid}:privileges:groups:topics:delete`, group.name, (err) => {
                                                                  if (!err) {
                          Severity: Major
                          Found in src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js and 2 other locations - About 3 hrs to fix
                          src/upgrades/1.1.0/assign_topic_read_privilege.js on lines 30..44
                          src/upgrades/1.2.0/edit_delete_deletetopic_privileges.js on lines 81..95

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

                          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