NodeBB/NodeBB

View on GitHub

Showing 537 of 553 total issues

Consider simplifying this complex logical expression.
Open

    if (nconf.get('url')) {
        nconf.set('url', nconf.get('url').replace(/\/$/, ''));
        nconf.set('url_parsed', url.parse(nconf.get('url')));
        // Parse out the relative_url and other goodies from the configured URL
        const urlObject = url.parse(nconf.get('url'));
Severity: Major
Found in src/prestart.js - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

            if (shouldQueue) {
                const [userData, isPrivileged, isMemberOfExempt, categoryQueueEnabled] = await Promise.all([
                    user.getUserFields(uid, ['uid', 'reputation', 'postcount']),
                    user.isPrivileged(uid),
                    groups.isMemberOfAny(uid, meta.config.groupsExemptFromPostQueue),
    Severity: Major
    Found in src/posts/queue.js - About 1 hr to fix

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

              if ((!isArrayOfScores && !utils.isNumber(scores)) ||
                  (isArrayOfScores && scores.map(s => utils.isNumber(s)).includes(false))) {
                  throw new Error(`[[error:invalid-score, ${scores}]]`);
              }
      Severity: Major
      Found in src/database/redis/sorted/add.js and 2 other locations - About 1 hr to fix
      src/database/mongo/sorted/add.js on lines 56..59
      src/database/postgres/sorted/add.js on lines 72..75

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

      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

              if ((!isArrayOfScores && !utils.isNumber(scores)) ||
                  (isArrayOfScores && scores.map(s => utils.isNumber(s)).includes(false))) {
                  throw new Error(`[[error:invalid-score, ${scores}]]`);
              }
      Severity: Major
      Found in src/database/mongo/sorted/add.js and 2 other locations - About 1 hr to fix
      src/database/postgres/sorted/add.js on lines 72..75
      src/database/redis/sorted/add.js on lines 45..48

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

      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

              if ((!isArrayOfScores && !utils.isNumber(scores)) ||
                  (isArrayOfScores && scores.map(s => utils.isNumber(s)).includes(false))) {
                  throw new Error(`[[error:invalid-score, ${scores}]]`);
              }
      Severity: Major
      Found in src/database/postgres/sorted/add.js and 2 other locations - About 1 hr to fix
      src/database/mongo/sorted/add.js on lines 56..59
      src/database/redis/sorted/add.js on lines 45..48

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

      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 deleteUserFromFollowedTags(uid) {
              const tags = await db.getSortedSetRange(`uid:${uid}:followed_tags`, 0, -1);
              await db.sortedSetsRemove(tags.map(tag => `tag:${tag}:followers`), uid);
          }
      Severity: Major
      Found in src/user/delete.js and 2 other locations - About 55 mins to fix
      src/user/delete.js on lines 166..169
      src/user/delete.js on lines 171..174

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

      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

      Topics.exists = async function (tids) {
          return await db.exists(
              Array.isArray(tids) ? tids.map(tid => `topic:${tid}`) : `topic:${tids}`
          );
      };
      Severity: Major
      Found in src/topics/index.js and 2 other locations - About 55 mins to fix
      src/categories/index.js on lines 27..31
      src/posts/index.js on lines 30..34

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

      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

      Categories.exists = async function (cids) {
          return await db.exists(
              Array.isArray(cids) ? cids.map(cid => `category:${cid}`) : `category:${cids}`
          );
      };
      Severity: Major
      Found in src/categories/index.js and 2 other locations - About 55 mins to fix
      src/posts/index.js on lines 30..34
      src/topics/index.js on lines 38..42

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

      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 deleteUserFromIgnoredTopics(uid) {
              const tids = await db.getSortedSetRange(`uid:${uid}:ignored_tids`, 0, -1);
              await db.setsRemove(tids.map(tid => `tid:${tid}:ignorers`), uid);
          }
      Severity: Major
      Found in src/user/delete.js and 2 other locations - About 55 mins to fix
      src/user/delete.js on lines 166..169
      src/user/delete.js on lines 176..179

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

      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

      Posts.exists = async function (pids) {
          return await db.exists(
              Array.isArray(pids) ? pids.map(pid => `post:${pid}`) : `post:${pids}`
          );
      };
      Severity: Major
      Found in src/posts/index.js and 2 other locations - About 55 mins to fix
      src/categories/index.js on lines 27..31
      src/topics/index.js on lines 38..42

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

      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 deleteUserFromFollowedTopics(uid) {
              const tids = await db.getSortedSetRange(`uid:${uid}:followed_tids`, 0, -1);
              await db.setsRemove(tids.map(tid => `tid:${tid}:followers`), uid);
          }
      Severity: Major
      Found in src/user/delete.js and 2 other locations - About 55 mins to fix
      src/user/delete.js on lines 171..174
      src/user/delete.js on lines 176..179

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

      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

      Users.updateSettings = async (req, res) => {
          const settings = await api.users.updateSettings(req, { ...req.body, uid: req.params.uid });
          helpers.formatApiResponse(200, res, settings);
      };
      Severity: Major
      Found in src/controllers/write/users.js and 2 other locations - About 55 mins to fix
      src/controllers/write/groups.js on lines 22..28
      src/controllers/write/users.js on lines 39..42

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

      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

      Users.update = async (req, res) => {
          const userObj = await api.users.update(req, { ...req.body, uid: req.params.uid });
          helpers.formatApiResponse(200, res, userObj);
      };
      Severity: Major
      Found in src/controllers/write/users.js and 2 other locations - About 55 mins to fix
      src/controllers/write/groups.js on lines 22..28
      src/controllers/write/users.js on lines 84..87

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

      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

      Groups.update = async (req, res) => {
          const groupObj = await api.groups.update(req, {
              ...req.body,
              slug: req.params.slug,
          });
      Severity: Major
      Found in src/controllers/write/groups.js and 2 other locations - About 55 mins to fix
      src/controllers/write/users.js on lines 39..42
      src/controllers/write/users.js on lines 84..87

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

      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 exports has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
      Open

      module.exports = function (SocketTopics) {
          SocketTopics.markAsRead = async function (socket, tids) {
              sockets.warnDeprecated(socket, 'PUT /api/v3/topics/:tid/read');
      
              if (!Array.isArray(tids) || socket.uid <= 0) {
      Severity: Minor
      Found in src/socket.io/topics/unread.js - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function register has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
      Open

      Hooks.register = function (id, data) {
          if (!data.hook || !data.method) {
              winston.warn(`[plugins/${id}] registerHook called with invalid data.hook/method`, data);
              return;
          }
      Severity: Minor
      Found in src/plugins/hooks.js - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function get has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
      Open

      privsTopics.get = async function (tid, uid) {
          uid = parseInt(uid, 10);
      
          const privs = [
              'topics:reply', 'topics:read', 'topics:schedule', 'topics:tag',
      Severity: Minor
      Found in src/privileges/topics.js - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function notAllowed has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
      Open

      helpers.notAllowed = async function (req, res, error) {
          ({ error } = await plugins.hooks.fire('filter:helpers.notAllowed', { req, res, error }));
      
          await plugins.hooks.fire('response:helpers.notAllowed', { req, res, error });
          if (res.headersSent) {
      Severity: Minor
      Found in src/controllers/helpers.js - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function loadConfig has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
      Open

      apiController.loadConfig = async function (req) {
          const config = {
              relative_path,
              upload_url,
              asset_base_url,
      Severity: Minor
      Found in src/controllers/api.js - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

      module.exports = function (module) {
          const helpers = require('../helpers');
      
          module.sortedSetRemove = async function (key, value) {
              if (!key) {
      Severity: Minor
      Found in src/database/redis/sorted/remove.js - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Severity
      Category
      Status
      Source
      Language