grigori-gru/matrix-cli

View on GitHub

Showing 43 of 43 total issues

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

    File actions.js has 285 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const { formatName } = require('./utils');
    const chalk = require('chalk');
    const myLogger = require('./logger');
    // eslint-disable-next-line
    const MatrixService = require('./matrix-service');
    Severity: Minor
    Found in src/lib/actions.js - About 2 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

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

                    expect(res).toEqual({
                        invitedUser: matrixService.getUserId(userToInvite),
                        invitedRooms: manyMembersNoMessages.map(({ roomId, name }) => ({ roomId, roomName: name })),
                        errInvitedRooms: [],
                        errors: [],
        Severity: Major
        Found in __tests__/actions.test.js and 1 other location - About 2 hrs to fix
        __tests__/actions.test.js on lines 126..131

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

        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

                    expect(res).toEqual({
                        invitedUser: matrixService.getUserId(userToInvite),
                        invitedRooms: allRooms.map(({ roomId, name }) => ({ roomId, roomName: name })),
                        errInvitedRooms: [],
                        errors: [],
        Severity: Major
        Found in __tests__/actions.test.js and 1 other location - About 2 hrs to fix
        __tests__/actions.test.js on lines 144..149

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

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

            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

            Function selectRooms has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const selectRooms = async rooms => {
                const preparedRooms = rooms.map(({ roomName }) => ({ name: roomName, message: roomName }));
                const prompt = new MultiSelect({
                    name: 'rooms',
                    message: chalk.blueBright('Select rooms'),
            Severity: Minor
            Found in src/lib/questions.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 selectRooms has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                const selectRooms = async rooms => {
                    const preparedRooms = rooms.map(({ roomName }) => ({ name: roomName, message: roomName }));
                    const prompt = new MultiSelect({
                        name: 'rooms',
                        message: chalk.blueBright('Select rooms'),
                Severity: Minor
                Found in src/lib/questions.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

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

                          return {
                              ...roomStub,
                              roomId: fake.random.uuid(),
                              name: fake.random.word(),
                              timeline: Array.from({ length: 10 }, getEvent(period, bot)),
                      Severity: Major
                      Found in __tests__/fixtures/fake-sdk.js and 1 other location - About 1 hr to fix
                      __tests__/fixtures/fake-sdk.js on lines 69..74

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

                      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

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

                          return {
                              ...roomStub,
                              roomId: fake.random.uuid(),
                              name: fake.random.word(),
                              timeline: Array.from({ length: 10 }, getEvent(period, bot)),
                      Severity: Major
                      Found in __tests__/fixtures/fake-sdk.js and 1 other location - About 1 hr to fix
                      __tests__/fixtures/fake-sdk.js on lines 55..60

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

                      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 setPower has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          async setPower() {
                              const userId = await this._selectUser();
                      
                              if (!userId) {
                                  this.logger.log(chalk.yellow('\nNo user is selected\n'));
                      Severity: Minor
                      Found in src/lib/actions.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
                          Severity
                          Category
                          Status
                          Source
                          Language