Chatie/wechaty

View on GitHub

Showing 64 of 64 total issues

File wechaty.ts has 582 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 message.ts has 405 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 5 hrs to fix

      Function initPuppetEventBridge has 116 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 346 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

          File contact.ts has 322 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

            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

              Message has 27 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

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

                export class Wechaty extends Accessory implements Sayable {
                
                  public 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 303..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 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 338..349

                  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 say has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                  Open

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

                    Function start has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      public async start (): Promise<void> {
                        log.info('Wechaty', '<%s> start() v%s is starting...' ,
                                            this.options.puppet || config.systemPuppetName(),
                                            this.version(),
                                )
                    Severity: Major
                    Found in src/wechaty.ts - About 2 hrs to fix

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

                        constructor (
                          public id: string,
                        ) {
                          super()
                          log.verbose('RoomInvitation', 'constructor(id=%s)', id)
                      Severity: Major
                      Found in src/user/room-invitation.ts and 1 other location - About 2 hrs to fix
                      src/user/friendship.ts on lines 164..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 77.

                      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

                        constructor (
                          public id: string,
                        ) {
                          super()
                          log.verbose('Friendship', 'constructor(id=%s)', id)
                      Severity: Major
                      Found in src/user/friendship.ts and 1 other location - About 2 hrs to fix
                      src/user/room-invitation.ts on lines 57..73

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

                      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 a Cognitive Complexity of 16 (exceeds 5 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: Minor
                      Found in src/io.ts - 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 mention has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        public async mention (): Promise<Contact[]> {
                          log.verbose('Message', 'mention()')
                      
                          const room = this.room()
                          if (this.type() !== MessageType.Text || !room) {
                      Severity: Minor
                      Found in src/user/message.ts - About 1 hr to fix

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

                        function outputContributorMd () {
                          const MIN_MAINTAINER_COMMIT_NUM = 2
                          function isMaintainer (committer: string): boolean {
                            return contributeMap[committer].length >= MIN_MAINTAINER_COMMIT_NUM
                          }
                        Severity: Minor
                        Found in scripts/sort-contributiveness.ts - About 1 hr to fix

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

                            private updateChunk (chunk: any): string {
                              const buffer  = this.lineBuf + chunk.toString()
                              this.lineBuf    = ''
                          
                              if (!buffer) {
                          Severity: Minor
                          Found in scripts/update-license.ts - About 1 hr to fix

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

                              public static set wechaty (wechaty: Wechaty) {
                                log.silly('Accessory', '<%s> static set wechaty = "%s"',
                                                              this.name,
                                                              wechaty,
                                          )
                            Severity: Major
                            Found in src/accessory.ts and 1 other location - About 1 hr to fix
                            src/accessory.ts on lines 36..46

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

                            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

                            Severity
                            Category
                            Status
                            Source
                            Language