NodeBB/NodeBB

View on GitHub

Showing 536 of 552 total issues

Function email has 95 lines of code (exceeds 75 allowed). Consider refactoring.
Open

Interstitials.email = async (data) => {
    if (!data.userData) {
        throw new Error('[[error:invalid-data]]');
    }
    if (!data.userData.updateEmail) {
Severity: Major
Found in src/user/interstitials.js - About 1 hr to fix

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

            if (group['cover:thumb:url']) {
                group['cover:thumb:url'] = group['cover:thumb:url'].startsWith('http') ? group['cover:thumb:url'] : (nconf.get('relative_path') + group['cover:thumb:url']);
            } else {
                group['cover:thumb:url'] = require('../coverPhoto').getDefaultGroupCover(group.name);
            }
    Severity: Major
    Found in src/groups/data.js and 2 other locations - About 1 hr to fix
    src/controllers/accounts/helpers.js on lines 120..124
    src/groups/data.js on lines 84..88

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

    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 (userData['cover:url']) {
            userData['cover:url'] = userData['cover:url'].startsWith('http') ? userData['cover:url'] : (nconf.get('relative_path') + userData['cover:url']);
        } else {
            userData['cover:url'] = require('../../coverPhoto').getDefaultProfileCover(userData.uid);
        }
    Severity: Major
    Found in src/controllers/accounts/helpers.js and 2 other locations - About 1 hr to fix
    src/groups/data.js on lines 84..88
    src/groups/data.js on lines 90..94

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

    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 (group['cover:url']) {
                group['cover:url'] = group['cover:url'].startsWith('http') ? group['cover:url'] : (nconf.get('relative_path') + group['cover:url']);
            } else {
                group['cover:url'] = require('../coverPhoto').getDefaultGroupCover(group.name);
            }
    Severity: Major
    Found in src/groups/data.js and 2 other locations - About 1 hr to fix
    src/controllers/accounts/helpers.js on lines 120..124
    src/groups/data.js on lines 90..94

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

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

        userFilter.init = function (el, options) {
            if (!el || !el.length) {
                return;
            }
            options = options || {};
    Severity: Major
    Found in public/src/modules/userFilter.js - About 1 hr to fix

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

      module.exports = function (module) {
          const helpers = require('./helpers');
      
          module.flushdb = async function () {
              await module.client.send_command('flushdb', []);
      Severity: Major
      Found in src/database/redis/main.js - About 1 hr to fix

        Function checkPrivileges has a Cognitive Complexity of 19 (exceeds 10 allowed). Consider refactoring.
        Open

        middleware.checkPrivileges = helpers.try(async (req, res, next) => {
            // Kick out guests, obviously
            if (req.uid <= 0) {
                return controllers.helpers.notAllowed(req, res);
            }
        Severity: Minor
        Found in src/middleware/admin.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 registerComplete has a Cognitive Complexity of 19 (exceeds 10 allowed). Consider refactoring.
        Open

        authenticationController.registerComplete = async function (req, res) {
            try {
                // For the interstitials that respond, execute the callback with the form body
                const data = await user.interstitials.get(req, req.session.registration);
                const callbacks = data.interstitials.reduce((memo, cur) => {
        Severity: Minor
        Found in src/controllers/authentication.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 19 (exceeds 10 allowed). Consider refactoring.
        Open

        module.exports = function (opts) {
            const { LRUCache } = require('lru-cache');
            const pubsub = require('../pubsub');
        
            // lru-cache@7 deprecations
        Severity: Minor
        Found in src/cache/lru.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 19 (exceeds 10 allowed). Consider refactoring.
        Open

        module.exports = function (Posts) {
            Posts.create = async function (data) {
                // This is an internal method, consider using Topics.reply instead
                const { uid } = data;
                const { tid } = data;
        Severity: Minor
        Found in src/posts/create.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 19 (exceeds 10 allowed). Consider refactoring.
        Open

        module.exports = function (opts) {
            const TTLCache = require('@isaacs/ttlcache');
            const pubsub = require('../pubsub');
        
            const ttlCache = new TTLCache(opts);
        Severity: Minor
        Found in src/cache/ttl.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 19 (exceeds 10 allowed). Consider refactoring.
        Open

        module.exports = function (module) {
            const helpers = require('../helpers');
            module.sortedSetIntersectCard = async function (keys) {
                if (!Array.isArray(keys) || !keys.length) {
                    return 0;
        Severity: Minor
        Found in src/database/redis/sorted/intersect.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 createAdmin has a Cognitive Complexity of 19 (exceeds 10 allowed). Consider refactoring.
        Open

        async function createAdmin() {
            const User = require('./user');
            const Groups = require('./groups');
            let password;
        
        
        Severity: Minor
        Found in src/install.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 loadClientHeaderFooterData has 92 lines of code (exceeds 75 allowed). Consider refactoring.
        Open

            async function loadClientHeaderFooterData(req, res, options) {
                const registrationType = meta.config.registrationType || 'normal';
                res.locals.config = res.locals.config || {};
                const templateValues = {
                    title: meta.config.title || '',
        Severity: Major
        Found in src/middleware/render.js - About 1 hr to fix

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

          module.exports = function (Groups) {
              Groups.leave = async function (groupNames, uid) {
                  if (Array.isArray(groupNames) && !groupNames.length) {
                      return;
                  }
          Severity: Major
          Found in src/groups/leave.js - About 1 hr to fix

            Function loadRoom has 92 lines of code (exceeds 75 allowed). Consider refactoring.
            Open

                Messaging.loadRoom = async (uid, data) => {
                    const { roomId } = data;
                    const [room, inRoom, canChat, isAdmin, isGlobalMod] = await Promise.all([
                        Messaging.getRoomData(roomId),
                        Messaging.isUserInRoom(uid, roomId),
            Severity: Major
            Found in src/messaging/rooms.js - About 1 hr to fix

              Function init has 91 lines of code (exceeds 75 allowed). Consider refactoring.
              Open

                  categorySearch.init = function (el, options) {
                      let categoriesList = null;
                      options = options || {};
                      options.privilege = options.privilege || 'topics:read';
                      options.states = options.states || ['watching', 'tracking', 'notwatching', 'ignoring'];
              Severity: Major
              Found in public/src/modules/categorySearch.js - About 1 hr to fix

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

                module.exports = function (Groups) {
                    Groups.getPending = async function (groupName) {
                        return await Groups.getUsersFromSet(`group:${groupName}:pending`, ['username', 'userslug', 'picture']);
                    };
                
                
                Severity: Major
                Found in src/groups/invite.js - About 1 hr to fix

                  Function set has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
                  Open

                  Themes.set = async (data) => {
                      switch (data.type) {
                          case 'local': {
                              const current = await Meta.configs.get('theme:id');
                              const score = await db.sortedSetScore('plugins:active', current);
                  Severity: Minor
                  Found in src/meta/themes.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 onMessage has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
                  Open

                  async function onMessage(socket, payload) {
                      const { event, params, callback } = payload;
                      try {
                          if (!event) {
                              return winston.warn('[socket.io] Empty method name');
                  Severity: Minor
                  Found in src/socket.io/index.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