NodeBB/NodeBB

View on GitHub

Showing 536 of 552 total issues

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

    longestArgumentTermLength(cmd, helper) {
        return helper.visibleArguments(cmd).reduce((max, argument) => Math.max(
            max,
            helper.argumentTerm(argument).length - getControlCharacterSpaces(helper.argumentTerm(argument))
        ), 0);
Severity: Major
Found in src/cli/colors.js and 2 other locations - About 50 mins to fix
src/cli/colors.js on lines 85..90
src/cli/colors.js on lines 91..96

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

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

        await module.transaction(async (client) => {
            await helpers.ensureLegacyObjectType(client, key, 'zset');
            await client.query({
                name: 'sortedSetAddBulk',
                text: `
Severity: Major
Found in src/database/postgres/sorted/add.js and 2 other locations - About 50 mins to fix
src/database/postgres/sorted/add.js on lines 21..32
src/database/postgres/sorted/add.js on lines 119..131

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

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

        await module.transaction(async (client) => {
            await helpers.ensureLegacyObjectType(client, key, 'set');
            await client.query({
                name: 'setAdd',
                text: `
Severity: Major
Found in src/database/postgres/sets.js and 2 other locations - About 50 mins to fix
src/database/postgres/main.js on lines 152..163
src/database/postgres/sets.js on lines 41..54

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

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

        await module.transaction(async (client) => {
            await helpers.ensureLegacyObjectsType(client, keys, 'set');
            await client.query({
                name: 'setsAdd',
                text: `
Severity: Major
Found in src/database/postgres/sets.js and 2 other locations - About 50 mins to fix
src/database/postgres/main.js on lines 152..163
src/database/postgres/sets.js on lines 15..27

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

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

        await module.transaction(async (client) => {
            await helpers.ensureLegacyObjectType(client, key, 'string');
            await client.query({
                name: 'set',
                text: `
Severity: Major
Found in src/database/postgres/main.js and 2 other locations - About 50 mins to fix
src/database/postgres/sets.js on lines 15..27
src/database/postgres/sets.js on lines 41..54

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

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

Avoid deeply nested control flow statements.
Open

                    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 - About 45 mins to fix

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

    SocketTopics.getMyNextPostIndex = async function (socket, data) {
        if (!data || !data.tid || !data.index || !data.sort) {
            throw new Error('[[error:invalid-data]]');
        }
    
    
    Severity: Minor
    Found in src/socket.io/topics.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 expose has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    async function expose(exposedField, method, field, req, res, next) {
    Severity: Minor
    Found in src/middleware/index.js - About 45 mins to fix

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

      Data.getStaticDirectories = async function (pluginData) {
          const validMappedPath = /^[\w\-_]+$/;
      
          if (!pluginData.staticDirs) {
              return;
      Severity: Minor
      Found in src/plugins/data.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 modifyTopic has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

      function modifyTopic(topic, fields) {
          if (!topic) {
              return;
          }
      
      
      Severity: Minor
      Found in src/topics/data.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 addArrayChildElement has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          function addArrayChildElement(field, key, attributes, value, separator, insertCb) {
      Severity: Minor
      Found in public/src/modules/settings/array.js - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                    if (!safeUrls.length || !safeUrls.some(function (url) { return href.indexOf(url) !== -1; })) {
                                        ajaxify.go('outgoing?url=' + encodeURIComponent(href));
                                        e.preventDefault();
                                    }
        Severity: Major
        Found in public/src/ajaxify.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                              if (!Array.isArray(widgetData[data[d].name])) {
                                                  widgetData[data[d].name] = [
                                                      widgetData[data[d].name],
                                                  ];
                                              }
          Severity: Major
          Found in public/src/admin/extend/widgets.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if (data.responseJSON.startsWith('http://') || data.responseJSON.startsWith('https://')) {
                                    window.location.href = data.responseJSON;
                                } else {
                                    ajaxify.go(data.responseJSON.slice(1), callback, quiet);
                                }
            Severity: Major
            Found in public/src/ajaxify.js - About 45 mins to fix

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

              module.exports = function (SocketUser) {
                  SocketUser.updateCover = async function (socket, data) {
                      if (!socket.uid) {
                          throw new Error('[[error:no-privileges]]');
                      }
              Severity: Minor
              Found in src/socket.io/user/profile.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 getTopicPosts has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  Topics.getTopicPosts = async function (topicData, set, start, stop, uid, reverse) {
              Severity: Minor
              Found in src/topics/posts.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if (toggle) {
                                            toggle.classList.toggle('invisible', true);
                                        }
                Severity: Major
                Found in public/src/admin/manage/categories.js - About 45 mins to fix

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

                  Topics.getTopicWithPosts = async function (topicData, set, uid, start, stop, reverse) {
                  Severity: Minor
                  Found in src/topics/index.js - About 45 mins to fix

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

                    module.exports = function (Topics) {
                        Topics.getSuggestedTopics = async function (tid, uid, start, stop, cutoff = 0) {
                            let tids;
                            tid = parseInt(tid, 10);
                            cutoff = cutoff === 0 ? cutoff : (cutoff * 2592000000);
                    Severity: Minor
                    Found in src/topics/suggested.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 uploadImage has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    async function uploadImage(filename, folder, uploadedFile, req, res, next) {
                    Severity: Minor
                    Found in src/controllers/admin/uploads.js - About 45 mins to fix
                      Severity
                      Category
                      Status
                      Source
                      Language