Showing 300 of 401 total issues
Function TestDiscV5WithCapabilitiesFilter
has 55 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestDiscV5WithCapabilitiesFilter(t *testing.T) {
// H1
host1, _, prvKey1 := tests.CreateHost(t)
udpPort1, err := tests.FindFreeUDPPort(t, "127.0.0.1", 3)
Function TestWakuStoreWithStaticSharding
has 55 lines of code (exceeds 50 allowed). Consider refactoring. Open
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"))
Method WakuRLNRelay.ValidateMessage
has 12 return statements (exceeds 4 allowed). Open
Open
func (rlnRelay *WakuRLNRelay) ValidateMessage(msg *pb.WakuMessage, optionalTime *time.Time) (messageValidationResult, error) {
if msg == nil {
return validationError, errors.New("nil message")
}
Function NewNode
has 12 return statements (exceeds 4 allowed). Open
Open
func NewNode(instance *WakuInstance, configJSON string) error {
if err := validateInstance(instance, NotConfigured); err != nil {
return err
}
Method WakuRelay.Publish
has 12 return statements (exceeds 4 allowed). Open
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")
}
Method DynamicGroupManager.handler
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (gm *DynamicGroupManager) handler(events []*contracts.RLNMemberRegistered, latestProcessBlock uint64) error {
gm.lastBlockProcessedMutex.Lock()
defer gm.lastBlockProcessedMutex.Unlock()
toRemoveTable := om.New()
Method WakuNode.findRelayNodes
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
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
Function NewDynamicGroupManager
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
ethClientAddr string,
memContractAddr common.Address,
membershipIndexToLoad *uint,
appKeystore *keystore.AppKeystore,
keystorePassword string,
Method Chat.parseInput
has 11 return statements (exceeds 4 allowed). Open
Open
func (c *Chat) parseInput() {
defer c.wg.Done()
var disconnectedPeers []peer.ID
Method DB.prepareStmts
has 11 return statements (exceeds 4 allowed). Open
Open
func (db *DB) prepareStmts() error {
stmt, err := db.db.Prepare("INSERT INTO registrations VALUES (NULL, ?, ?, ?, ?)")
if err != nil {
return err
}
Function getStoreParams
has 11 return statements (exceeds 4 allowed). Open
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
Method Chat.publish
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
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),
Function TestWakuLightPushCornerCases
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestWakuLightPushCornerCases(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
testTopic := "/waku/2/go/lightpush/test"
Method DB.prepareStmts
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (db *DB) prepareStmts() error {
stmt, err := db.db.Prepare("INSERT INTO registrations VALUES (NULL, ?, ?, ?, ?)")
if err != nil {
return err
}
Function rlnFlags
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func rlnFlags() []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "rln-relay",
Value: false,
Function Multiaddress
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
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
Method WakuLightPush.handleOpts
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
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
Method HistoryRetriever.createMessagesRequest
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
ctx context.Context,
peerID peer.ID,
criteria store.FilterCriteria,
cursor []byte,
limit uint64,
Method Chat.discoverNodes
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
Open
func (c *Chat) discoverNodes(connectionWg *sync.WaitGroup) {
defer c.wg.Done()
defer connectionWg.Done()
<-c.uiReady // wait until UI is ready
- Read upRead up
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
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