waku-org/go-waku

View on GitHub
examples/chat2-reliable/chat.go

Summary

Maintainability
F
4 days
Test Coverage

Method Chat.parseInput has a Cognitive Complexity of 94 (exceeds 20 allowed). Consider refactoring.
Open

func (c *Chat) parseInput() {
    defer c.wg.Done()

    var disconnectedPeers []peer.ID

Severity: Minor
Found in examples/chat2-reliable/chat.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 Chat.parseInput has 106 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (c *Chat) parseInput() {
    defer c.wg.Done()

    var disconnectedPeers []peer.ID

Severity: Major
Found in examples/chat2-reliable/chat.go - About 3 hrs to fix

    Function NewChat has 66 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func NewChat(ctx context.Context, node *node.WakuNode, connNotifier <-chan node.PeerConnection, options Options) *Chat {
        chat := &Chat{
            ctx:              ctx,
            node:             node,
            options:          options,
    Severity: Minor
    Found in examples/chat2-reliable/chat.go - About 1 hr to fix

      Method Chat.parseInput has 11 return statements (exceeds 4 allowed).
      Open

      func (c *Chat) parseInput() {
          defer c.wg.Done()
      
          var disconnectedPeers []peer.ID
      
      
      Severity: Major
      Found in examples/chat2-reliable/chat.go - About 1 hr to fix

        Method Chat.discoverNodes has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
        Open

        func (c *Chat) discoverNodes(connectionWg *sync.WaitGroup) {
            defer c.wg.Done()
            defer connectionWg.Done()
        
            <-c.uiReady // wait until UI is ready
        Severity: Minor
        Found in examples/chat2-reliable/chat.go - About 55 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

        Avoid deeply nested control flow statements.
        Open

                                    if err != nil {
                                        c.ui.ErrorMessage(err)
                                        return
                                    }
        Severity: Major
        Found in examples/chat2-reliable/chat.go - About 45 mins to fix

          Method Chat.publish has 5 return statements (exceeds 4 allowed).
          Open

          func (c *Chat) publish(ctx context.Context, message *pb.Message) error {
              msgBytes, err := proto.Marshal(message)
              if err != nil {
                  return err
              }
          Severity: Major
          Found in examples/chat2-reliable/chat.go - About 35 mins to fix

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

                if options.Filter.Enable {
                    cf := protocol.ContentFilter{
                        PubsubTopic:   relay.DefaultWakuTopic,
                        ContentTopics: protocol.NewContentTopicSet(options.ContentTopic),
                    }
            Severity: Major
            Found in examples/chat2-reliable/chat.go and 1 other location - About 4 hrs to fix
            examples/chat2/chat.go on lines 63..97

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

            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

                            if line == "/peers" {
                                peers := c.node.Host().Network().Peers()
                                if len(peers) == 0 {
                                    c.ui.InfoMessage("No peers available")
                                } else {
            Severity: Major
            Found in examples/chat2-reliable/chat.go and 1 other location - About 4 hrs to fix
            examples/chat2/chat.go on lines 204..233

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

            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

                    if err != nil {
                        c.ui.ErrorMessage(errors.New(err.Error()))
                    } else {
                        var nodeList []peer.AddrInfo
                        for _, n := range nodes {
            Severity: Major
            Found in examples/chat2-reliable/chat.go and 1 other location - About 3 hrs to fix
            examples/chat2/chat.go on lines 508..533

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

            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

                            if strings.HasPrefix(line, "/connect") {
                                peer := strings.TrimPrefix(line, "/connect ")
                                c.wg.Add(1)
                                go func(peer string) {
                                    defer c.wg.Done()
            Severity: Major
            Found in examples/chat2-reliable/chat.go and 1 other location - About 3 hrs to fix
            examples/chat2/chat.go on lines 173..201

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

            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

                for _, n := range c.options.StaticNodes {
                    go func(addr multiaddr.Multiaddr) {
                        defer wg.Done()
                        ctx, cancel := context.WithTimeout(c.ctx, time.Duration(10)*time.Second)
                        defer cancel()
            Severity: Major
            Found in examples/chat2-reliable/chat.go and 1 other location - About 1 hr to fix
            examples/chat2/chat.go on lines 425..438

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

            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 decodeMessage(contentTopic string, wakumsg *wpb.WakuMessage) (*pb.Message, error) {
                keyInfo := &payload.KeyInfo{
                    Kind: payload.None,
                }
            
            
            Severity: Major
            Found in examples/chat2-reliable/chat.go and 1 other location - About 1 hr to fix
            examples/chat2/chat.go on lines 344..360

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

            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

                if c.options.RLNRelay.Enable {
                    err = c.node.RLNRelay().AppendRLNProof(wakuMsg, c.node.Timesource().Now())
                    if err != nil {
                        return err
                    }
            Severity: Major
            Found in examples/chat2-reliable/chat.go and 1 other location - About 1 hr to fix
            examples/chat2/chat.go on lines 310..324

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

            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