waku-org/go-waku

View on GitHub

Showing 401 of 401 total issues

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

package main

import (
    "fmt"

Severity: Major
Found in examples/chat2/flags.go and 1 other location - About 3 days to fix
examples/chat2-reliable/flags.go on lines 1..230

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

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

package main

import (
    "fmt"

Severity: Major
Found in examples/chat2-reliable/flags.go and 1 other location - About 3 days to fix
examples/chat2/flags.go on lines 1..230

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

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

Function Execute has a Cognitive Complexity of 91 (exceeds 20 allowed). Consider refactoring.
Open

func Execute(options NodeOptions) error {
    // Set encoding for logs (console, json, ...)
    // Note that libp2p reads the encoding from GOLOG_LOG_FMT env var.
    lvl, err := zapcore.ParseLevel(options.LogLevel)
    if err != nil {
Severity: Minor
Found in cmd/waku/node.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

Function Execute has 285 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func Execute(options NodeOptions) error {
    // Set encoding for logs (console, json, ...)
    // Note that libp2p reads the encoding from GOLOG_LOG_FMT env var.
    lvl, err := zapcore.ParseLevel(options.LogLevel)
    if err != nil {
Severity: Major
Found in cmd/waku/node.go - About 1 day to fix

    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 WakuNode.startKeepAlive has a Cognitive Complexity of 79 (exceeds 20 allowed). Consider refactoring.
    Open

    func (w *WakuNode) startKeepAlive(ctx context.Context, randomPeersPingDuration time.Duration, allPeersPingDuration time.Duration) {
        defer utils.LogOnPanic()
        defer w.wg.Done()
    
        if !w.opts.enableRelay {
    Severity: Minor
    Found in waku/v2/node/keepalive.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

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

    package main
    
    import (
        "crypto/ecdsa"
        "errors"
    Severity: Major
    Found in examples/chat2/options.go and 1 other location - About 1 day to fix
    examples/chat2-reliable/options.go on lines 1..126

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

    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

    package main
    
    import (
        "crypto/ecdsa"
        "errors"
    Severity: Major
    Found in examples/chat2-reliable/options.go and 1 other location - About 1 day to fix
    examples/chat2/options.go on lines 1..126

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

    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 wakunode2.go has 781 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    package node
    
    import (
        "context"
        "math/rand"
    Severity: Major
    Found in waku/v2/node/wakunode2.go - About 1 day to fix

      Method MissingMessageVerifier.fetchMessagesBatch has a Cognitive Complexity of 63 (exceeds 20 allowed). Consider refactoring.
      Open

      func (m *MissingMessageVerifier) fetchMessagesBatch(c chan<- *protocol.Envelope, interest criteriaInterest, batchFrom int, batchTo int, now time.Time) error {
          contentTopics := interest.contentFilter.ContentTopics.ToList()
      
          logger := m.logger.With(
              zap.Stringer("peerID", interest.peerID),
      Severity: Minor
      Found in waku/v2/api/missing/missing_messages.go - About 7 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 getFlags has 193 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func getFlags() []cli.Flag {
          // Defaults
          options.Fleet = fleetProd
      
          testCT, err := protocol.NewContentTopic("toy-chat", "3", "mingde", "proto")
      Severity: Major
      Found in examples/chat2-reliable/flags.go - About 6 hrs to fix

        Function getFlags has 193 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func getFlags() []cli.Flag {
            // Defaults
            options.Fleet = fleetProd
        
            testCT, err := protocol.NewContentTopic("toy-chat", "3", "mingde", "proto")
        Severity: Major
        Found in examples/chat2/flags.go - About 6 hrs to fix

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

              switch msg := msg.(type) {
          
              case tea.WindowSizeMsg:
                  m.width, m.height = msg.Width, msg.Height
          
          
          Severity: Major
          Found in examples/chat2/ui.go and 1 other location - About 6 hrs to fix
          examples/chat2-reliable/ui.go on lines 142..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 471.

          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

              switch msg := msg.(type) {
          
              case tea.WindowSizeMsg:
                  m.width, m.height = msg.Width, msg.Height
          
          
          Severity: Major
          Found in examples/chat2-reliable/ui.go and 1 other location - About 6 hrs to fix
          examples/chat2/ui.go on lines 142..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 471.

          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 client.go has 648 lines of code (exceeds 500 allowed). Consider refactoring.
          Open

          package filter
          
          import (
              "context"
              "encoding/hex"
          Severity: Minor
          Found in waku/v2/protocol/filter/client.go - About 5 hrs to fix

            Function New has a Cognitive Complexity of 51 (exceeds 20 allowed). Consider refactoring.
            Open

            func New(opts ...WakuNodeOption) (*WakuNode, error) {
                var err error
                params := new(WakuNodeParameters)
                params.libP2POpts = DefaultLibP2POptions
            
            
            Severity: Minor
            Found in waku/v2/node/wakunode2.go - About 5 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

            WakuNode has 40 methods (exceeds 20 allowed). Consider refactoring.
            Open

            type WakuNode struct {
                host       host.Host
                opts       *WakuNodeParameters
                log        *zap.Logger
                timesource timesource.Timesource
            Severity: Minor
            Found in waku/v2/node/wakunode2.go - About 5 hrs to fix

              Method HistoryRetriever.Query has a Cognitive Complexity of 48 (exceeds 20 allowed). Consider refactoring.
              Open

              func (hr *HistoryRetriever) Query(
                  ctx context.Context,
                  criteria store.FilterCriteria,
                  storenodeID peer.ID,
                  pageLimit uint64,
              Severity: Minor
              Found in waku/v2/api/history/history.go - About 4 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 getStoreParams has a Cognitive Complexity of 47 (exceeds 20 allowed). Consider refactoring.
              Open

              func getStoreParams(r *http.Request) (store.Criteria, []store.RequestOption, error) {
                  var options []store.RequestOption
                  var err error
                  peerAddrStr := r.URL.Query().Get("peerAddr")
                  var m multiaddr.Multiaddr
              Severity: Minor
              Found in cmd/waku/server/rest/store.go - About 4 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

              Severity
              Category
              Status
              Source
              Language