NodeBB/NodeBB

View on GitHub

Showing 536 of 552 total issues

Function sortedSetLex has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    async function sortedSetLex(key, min, max, sort, start, count) {
Severity: Minor
Found in src/database/postgres/sorted.js - About 45 mins to fix

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

    categoriesController.getAll = async function (req, res) {
        const rootCid = parseInt(req.query.cid, 10) || 0;
        async function getRootAndChildren() {
            const rootChildren = await categories.getAllCidsFromSet(`cid:${rootCid}:children`);
            const childCids = _.flatten(await Promise.all(rootChildren.map(cid => categories.getChildrenCids(cid))));
    Severity: Minor
    Found in src/controllers/admin/categories.js - About 45 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 sortedSetLex has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        async function sortedSetLex(key, min, max, sort, start, count) {
    Severity: Minor
    Found in src/database/mongo/sorted.js - About 45 mins to fix

      Function setupFallbackTransport has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

      Emailer.setupFallbackTransport = (config) => {
          winston.verbose('[emailer] Setting up fallback transport');
          // Enable SMTP transport if enabled in ACP
          if (parseInt(config['email:smtpTransport:enabled'], 10) === 1) {
              const smtpOptions = {
      Severity: Minor
      Found in src/emailer.js - About 45 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 exports has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

      module.exports = function (User) {
          const deletesInProgress = {};
      
          User.delete = async (callerUid, uid) => {
              await User.deleteContent(callerUid, uid);
      Severity: Minor
      Found in src/user/delete.js - About 45 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 update has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

      chatsAPI.update = async (caller, data) => {
          if (!data || !data.roomId) {
              throw new Error('[[error:invalid-data]]');
          }
      
      
      Severity: Minor
      Found in src/api/chats.js - About 45 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 setUnread has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

      Categories.setUnread = async function (tree, cids, uid) {
          if (uid <= 0) {
              return;
          }
          const { unreadCids } = await topics.getUnreadData({
      Severity: Minor
      Found in src/categories/index.js - About 45 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 leave has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

      groupsAPI.leave = async function (caller, data) {
          if (!data) {
              throw new Error('[[error:invalid-data]]');
          }
          if (caller.uid <= 0) {
      Severity: Minor
      Found in src/api/groups.js - About 45 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 addReport has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      Flags.addReport = async function (flagId, type, id, uid, reason, timestamp) {
      Severity: Minor
      Found in src/flags.js - About 45 mins to fix

        Function Settings has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        function Settings(hash, version, defCfg, callback, forceUpdate, reset) {
        Severity: Minor
        Found in src/settings.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                      if (targetUid) {
                                          await db.setObjectField(`flag:${flagObj.flagId}`, 'targetUid', targetUid);
                                      }
          Severity: Major
          Found in src/upgrades/1.15.0/add_target_uid_to_flags.js - About 45 mins to fix

            Function create has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            Flags.create = async function (type, id, uid, reason, timestamp, forceFlag = false) {
            Severity: Minor
            Found in src/flags.js - About 45 mins to fix

              Function installAll has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
              Open

              pkgInstall.installAll = () => {
                  const prod = process.env.NODE_ENV !== 'development';
                  let command = 'npm install';
              
                  const supportedPackageManagerList = exports.supportedPackageManager; // load config from src/cli/package-install.js
              Severity: Minor
              Found in src/cli/package-install.js - About 45 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

              Avoid deeply nested control flow statements.
              Open

                                      } else if (flagObj.type === 'user') {
                                          await db.setObjectField(`flag:${flagObj.flagId}`, 'targetUid', targetId);
                                      }
              Severity: Major
              Found in src/upgrades/1.15.0/add_target_uid_to_flags.js - About 45 mins to fix

                Function method has a Cognitive Complexity of 13 (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.2.0/category_recent_tids.js - About 45 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 addWorkerEvents has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
                Open

                Loader.addWorkerEvents = function (worker) {
                    worker.on('exit', (code, signal) => {
                        console.log(`[cluster] Child Process (${worker.pid}) has exited (code: ${code}, signal: ${signal})`);
                        if (!(worker.suicide || code === 0)) {
                            console.log('[cluster] Spinning up another process...');
                Severity: Minor
                Found in loader.js - About 45 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

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

                Users.deleteContent = async (req, res) => {
                    await api.users.deleteContent(req, { ...req.params, password: req.body.password });
                    helpers.formatApiResponse(200, res);
                };
                Severity: Major
                Found in src/controllers/write/users.js and 8 other locations - About 40 mins to fix
                src/controllers/write/users.js on lines 44..47
                src/controllers/write/users.js on lines 54..57
                src/controllers/write/users.js on lines 64..67
                src/controllers/write/users.js on lines 89..92
                src/controllers/write/users.js on lines 104..107
                src/controllers/write/users.js on lines 109..112
                src/controllers/write/users.js on lines 114..117
                src/controllers/write/users.js on lines 119..122

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

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

                Users.changePicture = async (req, res) => {
                    await api.users.changePicture(req, { ...req.body, uid: req.params.uid });
                    helpers.formatApiResponse(200, res);
                };
                Severity: Major
                Found in src/controllers/write/users.js and 8 other locations - About 40 mins to fix
                src/controllers/write/users.js on lines 44..47
                src/controllers/write/users.js on lines 49..52
                src/controllers/write/users.js on lines 54..57
                src/controllers/write/users.js on lines 89..92
                src/controllers/write/users.js on lines 104..107
                src/controllers/write/users.js on lines 109..112
                src/controllers/write/users.js on lines 114..117
                src/controllers/write/users.js on lines 119..122

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

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

                Users.unban = async (req, res) => {
                    await api.users.unban(req, { ...req.body, uid: req.params.uid });
                    helpers.formatApiResponse(200, res);
                };
                Severity: Major
                Found in src/controllers/write/users.js and 8 other locations - About 40 mins to fix
                src/controllers/write/users.js on lines 44..47
                src/controllers/write/users.js on lines 49..52
                src/controllers/write/users.js on lines 54..57
                src/controllers/write/users.js on lines 64..67
                src/controllers/write/users.js on lines 89..92
                src/controllers/write/users.js on lines 104..107
                src/controllers/write/users.js on lines 114..117
                src/controllers/write/users.js on lines 119..122

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

                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

                                } else if (numMinutes) {
                                    if (numSeconds) {
                                        msg = '[[error:' + languageKey + '-minutes-seconds, ' + numMinutes + ', ' + numSeconds + ']]';
                                    } else {
                                        msg = '[[error:' + languageKey + '-minutes, ' + numMinutes + ']]';
                Severity: Major
                Found in public/src/client/topic/postTools.js and 2 other locations - About 40 mins to fix
                public/src/client/topic/postTools.js on lines 205..223
                public/src/client/topic/postTools.js on lines 211..223

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

                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