grigori-gru/matrix-cli

View on GitHub
src/lib/matrix-service.js

Summary

Maintainability
F
3 days
Test Coverage

File matrix-service.js has 389 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const fileSystem = require('fs').promises;
const matrixSdk = require('matrix-js-sdk');
const url = require('url');
const { getParsedRooms, isEnglish, timing, getOutdatedRooms } = require('./utils');
const Listr = require('listr');
Severity: Minor
Found in src/lib/matrix-service.js - About 5 hrs to fix

    exports has 25 functions (exceeds 20 allowed). Consider refactoring.
    Open

    module.exports = class {
        /**
         * @param {object} sdk sdk client
         */
        constructor({
    Severity: Minor
    Found in src/lib/matrix-service.js - About 2 hrs to fix

      Function leaveRooms has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async leaveRooms(allRooms, options = {}) {
              const client = this.client || (await this.getClient());
              const leavedRooms = [];
              const errLeavedRooms = [];
      
      
      Severity: Minor
      Found in src/lib/matrix-service.js - About 1 hr to fix

        Function inviteUserToRooms has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async inviteUserToRooms(allRooms, userId) {
                const client = this.client || (await this.getClient());
                const invitedRooms = [];
                const errInvitedRooms = [];
        
        
        Severity: Minor
        Found in src/lib/matrix-service.js - About 1 hr to fix

          Function iter has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  const iter = async (rooms = [], errors = []) => {
                      if (!rooms.length) {
                          return { errors, leavedRooms, errLeavedRooms };
                      }
          
          
          Severity: Minor
          Found in src/lib/matrix-service.js - About 1 hr to fix

            Function leaveRooms has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                async leaveRooms(allRooms, options = {}) {
                    const client = this.client || (await this.getClient());
                    const leavedRooms = [];
                    const errLeavedRooms = [];
            
            
            Severity: Minor
            Found in src/lib/matrix-service.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 setPower has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                async setPower(rooms, matrixUserId, level) {
                    const poweredRooms = [];
                    const errPoweredRooms = [];
            
                    const iter = async (rooms = [], errors = []) => {
            Severity: Minor
            Found in src/lib/matrix-service.js - About 1 hr to fix

              Function join has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  async join(allRooms) {
                      const client = this.client || (await this.getClient());
                      const joinedRooms = [];
                      const errJoinedRooms = [];
              
              
              Severity: Minor
              Found in src/lib/matrix-service.js - About 1 hr to fix

                Function iter has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        const iter = async (rooms = [], errors = []) => {
                            if (!rooms.length) {
                                return { errors, invitedRooms, errInvitedRooms };
                            }
                
                
                Severity: Minor
                Found in src/lib/matrix-service.js - About 1 hr to fix

                  Function getClient has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      async getClient() {
                          const tasks = new Listr([
                              {
                                  title: spinLoginText,
                                  task: async ctx => {
                  Severity: Minor
                  Found in src/lib/matrix-service.js - About 1 hr to fix

                    Function iter has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            const iter = async (rooms = [], errors = []) => {
                                if (!rooms.length) {
                                    return { errors, poweredRooms, errPoweredRooms };
                                }
                    
                    
                    Severity: Minor
                    Found in src/lib/matrix-service.js - About 1 hr to fix

                      Function iter has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                              const iter = async (rooms = [], errors = []) => {
                                  if (!rooms.length) {
                                      return { errors, joinedRooms, errJoinedRooms };
                                  }
                      
                      
                      Severity: Minor
                      Found in src/lib/matrix-service.js - About 1 hr to fix

                        Function setPower has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            async setPower(rooms, matrixUserId, level) {
                                const poweredRooms = [];
                                const errPoweredRooms = [];
                        
                                const iter = async (rooms = [], errors = []) => {
                        Severity: Minor
                        Found in src/lib/matrix-service.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 inviteUserToRooms has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            async inviteUserToRooms(allRooms, userId) {
                                const client = this.client || (await this.getClient());
                                const invitedRooms = [];
                                const errInvitedRooms = [];
                        
                        
                        Severity: Minor
                        Found in src/lib/matrix-service.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 join has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            async join(allRooms) {
                                const client = this.client || (await this.getClient());
                                const joinedRooms = [];
                                const errJoinedRooms = [];
                        
                        
                        Severity: Minor
                        Found in src/lib/matrix-service.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

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

                                    this.logger.log(
                                        `Left: ${chalk.yellow(rooms.length)} Complited: ${chalk.green(leavedRooms.length)} Error: ${chalk.red(
                                            errLeavedRooms.length,
                                        )}`,
                                    );
                        Severity: Major
                        Found in src/lib/matrix-service.js and 1 other location - About 1 hr to fix
                        src/lib/matrix-service.js on lines 399..403

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

                        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

                                    this.logger.log(
                                        `Left: ${chalk.yellow(rooms.length)} Complited: ${chalk.green(invitedRooms.length)} Error: ${chalk.red(
                                            errInvitedRooms.length,
                                        )}`,
                                    );
                        Severity: Major
                        Found in src/lib/matrix-service.js and 1 other location - About 1 hr to fix
                        src/lib/matrix-service.js on lines 311..315

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

                        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

                                const manyMembersNoMessages = parsedRooms.filter(room => {
                                    return room.members.length > 1 && room.messages.length === 0;
                                });
                        Severity: Minor
                        Found in src/lib/matrix-service.js and 1 other location - About 50 mins to fix
                        src/lib/matrix-service.js on lines 174..176

                        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

                                const singleRoomsNoMessages = parsedRooms.filter(room => {
                                    return room.members.length === 1 && room.messages.length === 0;
                                });
                        Severity: Minor
                        Found in src/lib/matrix-service.js and 1 other location - About 50 mins to fix
                        src/lib/matrix-service.js on lines 182..184

                        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

                                const manyMembersManyMessages = parsedRooms.filter(room => {
                                    return room.members.length > 1 && room.messages.length;
                                });
                        Severity: Minor
                        Found in src/lib/matrix-service.js and 1 other location - About 35 mins to fix
                        src/lib/matrix-service.js on lines 178..180

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

                        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

                                const singleRoomsManyMessages = parsedRooms.filter(room => {
                                    return room.members.length === 1 && room.messages.length;
                                });
                        Severity: Minor
                        Found in src/lib/matrix-service.js and 1 other location - About 35 mins to fix
                        src/lib/matrix-service.js on lines 186..188

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

                        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