RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/slackbridge/server/RocketAdapter.js

Summary

Maintainability
F
1 wk
Test Coverage

Function addUser has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
Open

    async addUser(slackUserID) {
        rocketLogger.debug('Adding Rocket.Chat user from Slack', slackUserID);
        let addedUser;
        for await (const slack of this.slackAdapters) {
            if (addedUser) {
Severity: Minor
Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 1 day 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

File RocketAdapter.js has 458 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import util from 'util';

import { Messages, Rooms, Users } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';
import { Accounts } from 'meteor/accounts-base';
Severity: Minor
Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 7 hrs to fix

    Function addChannel has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
    Open

        async addChannel(slackChannelID, hasRetried = false) {
            rocketLogger.debug('Adding Rocket.Chat channel from Slack', slackChannelID);
            let addedRoom;
    
            for await (const slack of this.slackAdapters) {
    Severity: Minor
    Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 6 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 addUser has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        async addUser(slackUserID) {
            rocketLogger.debug('Adding Rocket.Chat user from Slack', slackUserID);
            let addedUser;
            for await (const slack of this.slackAdapters) {
                if (addedUser) {
    Severity: Major
    Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 3 hrs to fix

      RocketAdapter has 27 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export default class RocketAdapter {
          constructor(slackBridge) {
              rocketLogger.debug('constructor');
              this.slackBridge = slackBridge;
              this.util = util;
      Severity: Minor
      Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 3 hrs to fix

        Function createAndSaveMessage has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            async createAndSaveMessage(rocketChannel, rocketUser, slackMessage, rocketMsgDataDefaults, isImporting, slack) {
                if (slackMessage.type === 'message') {
                    let rocketMsgObj = {};
                    if (!_.isEmpty(slackMessage.subtype)) {
                        rocketMsgObj = await slack.processSubtypedMessage(rocketChannel, rocketUser, slackMessage, isImporting);
        Severity: Minor
        Found in apps/meteor/app/slackbridge/server/RocketAdapter.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 addChannel has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async addChannel(slackChannelID, hasRetried = false) {
                rocketLogger.debug('Adding Rocket.Chat channel from Slack', slackChannelID);
                let addedRoom;
        
                for await (const slack of this.slackAdapters) {
        Severity: Major
        Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 2 hrs to fix

          Function createAndSaveMessage has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async createAndSaveMessage(rocketChannel, rocketUser, slackMessage, rocketMsgDataDefaults, isImporting, slack) {
                  if (slackMessage.type === 'message') {
                      let rocketMsgObj = {};
                      if (!_.isEmpty(slackMessage.subtype)) {
                          rocketMsgObj = await slack.processSubtypedMessage(rocketChannel, rocketUser, slackMessage, isImporting);
          Severity: Major
          Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 2 hrs to fix

            Function onSetReaction has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                async onSetReaction(rocketMsgID, reaction) {
                    try {
                        if (!this.slackBridge.isReactionsEnabled) {
                            return;
                        }
            Severity: Minor
            Found in apps/meteor/app/slackbridge/server/RocketAdapter.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 onUnSetReaction has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                async onUnSetReaction(rocketMsgID, reaction) {
                    try {
                        if (!this.slackBridge.isReactionsEnabled) {
                            return;
                        }
            Severity: Minor
            Found in apps/meteor/app/slackbridge/server/RocketAdapter.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 11 (exceeds 5 allowed). Consider refactoring.
            Open

                async onMessage(rocketMessage) {
                    for await (const slack of this.slackAdapters) {
                        try {
                            if (!slack.getSlackChannel(rocketMessage.rid)) {
                                // This is on a channel that the rocket bot is not subscribed
            Severity: Minor
            Found in apps/meteor/app/slackbridge/server/RocketAdapter.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 convertSlackMsgTxtToRocketTxtFormat has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                async convertSlackMsgTxtToRocketTxtFormat(slackMsgTxt) {
                    const regex = /(?:<@)([a-zA-Z0-9]+)(?:\|.+)?(?:>)/g;
                    if (!_.isEmpty(slackMsgTxt)) {
                        slackMsgTxt = slackMsgTxt.replace(/<!everyone>/g, '@all');
                        slackMsgTxt = slackMsgTxt.replace(/<!channel>/g, '@all');
            Severity: Minor
            Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                      if (rocketUserData.profile.image_original) {
                                          url = rocketUserData.profile.image_original;
                                      } else if (rocketUserData.profile.image_512) {
                                          url = rocketUserData.profile.image_512;
                                      }
              Severity: Major
              Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 45 mins to fix

                Function getRocketUsers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    async getRocketUsers(members, slackChannel) {
                        const rocketUsers = [];
                        for await (const member of members) {
                            if (member !== slackChannel.creator) {
                                const rocketUser = (await this.findUser(member)) || (await this.addUser(member));
                Severity: Minor
                Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 35 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 processFileShare has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    async processFileShare(rocketMessage, slack) {
                        if (!settings.get('SlackBridge_FileUpload_Enabled')) {
                            return;
                        }
                
                
                Severity: Minor
                Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 35 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

                Avoid too many return statements within this function.
                Open

                        return addedRoom;
                Severity: Major
                Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return rocketMessage;
                  Severity: Major
                  Found in apps/meteor/app/slackbridge/server/RocketAdapter.js - About 30 mins to fix

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

                        async onUnSetReaction(rocketMsgID, reaction) {
                            try {
                                if (!this.slackBridge.isReactionsEnabled) {
                                    return;
                                }
                    Severity: Major
                    Found in apps/meteor/app/slackbridge/server/RocketAdapter.js and 1 other location - About 1 day to fix
                    apps/meteor/app/slackbridge/server/RocketAdapter.js on lines 75..102

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

                    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 2 locations. Consider refactoring.
                    Open

                        async onSetReaction(rocketMsgID, reaction) {
                            try {
                                if (!this.slackBridge.isReactionsEnabled) {
                                    return;
                                }
                    Severity: Major
                    Found in apps/meteor/app/slackbridge/server/RocketAdapter.js and 1 other location - About 1 day to fix
                    apps/meteor/app/slackbridge/server/RocketAdapter.js on lines 104..132

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

                    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 2 locations. Consider refactoring.
                    Open

                        async getChannel(slackMessage) {
                            return slackMessage.channel ? (await this.findChannel(slackMessage.channel)) || this.addChannel(slackMessage.channel) : null;
                        }
                    Severity: Minor
                    Found in apps/meteor/app/slackbridge/server/RocketAdapter.js and 1 other location - About 50 mins to fix
                    apps/meteor/app/slackbridge/server/RocketAdapter.js on lines 261..263

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

                    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 2 locations. Consider refactoring.
                    Open

                        async getRocketUserCreator(slackChannel) {
                            return slackChannel.creator ? (await this.findUser(slackChannel.creator)) || this.addUser(slackChannel.creator) : null;
                        }
                    Severity: Minor
                    Found in apps/meteor/app/slackbridge/server/RocketAdapter.js and 1 other location - About 50 mins to fix
                    apps/meteor/app/slackbridge/server/RocketAdapter.js on lines 232..234

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

                    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 2 locations. Consider refactoring.
                    Open

                                    if (!this.userTags[slackUserID]) {
                                        this.userTags[slackUserID] = {
                                            slack: `<@${slackUserID}>`,
                                            rocket: `@${rocketUserData.name}`,
                                        };
                    Severity: Minor
                    Found in apps/meteor/app/slackbridge/server/RocketAdapter.js and 1 other location - About 50 mins to fix
                    apps/meteor/app/slackbridge/server/RocketAdapter.js on lines 339..344

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

                    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 2 locations. Consider refactoring.
                    Open

                            if (rocketUser && !this.userTags[slackUserID]) {
                                this.userTags[slackUserID] = {
                                    slack: `<@${slackUserID}>`,
                                    rocket: `@${rocketUser.username}`,
                                };
                    Severity: Minor
                    Found in apps/meteor/app/slackbridge/server/RocketAdapter.js and 1 other location - About 50 mins to fix
                    apps/meteor/app/slackbridge/server/RocketAdapter.js on lines 427..432

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

                    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

                    There are no issues that match your filters.

                    Category
                    Status