wechaty/go-wechaty

View on GitHub

Showing 544 of 544 total issues

Method Wechaty.initPuppetEventBridge has a Cognitive Complexity of 85 (exceeds 14 allowed). Consider refactoring.
Open

func (w *Wechaty) initPuppetEventBridge() {
    // TODO temporary
    for _, name := range schemas.GetEventNames() {
        name := name
        switch name {
Severity: Minor
Found in wechaty/wechaty.go - 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

Method Wechaty.initPuppetEventBridge has 180 lines of code (exceeds 45 allowed). Consider refactoring.
Open

func (w *Wechaty) initPuppetEventBridge() {
    // TODO temporary
    for _, name := range schemas.GetEventNames() {
        name := name
        switch name {
Severity: Major
Found in wechaty/wechaty.go - About 6 hrs to fix

    PuppetService has 66 methods (exceeds 60 allowed). Consider refactoring.
    Open

    type PuppetService struct {
        *wechatyPuppet.Puppet
        grpcConn    *grpc.ClientConn
        grpcClient  pbwechaty.PuppetClient
        eventStream pbwechaty.Puppet_EventClient
    Severity: Major
    Found in wechaty-puppet-service/puppet_service.go - About 3 hrs to fix

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

      // Code generated by "stringer -type=ImageType"; DO NOT EDIT.
      
      package schemas
      
      import "strconv"
      Severity: Major
      Found in wechaty-puppet/schemas/imagetype_string.go and 1 other location - About 2 hrs to fix
      wechaty-puppet/schemas/friendshiptype_string.go on lines 1..26

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

      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

      // Code generated by "stringer -type=FriendshipType"; DO NOT EDIT.
      
      package schemas
      
      import "strconv"
      Severity: Major
      Found in wechaty-puppet/schemas/friendshiptype_string.go and 1 other location - About 2 hrs to fix
      wechaty-puppet/schemas/imagetype_string.go on lines 1..26

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

      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

      // Code generated by "stringer -type=ContactType"; DO NOT EDIT.
      
      package schemas
      
      import "strconv"
      Severity: Major
      Found in wechaty-puppet/schemas/contacttype_string.go and 1 other location - About 2 hrs to fix
      wechaty-puppet/schemas/contactgender_string.go on lines 1..25

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

      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

      // Code generated by "stringer -type=ContactGender"; DO NOT EDIT.
      
      package schemas
      
      import "strconv"
      Severity: Major
      Found in wechaty-puppet/schemas/contactgender_string.go and 1 other location - About 2 hrs to fix
      wechaty-puppet/schemas/contacttype_string.go on lines 1..25

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

      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 puppet_service.go has 1010 lines of code (exceeds 1000 allowed). Consider refactoring.
      Open

      package puppetservice
      
      import (
          "context"
          "crypto/x509"
      Severity: Major
      Found in wechaty-puppet-service/puppet_service.go - About 2 hrs to fix

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

        func TestFromQRCode(t *testing.T) {
            t.Run("FromQRCode no QR code", func(t *testing.T) {
                if err := FromQRCode("").Error(); !errors.Is(err, ErrNoQRCode) {
                    t.Error(err)
                }
        Severity: Major
        Found in wechaty-puppet/filebox/file_box_test.go and 2 other locations - About 2 hrs to fix
        wechaty-puppet/filebox/file_box_test.go on lines 28..40
        wechaty-puppet/filebox/file_box_test.go on lines 93..105

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

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

        func TestFromBase64(t *testing.T) {
            t.Run("FromBase64 no base64 data", func(t *testing.T) {
                if err := FromBase64("").Error(); !errors.Is(err, ErrNoBase64Data) {
                    t.Error(err)
                }
        Severity: Major
        Found in wechaty-puppet/filebox/file_box_test.go and 2 other locations - About 2 hrs to fix
        wechaty-puppet/filebox/file_box_test.go on lines 79..91
        wechaty-puppet/filebox/file_box_test.go on lines 93..105

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

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

        func TestFromUuid(t *testing.T) {
            t.Run("FromUuid no uuid", func(t *testing.T) {
                if err := FromUuid("").Error(); !errors.Is(err, ErrNoUuid) {
                    t.Error(err)
                }
        Severity: Major
        Found in wechaty-puppet/filebox/file_box_test.go and 2 other locations - About 2 hrs to fix
        wechaty-puppet/filebox/file_box_test.go on lines 28..40
        wechaty-puppet/filebox/file_box_test.go on lines 79..91

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

        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

        // Code generated by "stringer -type=FileBoxType"; DO NOT EDIT.
        
        package file_box
        
        import "strconv"
        Severity: Major
        Found in wechaty-puppet/file-box/fileboxtype_string.go and 1 other location - About 2 hrs to fix
        wechaty-puppet/filebox/type_string.go on lines 1..23

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

        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

        // Code generated by "stringer -type=Type"; DO NOT EDIT.
        
        package filebox
        
        import "strconv"
        Severity: Major
        Found in wechaty-puppet/filebox/type_string.go and 1 other location - About 2 hrs to fix
        wechaty-puppet/file-box/fileboxtype_string.go on lines 1..23

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

        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

                FinderColumn struct {
                    Text   string `xml:",chardata"`
                    CardId struct {
                        Text string `xml:",chardata"`
                    } `xml:"cardId"`
        Severity: Major
        Found in wechaty-puppet/helper/fix_unknown_message.go and 1 other location - About 1 hr to fix
        wechaty-puppet/helper/fix_unknown_message.go on lines 94..120

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

        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

                Streamvideo struct {
                    Text           string `xml:",chardata"`
                    Streamvideourl struct {
                        Text string `xml:",chardata"`
                    } `xml:"streamvideourl"`
        Severity: Major
        Found in wechaty-puppet/helper/fix_unknown_message.go and 1 other location - About 1 hr to fix
        wechaty-puppet/helper/fix_unknown_message.go on lines 457..483

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

        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

        Method Message.MentionList has a Cognitive Complexity of 23 (exceeds 14 allowed). Consider refactoring.
        Open

        func (m *Message) MentionList() []_interface.IContact {
            room := m.Room()
            if m.Type() != schemas.MessageTypeText || room == nil {
                return nil
            }
        Severity: Minor
        Found in wechaty/user/message.go - 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

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

        func (p *Puppet) FriendshipPayload(friendshipID string) (*schemas.FriendshipPayload, error) {
            cachePayload, ok := p.cacheFriendshipPayload.Get(friendshipID)
            if ok {
                return cachePayload.(*schemas.FriendshipPayload), nil
            }
        Severity: Major
        Found in wechaty-puppet/puppet.go and 2 other locations - About 1 hr to fix
        wechaty-puppet/puppet.go on lines 334..345
        wechaty-puppet/puppet.go on lines 551..562

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

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

        func (p *Puppet) ContactPayload(contactID string) (*schemas.ContactPayload, error) {
            cachePayload, ok := p.cacheContactPayload.Get(contactID)
            if ok {
                return cachePayload.(*schemas.ContactPayload), nil
            }
        Severity: Major
        Found in wechaty-puppet/puppet.go and 2 other locations - About 1 hr to fix
        wechaty-puppet/puppet.go on lines 282..293
        wechaty-puppet/puppet.go on lines 551..562

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

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

        func (p *Puppet) RoomInvitationPayload(roomInvitationID string) (*schemas.RoomInvitationPayload, error) {
            cachePayload, ok := p.cacheRoomInvitationPayload.Get(roomInvitationID)
            if ok {
                return cachePayload.(*schemas.RoomInvitationPayload), nil
            }
        Severity: Major
        Found in wechaty-puppet/puppet.go and 2 other locations - About 1 hr to fix
        wechaty-puppet/puppet.go on lines 282..293
        wechaty-puppet/puppet.go on lines 334..345

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

        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

        func (p *PuppetService) RoomAvatar(roomID string) (*filebox.FileBox, error) {
            log.Tracef("PuppetService RoomAvatar(%s)\n", roomID)
            response, err := p.grpcClient.RoomAvatar(context.Background(), &pbwechatypuppet.RoomAvatarRequest{
                Id: roomID,
            })
        Severity: Major
        Found in wechaty-puppet-service/puppet_service.go and 1 other location - About 1 hr to fix
        wechaty-puppet-service/puppet_service.go on lines 439..448

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

        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