NodeBB/NodeBB

View on GitHub

Showing 538 of 554 total issues

Function addTags has 80 lines of code (exceeds 75 allowed). Consider refactoring.
Open

async function addTags(topicData, req, res, currentPage) {
    const postIndex = parseInt(req.params.post_index, 10) || 0;
    const postAtIndex = topicData.posts.find(p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10));
    let description = '';
    if (postAtIndex && postAtIndex.content) {
Severity: Major
Found in src/controllers/topics.js - About 1 hr to fix

    Function setupSearch has 79 lines of code (exceeds 75 allowed). Consider refactoring.
    Open

        function setupSearch(dict, searchEl) {
            const dropdown = searchEl.find('.dropdown');
            const menu = searchEl.find('.dropdown-menu');
            const input = searchEl.find('input');
            const placeholderText = dropdown.attr('data-text');
    Severity: Major
    Found in public/src/admin/modules/search.js - About 1 hr to fix

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

      module.exports = function (Groups) {
          Groups.create = async function (data) {
              const isSystem = isSystemGroup(data);
              const timestamp = data.timestamp || Date.now();
              let disableJoinRequests = parseInt(data.disableJoinRequests, 10) === 1 ? 1 : 0;
      Severity: Major
      Found in src/groups/create.js - About 1 hr to fix

        Function getTids has 79 lines of code (exceeds 75 allowed). Consider refactoring.
        Open

            async function getTids(params) {
                const counts = { '': 0, new: 0, watched: 0, unreplied: 0 };
                const tidsByFilter = { '': [], new: [], watched: [], unreplied: [] };
                const unreadCids = [];
                if (params.uid <= 0) {
        Severity: Major
        Found in src/topics/unread.js - About 1 hr to fix

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

              if (total.pageViewsRegistered > 0) {
                  incrByBulk.push(['analytics:pageviews:registered', total.pageViewsRegistered, today.getTime()]);
                  incrByBulk.push(['analytics:pageviews:month:registered', total.pageViewsRegistered, month.getTime()]);
                  total.pageViewsRegistered = 0;
              }
          Severity: Major
          Found in src/analytics.js and 3 other locations - About 1 hr to fix
          src/analytics.js on lines 148..152
          src/analytics.js on lines 160..164
          src/analytics.js on lines 166..170

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

          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

              if (total.pageViews > 0) {
                  incrByBulk.push(['analytics:pageviews', total.pageViews, today.getTime()]);
                  incrByBulk.push(['analytics:pageviews:month', total.pageViews, month.getTime()]);
                  total.pageViews = 0;
              }
          Severity: Major
          Found in src/analytics.js and 3 other locations - About 1 hr to fix
          src/analytics.js on lines 154..158
          src/analytics.js on lines 160..164
          src/analytics.js on lines 166..170

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

          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

              if (total.pageViewsGuest > 0) {
                  incrByBulk.push(['analytics:pageviews:guest', total.pageViewsGuest, today.getTime()]);
                  incrByBulk.push(['analytics:pageviews:month:guest', total.pageViewsGuest, month.getTime()]);
                  total.pageViewsGuest = 0;
              }
          Severity: Major
          Found in src/analytics.js and 3 other locations - About 1 hr to fix
          src/analytics.js on lines 148..152
          src/analytics.js on lines 154..158
          src/analytics.js on lines 166..170

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

          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

              if (total.pageViewsBot > 0) {
                  incrByBulk.push(['analytics:pageviews:bot', total.pageViewsBot, today.getTime()]);
                  incrByBulk.push(['analytics:pageviews:month:bot', total.pageViewsBot, month.getTime()]);
                  total.pageViewsBot = 0;
              }
          Severity: Major
          Found in src/analytics.js and 3 other locations - About 1 hr to fix
          src/analytics.js on lines 148..152
          src/analytics.js on lines 154..158
          src/analytics.js on lines 160..164

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

          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 init has 78 lines of code (exceeds 75 allowed). Consider refactoring.
          Open

              Themes.init = function () {
                  $('#installed_themes').on('click', function (e) {
                      const target = $(e.target);
                      const action = target.attr('data-action');
          
          
          Severity: Major
          Found in public/src/admin/appearance/themes.js - About 1 hr to fix

            Function reloadRoutes has 78 lines of code (exceeds 75 allowed). Consider refactoring.
            Open

            Auth.reloadRoutes = async function (params) {
                loginStrategies.length = 0;
                const { router } = params;
            
                // Local Logins
            Severity: Major
            Found in src/routes/authentication.js - About 1 hr to fix

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

              module.exports = function (User) {
                  User.follow = async function (uid, followuid) {
                      await toggleFollow('follow', uid, followuid);
                  };
              
              
              Severity: Major
              Found in src/user/follow.js - About 1 hr to fix

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

                Assert.topic = helpers.try(async (req, res, next) => {
                    if (!await topics.exists(req.params.tid)) {
                        return controllerHelpers.formatApiResponse(404, res, new Error('[[error:no-topic]]'));
                    }
                
                
                Severity: Major
                Found in src/middleware/assert.js and 3 other locations - About 1 hr to fix
                src/middleware/assert.js on lines 26..32
                src/middleware/assert.js on lines 43..49
                src/middleware/assert.js on lines 59..65

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

                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

                Assert.post = helpers.try(async (req, res, next) => {
                    if (!await posts.exists(req.params.pid)) {
                        return controllerHelpers.formatApiResponse(404, res, new Error('[[error:no-post]]'));
                    }
                
                
                Severity: Major
                Found in src/middleware/assert.js and 3 other locations - About 1 hr to fix
                src/middleware/assert.js on lines 26..32
                src/middleware/assert.js on lines 43..49
                src/middleware/assert.js on lines 51..57

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

                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

                Assert.user = helpers.try(async (req, res, next) => {
                    if (!await user.exists(req.params.uid)) {
                        return controllerHelpers.formatApiResponse(404, res, new Error('[[error:no-user]]'));
                    }
                
                
                Severity: Major
                Found in src/middleware/assert.js and 3 other locations - About 1 hr to fix
                src/middleware/assert.js on lines 43..49
                src/middleware/assert.js on lines 51..57
                src/middleware/assert.js on lines 59..65

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

                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

                Assert.category = helpers.try(async (req, res, next) => {
                    if (!await categories.exists(req.params.cid)) {
                        return controllerHelpers.formatApiResponse(404, res, new Error('[[error:no-category]]'));
                    }
                
                
                Severity: Major
                Found in src/middleware/assert.js and 3 other locations - About 1 hr to fix
                src/middleware/assert.js on lines 26..32
                src/middleware/assert.js on lines 51..57
                src/middleware/assert.js on lines 59..65

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

                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 15 (exceeds 10 allowed). Consider refactoring.
                Open

                module.exports = function (Topics) {
                    const terms = {
                        day: 86400000,
                        week: 604800000,
                        month: 2592000000,
                Severity: Minor
                Found in src/topics/recent.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 exports has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
                Open

                module.exports = function (SocketPosts) {
                    SocketPosts.loadPostTools = async function (socket, data) {
                        if (!data || !data.pid) {
                            throw new Error('[[error:invalid-data]]');
                        }
                Severity: Minor
                Found in src/socket.io/posts/tools.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 get has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
                Open

                Thumbs.get = async function (tids) {
                    // Allow singular or plural usage
                    let singular = false;
                    if (!Array.isArray(tids)) {
                        tids = [tids];
                Severity: Minor
                Found in src/topics/thumbs.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 getBundleMetadata has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
                Open

                async function getBundleMetadata(target) {
                    const paths = [
                        path.join(__dirname, '../../node_modules'),
                        path.join(__dirname, '../../public/scss'),
                        path.join(__dirname, '../../public/fontawesome/scss'),
                Severity: Minor
                Found in src/meta/css.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 exports has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
                Open

                module.exports = function (Groups) {
                    Groups.getGroupsFields = async function (groupNames, fields) {
                        if (!Array.isArray(groupNames) || !groupNames.length) {
                            return [];
                        }
                Severity: Minor
                Found in src/groups/data.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

                Severity
                Category
                Status
                Source
                Language