waku-org/go-waku

View on GitHub

Showing 300 of 401 total issues

Function TestDiscV5WithCapabilitiesFilter has 55 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func TestDiscV5WithCapabilitiesFilter(t *testing.T) {

    // H1
    host1, _, prvKey1 := tests.CreateHost(t)
    udpPort1, err := tests.FindFreeUDPPort(t, "127.0.0.1", 3)
Severity: Minor
Found in waku/v2/discv5/discover_test.go - About 1 hr to fix

    Function TestWakuStoreWithStaticSharding has 55 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func TestWakuStoreWithStaticSharding(t *testing.T) {
        ctx, cancel := context.WithCancel(context.Background())
        defer cancel()
    
        host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
    Severity: Minor
    Found in waku/v2/protocol/legacy_store/waku_store_protocol_test.go - About 1 hr to fix

      Method WakuRLNRelay.ValidateMessage has 12 return statements (exceeds 4 allowed).
      Open

      func (rlnRelay *WakuRLNRelay) ValidateMessage(msg *pb.WakuMessage, optionalTime *time.Time) (messageValidationResult, error) {
          if msg == nil {
              return validationError, errors.New("nil message")
          }
      
      
      Severity: Major
      Found in waku/v2/protocol/rln/waku_rln_relay.go - About 1 hr to fix

        Function NewNode has 12 return statements (exceeds 4 allowed).
        Open

        func NewNode(instance *WakuInstance, configJSON string) error {
            if err := validateInstance(instance, NotConfigured); err != nil {
                return err
            }
        
        
        Severity: Major
        Found in library/node.go - About 1 hr to fix

          Method WakuRelay.Publish has 12 return statements (exceeds 4 allowed).
          Open

          func (w *WakuRelay) Publish(ctx context.Context, message *pb.WakuMessage, opts ...PublishOption) (pb.MessageHash, error) {
              // Publish a `WakuMessage` to a PubSub topic.
              if w.pubsub == nil {
                  return pb.MessageHash{}, errors.New("PubSub hasn't been set")
              }
          Severity: Major
          Found in waku/v2/protocol/relay/waku_relay.go - About 1 hr to fix

            Method DynamicGroupManager.handler has 54 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (gm *DynamicGroupManager) handler(events []*contracts.RLNMemberRegistered, latestProcessBlock uint64) error {
                gm.lastBlockProcessedMutex.Lock()
                defer gm.lastBlockProcessedMutex.Unlock()
            
                toRemoveTable := om.New()
            Severity: Minor
            Found in waku/v2/protocol/rln/group_manager/dynamic/dynamic.go - About 1 hr to fix

              Method WakuNode.findRelayNodes has 54 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (w *WakuNode) findRelayNodes(ctx context.Context) {
                  defer utils.LogOnPanic()
                  defer w.wg.Done()
              
                  // Feed peers more often right after the bootstrap, then backoff
              Severity: Minor
              Found in waku/v2/node/wakunode2.go - About 1 hr to fix

                Function NewDynamicGroupManager has 9 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    ethClientAddr string,
                    memContractAddr common.Address,
                    membershipIndexToLoad *uint,
                    appKeystore *keystore.AppKeystore,
                    keystorePassword string,
                Severity: Major
                Found in waku/v2/protocol/rln/group_manager/dynamic/dynamic.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 DB.prepareStmts has 11 return statements (exceeds 4 allowed).
                    Open

                    func (db *DB) prepareStmts() error {
                        stmt, err := db.db.Prepare("INSERT INTO registrations VALUES (NULL, ?, ?, ?, ?)")
                        if err != nil {
                            return err
                        }
                    Severity: Major
                    Found in waku/v2/rendezvous/db.go - About 1 hr to fix

                      Function getStoreParams has 11 return statements (exceeds 4 allowed).
                      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: Major
                      Found in cmd/waku/server/rest/store.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

                          Function TestWakuLightPushCornerCases has 52 lines of code (exceeds 50 allowed). Consider refactoring.
                          Open

                          func TestWakuLightPushCornerCases(t *testing.T) {
                              ctx, cancel := context.WithCancel(context.Background())
                              defer cancel()
                          
                              testTopic := "/waku/2/go/lightpush/test"
                          Severity: Minor
                          Found in waku/v2/protocol/lightpush/waku_lightpush_test.go - About 1 hr to fix

                            Method DB.prepareStmts has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                            Open

                            func (db *DB) prepareStmts() error {
                                stmt, err := db.db.Prepare("INSERT INTO registrations VALUES (NULL, ?, ?, ?, ?)")
                                if err != nil {
                                    return err
                                }
                            Severity: Minor
                            Found in waku/v2/rendezvous/db.go - About 1 hr to fix

                              Function rlnFlags has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                              Open

                              func rlnFlags() []cli.Flag {
                                  return []cli.Flag{
                                      &cli.BoolFlag{
                                          Name:        "rln-relay",
                                          Value:       false,
                              Severity: Minor
                              Found in cmd/waku/flags_rln.go - About 1 hr to fix

                                Function Multiaddress has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                                Open

                                func Multiaddress(node *enode.Node) (peer.ID, []multiaddr.Multiaddr, error) {
                                    pubKey := utils.EcdsaPubKeyToSecp256k1PublicKey(node.Pubkey())
                                    peerID, err := peer.IDFromPublicKey(pubKey)
                                    if err != nil {
                                        return "", nil, err
                                Severity: Minor
                                Found in waku/v2/protocol/enr/enr.go - About 1 hr to fix

                                  Method WakuLightPush.handleOpts has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                                  Open

                                  func (wakuLP *WakuLightPush) handleOpts(ctx context.Context, message *wpb.WakuMessage, opts ...RequestOption) (*lightPushRequestParameters, error) {
                                      params := new(lightPushRequestParameters)
                                      params.host = wakuLP.h
                                      params.log = wakuLP.log
                                      params.pm = wakuLP.pm
                                  Severity: Minor
                                  Found in waku/v2/protocol/lightpush/waku_lightpush.go - About 1 hr to fix

                                    Method HistoryRetriever.createMessagesRequest has 8 arguments (exceeds 4 allowed). Consider refactoring.
                                    Open

                                        ctx context.Context,
                                        peerID peer.ID,
                                        criteria store.FilterCriteria,
                                        cursor []byte,
                                        limit uint64,
                                    Severity: Major
                                    Found in waku/v2/api/history/history.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

                                      Function handleNWakuPreMigration has 9 return statements (exceeds 4 allowed).
                                      Open

                                      func handleNWakuPreMigration(db *sql.DB) (bool, error) {
                                          // Check if there's an user version in the DB, and if migration table does not exist.
                                          // Rename existing table, and move data afterwards
                                      
                                          var nwakuDBVersion int
                                      Severity: Major
                                      Found in waku/persistence/sqlite/nwaku.go - About 55 mins to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language