Chatie/wechaty

View on GitHub

Showing 83 of 83 total issues

File wechaty.ts has 585 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 *   Wechaty - https://github.com/chatie/wechaty
 *
 *   @copyright 2016-2018 Huan LI <zixia@zixia.net>
 *
Severity: Major
Found in src/wechaty.ts - About 1 day to fix

    File room.ts has 465 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /**
     *   Wechaty - https://github.com/chatie/wechaty
     *
     *   @copyright 2016-2018 Huan LI <zixia@zixia.net>
     *
    Severity: Minor
    Found in src/user/room.ts - About 7 hrs to fix

      File message.ts has 428 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      /**
       *   Wechaty - https://github.com/chatie/wechaty
       *
       *   @copyright 2016-2018 Huan LI <zixia@zixia.net>
       *
      Severity: Minor
      Found in src/user/message.ts - About 6 hrs to fix

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

            try {
              const roomIdList = await this.puppet.roomSearch(query)
              const roomList = roomIdList.map(id => this.load(id))
              await Promise.all(
                roomList.map(
        Severity: Major
        Found in src/user/room.ts and 1 other location - About 5 hrs to fix
        src/user/message.ts on lines 132..152

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

        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

            try {
              const MessageIdList = await this.puppet.messageSearch(puppetQuery)
              const messageList = MessageIdList.map(id => this.load(id))
              await Promise.all(
                messageList.map(
        Severity: Major
        Found in src/user/message.ts and 1 other location - About 5 hrs to fix
        src/user/room.ts on lines 140..160

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

        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

          public async toMiniProgram (): Promise<MiniProgram> {
            log.verbose('Message', 'toMiniProgram()')
        
            if (!this.payload) {
              throw new Error('no payload')
        Severity: Major
        Found in src/user/message.ts and 1 other location - About 5 hrs to fix
        src/user/message.ts on lines 914..932

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

        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

          public async toUrlLink (): Promise<UrlLink> {
            log.verbose('Message', 'toUrlLink()')
        
            if (!this.payload) {
              throw new Error('no payload')
        Severity: Major
        Found in src/user/message.ts and 1 other location - About 5 hrs to fix
        src/user/message.ts on lines 934..952

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

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

          protected initPuppetEventBridge (puppet: Puppet) {
            log.verbose('Wechaty', 'initPuppetEventBridge(%s)', puppet)
        
            const eventNameList: PuppetEventName[] = Object.keys(PUPPET_EVENT_DICT) as PuppetEventName[]
            for (const eventName of eventNameList) {
        Severity: Major
        Found in src/wechaty.ts - About 4 hrs to fix

          File io.ts has 344 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          /**
           *   Wechaty - https://github.com/chatie/wechaty
           *
           *   @copyright 2016-2018 Huan LI <zixia@zixia.net>
           *
          Severity: Minor
          Found in src/io.ts - About 4 hrs to fix

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

                for (n = 0; n < contactList.length; n++) {
                  const contact = contactList[n]
                  // use puppet.contactValidate() to confirm double confirm that this contactId is valid.
                  // https://github.com/lijiarui/wechaty-puppet-padchat/issues/64
                  // https://github.com/Chatie/wechaty/issues/1345
            Severity: Major
            Found in src/user/contact.ts and 1 other location - About 4 hrs to fix
            src/user/room.ts on lines 199..217

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

            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

                for (n = 0; n < roomList.length; n++) {
                  const room = roomList[n]
                  // use puppet.roomValidate() to confirm double confirm that this roomId is valid.
                  // https://github.com/lijiarui/wechaty-puppet-padchat/issues/64
                  // https://github.com/Chatie/wechaty/issues/1345
            Severity: Major
            Found in src/user/room.ts and 1 other location - About 4 hrs to fix
            src/user/contact.ts on lines 165..183

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

            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

            File contact.ts has 329 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            /**
             *   Wechaty - https://github.com/chatie/wechaty
             *
             *   @copyright 2016-2018 Huan LI <zixia@zixia.net>
             *
            Severity: Minor
            Found in src/user/contact.ts - About 3 hrs to fix

              Function say has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
              Open

                public async say (
                  textOrContactOrFileOrUrlOrMini : string | Contact | FileBox | UrlLink | MiniProgram,
                ): Promise<void> {
                  log.verbose('Message', 'say(%s)', textOrContactOrFileOrUrlOrMini)
              
              
              Severity: Minor
              Found in src/user/message.ts - About 3 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

              Room has 29 functions (exceeds 20 allowed). Consider refactoring.
              Open

              export class Room extends Accessory implements Sayable {
              
                protected static pool: Map<string, Room>
              
                /**
              Severity: Minor
              Found in src/user/room.ts - About 3 hrs to fix

                Message has 28 functions (exceeds 20 allowed). Consider refactoring.
                Open

                export class Message extends Accessory implements Sayable {
                
                  /**
                   *
                   * Static Properties
                Severity: Minor
                Found in src/user/message.ts - About 3 hrs to fix

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

                  export class Contact extends Accessory implements Sayable {
                  
                    // tslint:disable-next-line:variable-name
                    public static Type   = ContactType
                    // tslint:disable-next-line:variable-name
                  Severity: Minor
                  Found in src/user/contact.ts - About 3 hrs to fix

                    Wechaty has 26 functions (exceeds 20 allowed). Consider refactoring.
                    Open

                    export class Wechaty extends Accessory implements Sayable {
                    
                      public static readonly VERSION = VERSION
                    
                      public  readonly state      : StateSwitch
                    Severity: Minor
                    Found in src/wechaty.ts - About 3 hrs to fix

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

                        public room (): null | Room {
                          if (!this.payload) {
                            throw new Error('no payload')
                          }
                          const roomId = this.payload.roomId
                      Severity: Major
                      Found in src/user/message.ts and 1 other location - About 2 hrs to fix
                      src/user/message.ts on lines 306..318

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

                      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

                        public to (): null | Contact {
                          if (!this.payload) {
                            throw new Error('no payload')
                          }
                      
                      
                      Severity: Major
                      Found in src/user/message.ts and 1 other location - About 2 hrs to fix
                      src/user/message.ts on lines 341..352

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

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

                        private async wsOnMessage (data: WebSocket.Data) {
                          log.silly('Io', 'initWebSocket() ws.on(message): %s', data)
                          // flags.binary will be set if a binary data is received.
                          // flags.masked will be set if the data was masked.
                      
                      
                      Severity: Major
                      Found in src/io.ts - About 2 hrs to fix
                        Severity
                        Category
                        Status
                        Source
                        Language