Showing 244 of 303 total issues
Function Test500
has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring. Open
Open
func Test500(t *testing.T) {
maxMsgs := 500
maxMsgBytes := int2Bytes(maxMsgs)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
- 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 Execute
has 23 return statements (exceeds 4 allowed). Open
Open
func Execute(options NodeOptions) error {
// Set encoding for logs (console, json, ...)
// Note that libp2p reads the encoding from GOLOG_LOG_FMT env var.
utils.InitLogger(options.LogEncoding, options.LogOutput)
Method WakuStore.Request
has 77 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (s *WakuStore) Request(ctx context.Context, criteria Criteria, opts ...RequestOption) (*Result, error) {
params := new(Parameters)
optList := DefaultOptions()
optList = append(optList, opts...)
Function execute
has 77 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func execute(options Options) {
var err error
hostAddr, _ := net.ResolveTCPAddr("tcp", fmt.Sprintf("0.0.0.0:%d", options.Port))
if options.NodeKey == nil {
Function TestDecoupledStoreFromRelay
has 75 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestDecoupledStoreFromRelay(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// NODE1: Relay Node + Filter Server
Function TestStaticShardingLimits
has 75 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestStaticShardingLimits(t *testing.T) {
log := utils.Logger()
if os.Getenv("RUN_FLAKY_TESTS") != "true" {
Method WakuFilterLightNode.IncorrectSubscribe
has 75 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (wf *WakuFilterLightNode) IncorrectSubscribe(ctx context.Context, contentFilter protocol.ContentFilter, opts ...FilterSubscribeOption) ([]*subscription.SubscriptionDetails, error) {
wf.RLock()
defer wf.RUnlock()
if err := wf.ErrOnNotRunning(); err != nil {
return nil, err
Method Pairing.responderHandshake
has 74 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (p *Pairing) responderHandshake(ctx context.Context, msgCh <-chan *pb.WakuMessage) (doneCh chan error) {
doneCh = make(chan error, 1)
func() {
defer close(doneCh)
Function TestWakuRelayAutoShard
has 73 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestWakuRelayAutoShard(t *testing.T) {
testcTopic := "/toychat/2/huilong/proto"
testcTopic1 := "/toychat/1/huilong/proto"
port, err := tests.FindFreePort(t, "", 5)
Function TestWakuRLNOptions
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestWakuRLNOptions(t *testing.T) {
topicHealthStatusChan := make(chan peermanager.TopicHealthStatus, 100)
key, err := tests.RandomHex(32)
require.NoError(t, err)
Method WakuPeerExchange.Request
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (wakuPX *WakuPeerExchange) Request(ctx context.Context, numPeers int, opts ...RequestOption) error {
params := new(PeerExchangeRequestParameters)
params.host = wakuPX.h
params.log = wakuPX.log
params.pm = wakuPX.pm
Function main
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func main() {
// Removing noisy logs
lvl, err := logging.LevelFromString("error")
if err != nil {
panic(err)
Function TestWakuStoreResult
has 71 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestWakuStoreResult(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 70 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (rlnRelay *WakuRLNRelay) ValidateMessage(msg *pb.WakuMessage, optionalTime *time.Time) (messageValidationResult, error) {
if msg == nil {
return validationError, errors.New("nil message")
}
Method PeerManager.selectServicePeer
has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring. Open
Open
func (pm *PeerManager) selectServicePeer(criteria PeerSelectionCriteria) (PeerSet, error) {
peers := make(PeerSet)
var err error
for retryCnt := 0; retryCnt < 1; retryCnt++ {
//Try to fetch from serviceSlot
- 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
Method DB.Discover
has 67 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (db *DB) Discover(ns string, cookie []byte, limit int) ([]dbi.RegistrationRecord, []byte, error) {
now := time.Now().Unix()
var (
counter int64
Method WakuRLNRelaySuite.TestValidateMessage
has 67 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (s *WakuRLNRelaySuite) TestValidateMessage() {
groupKeyPairs, _, err := r.CreateMembershipList(100)
s.Require().NoError(err)
ctx, cancel := context.WithCancel(context.Background())
Function TestDiscV5WithShardFilter
has 67 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestDiscV5WithShardFilter(t *testing.T) {
// Following topic syntax for shard /waku/2/rs/<cluster_id>/<shard_number>
pubSubTopic := "/waku/2/rs/10/1"
Function getConfig
has 66 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func getConfig(configJSON string) (WakuConfig, error) {
var config WakuConfig
if configJSON != "" {
err := json.Unmarshal([]byte(configJSON), &config)
if err != nil {
Function TestQueryOptions
has 65 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestQueryOptions(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
pubSubTopic := "/waku/2/go/store/test"