waku-org/go-waku

View on GitHub
examples/chat2/chat.go

Summary

Maintainability
F
4 days
Test Coverage

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

func (c *Chat) parseInput() {
    defer c.wg.Done()
    for {
        select {
        case <-c.ctx.Done():
Severity: Minor
Found in examples/chat2/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 88 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (c *Chat) parseInput() {
    defer c.wg.Done()
    for {
        select {
        case <-c.ctx.Done():
Severity: Major
Found in examples/chat2/chat.go - About 2 hrs to fix

    Function NewChat has 58 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/chat.go - About 1 hr to fix

      Method Chat.publish has 52 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (c *Chat) publish(ctx context.Context, message string) error {
          msg := &pb.Chat2Message{
              Timestamp: uint64(c.node.Timesource().Now().Unix()),
              Nick:      c.nick,
              Payload:   []byte(message),
      Severity: Minor
      Found in examples/chat2/chat.go - About 1 hr to fix

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

        func (c *Chat) parseInput() {
            defer c.wg.Done()
            for {
                select {
                case <-c.ctx.Done():
        Severity: Major
        Found in examples/chat2/chat.go - About 55 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                      if err != nil {
                                          c.ui.ErrorMessage(err)
                                          return
                                      }
          Severity: Major
          Found in examples/chat2/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 string) error {
                msg := &pb.Chat2Message{
                    Timestamp: uint64(c.node.Timesource().Now().Unix()),
                    Nick:      c.nick,
                    Payload:   []byte(message),
            Severity: Major
            Found in examples/chat2/chat.go - About 35 mins to fix

              Method Chat.discoverNodes has a Cognitive Complexity of 21 (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/chat.go - About 25 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

              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/chat.go and 1 other location - About 4 hrs to fix
              examples/chat2-reliable/chat.go on lines 77..110

              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/chat.go and 1 other location - About 4 hrs to fix
              examples/chat2-reliable/chat.go on lines 226..255

              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/chat.go and 1 other location - About 3 hrs to fix
              examples/chat2-reliable/chat.go on lines 522..545

              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/chat.go and 1 other location - About 3 hrs to fix
              examples/chat2-reliable/chat.go on lines 195..223

              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 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/chat.go and 1 other location - About 1 hr to fix
              examples/chat2-reliable/chat.go on lines 439..452

              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.Chat2Message, error) {
                  keyInfo := &payload.KeyInfo{
                      Kind: payload.None,
                  }
              
              
              Severity: Major
              Found in examples/chat2/chat.go and 1 other location - About 1 hr to fix
              examples/chat2-reliable/chat.go on lines 365..381

              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 {
                      // for future version when we support more than one rln protected content topic,
                      // we should check the message content topic as well
                      err = c.node.RLNRelay().AppendRLNProof(wakuMsg, c.node.Timesource().Now())
                      if err != nil {
              Severity: Major
              Found in examples/chat2/chat.go and 1 other location - About 1 hr to fix
              examples/chat2-reliable/chat.go on lines 333..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 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