NodeBB/NodeBB

View on GitHub

Showing 481 of 497 total issues

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

module.exports = function (Categories) {
    Categories.update = async function (modified) {
        const cids = Object.keys(modified);
        await Promise.all(cids.map(cid => updateCategory(cid, modified[cid])));
        return cids;
Severity: Major
Found in src/categories/update.js - About 2 hrs to fix

    File dashboard.js has 515 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    'use strict';
    
    
    define('admin/dashboard', ['Chart', 'translator', 'benchpress'], function (Chart, translator, Benchpress) {
        var    Admin = {};
    Severity: Major
    Found in public/src/admin/dashboard.js - About 2 hrs to fix

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

      module.exports = function (User) {
          User.getLatestBanInfo = async function (uid) {
              // Simply retrieves the last record of the user's ban, even if they've been unbanned since then.
              const record = await db.getSortedSetRevRange(`uid:${uid}:bans:timestamp`, 0, 0);
              if (!record.length) {
      Severity: Major
      Found in src/user/info.js - About 2 hrs to fix

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

        module.exports = function (SocketTopics) {
            SocketTopics.isTagAllowed = async function (socket, data) {
                if (!data || !utils.isNumber(data.cid) || !data.tag) {
                    throw new Error('[[error:invalid-data]]');
                }
        Severity: Minor
        Found in src/socket.io/topics/tags.js - About 2 hrs 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 22 (exceeds 10 allowed). Consider refactoring.
        Open

        module.exports = function (module) {
            module.sortedSetUnionCard = async function (keys) {
                if (!Array.isArray(keys) || !keys.length) {
                    return 0;
                }
        Severity: Minor
        Found in src/database/mongo/sorted/union.js - About 2 hrs 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 22 (exceeds 10 allowed). Consider refactoring.
        Open

        module.exports = function (Posts) {
            Posts.bookmark = async function (pid, uid) {
                return await toggleBookmark('bookmark', pid, uid);
            };
        
        
        Severity: Minor
        Found in src/posts/bookmarks.js - About 2 hrs 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 22 (exceeds 10 allowed). Consider refactoring.
        Open

        module.exports = function (Messaging) {
            Messaging.editMessage = async (uid, mid, roomId, content) => {
                await Messaging.checkContent(content);
                const raw = await Messaging.getMessageField(mid, 'content');
                if (raw === content) {
        Severity: Minor
        Found in src/messaging/edit.js - About 2 hrs 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 22 (exceeds 10 allowed). Consider refactoring.
        Open

        module.exports = function (Messaging) {
            Messaging.newMessageCutoff = 1000 * 60 * 3;
        
            Messaging.getMessagesFields = async (mids, fields) => {
                if (!Array.isArray(mids) || !mids.length) {
        Severity: Minor
        Found in src/messaging/data.js - About 2 hrs 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 translate has 104 lines of code (exceeds 75 allowed). Consider refactoring.
        Open

                Translator.prototype.translate = function translate(str) {
                    // regex for valid text in namespace / key
                    var validText = 'a-zA-Z0-9\\-_.\\/';
                    var validTextRegex = new RegExp('[' + validText + ']');
                    var invalidTextRegex = new RegExp('[^' + validText + '\\]]');
        Severity: Major
        Found in public/src/modules/translator.js - About 2 hrs to fix

          Function prepareWidgets has 104 lines of code (exceeds 75 allowed). Consider refactoring.
          Open

              function prepareWidgets() {
                  $('[data-location="drafts"]').insertAfter($('[data-location="drafts"]').closest('.tab-content'));
          
                  $('#widgets .available-widgets .widget-panel').draggable({
                      helper: function (e) {
          Severity: Major
          Found in public/src/admin/extend/widgets.js - About 2 hrs to fix

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

            module.exports = function (User) {
                User.blocks = {
                    _cache: new LRU({
                        max: 100,
                        length: function () { return 1; },
            Severity: Minor
            Found in src/user/blocks.js - About 2 hrs 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 21 (exceeds 10 allowed). Consider refactoring.
            Open

            module.exports = function (User) {
                User.follow = async function (uid, followuid) {
                    await toggleFollow('follow', uid, followuid);
                };
            
            
            Severity: Minor
            Found in src/user/follow.js - About 2 hrs 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 102 lines of code (exceeds 75 allowed). Consider refactoring.
            Open

            module.exports = function (middleware) {
                middleware.processRender = function processRender(req, res, next) {
                    // res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687
                    const { render } = res;
            
            
            Severity: Major
            Found in src/middleware/render.js - About 2 hrs to fix

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

              module.exports = function (User) {
                  User.bans = {};
              
                  User.bans.ban = async function (uid, until, reason) {
                      // "until" (optional) is unix timestamp in milliseconds
              Severity: Major
              Found in src/user/bans.js - About 2 hrs to fix

                Function get has 101 lines of code (exceeds 75 allowed). Consider refactoring.
                Open

                categoryController.get = async function (req, res, next) {
                    const cid = req.params.category_id;
                
                    let currentPage = parseInt(req.query.page, 10) || 1;
                    let topicIndex = utils.isNumber(req.params.topic_index) ? parseInt(req.params.topic_index, 10) - 1 : 0;
                Severity: Major
                Found in src/controllers/category.js - About 2 hrs to fix

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

                  module.exports = function (Posts) {
                      Posts.uploads = {};
                  
                      const md5 = filename => crypto.createHash('md5').update(filename).digest('hex');
                      const pathPrefix = path.join(nconf.get('upload_path'), 'files');
                  Severity: Major
                  Found in src/posts/uploads.js - About 2 hrs to fix

                    File users.js has 501 lines of code (exceeds 500 allowed). Consider refactoring.
                    Open

                    'use strict';
                    
                    define('admin/manage/users', [
                        'translator', 'benchpress', 'autocomplete', 'api', 'slugify', 'bootbox', 'accounts/invite',
                    ], function (translator, Benchpress, autocomplete, api, slugify, bootbox, AccountInvite) {
                    Severity: Major
                    Found in public/src/admin/manage/users.js - About 2 hrs to fix

                      Function handleScrollNav has 100 lines of code (exceeds 75 allowed). Consider refactoring.
                      Open

                          function handleScrollNav() {
                              if (!thumb.length) {
                                  return;
                              }
                      
                      
                      Severity: Major
                      Found in public/src/modules/navigator.js - About 2 hrs to fix

                        Function createModal has 100 lines of code (exceeds 75 allowed). Consider refactoring.
                        Open

                            module.createModal = function (data, callback) {
                                callback = callback || function () {};
                                require(['scrollStop', 'forum/chats', 'forum/chats/messages'], function (scrollStop, Chats, ChatsMessages) {
                                    app.parseAndTranslate('chat', data, function (chatModal) {
                                        if (module.modalExists(data.roomId)) {
                        Severity: Major
                        Found in public/src/modules/chat.js - About 2 hrs to fix

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

                          module.exports = function (Messaging) {
                              Messaging.newMessageCutoff = 1000 * 60 * 3;
                          
                              Messaging.getMessagesFields = async (mids, fields) => {
                                  if (!Array.isArray(mids) || !mids.length) {
                          Severity: Major
                          Found in src/messaging/data.js - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language