docker/swarmkit

View on GitHub

Showing 1,008 of 1,820 total issues

Function validateResources has 5 return statements (exceeds 4 allowed).
Open

func validateResources(r *api.Resources) error {
    if r == nil {
        return nil
    }

Severity: Major
Found in manager/controlapi/service.go - About 35 mins to fix

    Method Server.RemoveService has 5 return statements (exceeds 4 allowed).
    Open

    func (s *Server) RemoveService(ctx context.Context, request *api.RemoveServiceRequest) (*api.RemoveServiceResponse, error) {
        if request.ServiceID == "" {
            return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
        }
    
    
    Severity: Major
    Found in manager/controlapi/service.go - About 35 mins to fix

      Method Dispatcher.UpdateTaskStatus has 5 return statements (exceeds 4 allowed).
      Open

      func (d *Dispatcher) UpdateTaskStatus(ctx context.Context, r *api.UpdateTaskStatusRequest) (*api.UpdateTaskStatusResponse, error) {
          d.rpcRW.RLock()
          defer d.rpcRW.RUnlock()
      
          dctx, err := d.isRunningLocked()
      Severity: Major
      Found in manager/dispatcher/dispatcher.go - About 35 mins to fix

        Method Server.UpdateNode has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
        Open

        func (s *Server) UpdateNode(ctx context.Context, request *api.UpdateNodeRequest) (*api.UpdateNodeResponse, error) {
            if request.NodeID == "" || request.NodeVersion == nil {
                return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
            }
            if err := validateNodeSpec(request.Spec); err != nil {
        Severity: Minor
        Found in manager/controlapi/node.go - About 35 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

        Method Transport.AddPeer has 5 return statements (exceeds 4 allowed).
        Open

        func (t *Transport) AddPeer(id uint64, addr string) error {
            t.mu.Lock()
            defer t.mu.Unlock()
            if t.stopped {
                return errors.New("transport stopped")
        Severity: Major
        Found in manager/state/raft/transport/transport.go - About 35 mins to fix

          Function CheckValuesOnNodes has 5 return statements (exceeds 4 allowed).
          Open

          func CheckValuesOnNodes(t *testing.T, clockSource *fakeclock.FakeClock, checkNodes map[uint64]*TestNode, ids []string, values []*api.Node) {
              iteration := 0
              for checkNodeID, node := range checkNodes {
                  assert.NoError(t, testutils.PollFunc(clockSource, func() error {
                      var err error
          Severity: Major
          Found in manager/state/raft/testutils/testutils.go - About 35 mins to fix

            Method Manager.IsStateDirty has 5 return statements (exceeds 4 allowed).
            Open

            func (m *Manager) IsStateDirty() (bool, error) {
                var (
                    storeSnapshot *api.StoreSnapshot
                    err           error
                )
            Severity: Major
            Found in manager/dirty.go - About 35 mins to fix

              Method Node.StreamRaftMessage has 5 return statements (exceeds 4 allowed).
              Open

              func (n *Node) StreamRaftMessage(stream api.Raft_StreamRaftMessageServer) error {
                  // recvdMsg is the current messasge received from the stream.
                  // assembledMessage is where the data from recvdMsg is appended to.
                  var recvdMsg, assembledMessage *api.StreamRaftMessageRequest
                  var err error
              Severity: Major
              Found in manager/state/raft/raft.go - About 35 mins to fix

                Method Allocator.reallocateNode has 5 return statements (exceeds 4 allowed).
                Open

                func (a *Allocator) reallocateNode(ctx context.Context, nodeID string) error {
                    var (
                        node *api.Node
                    )
                    a.store.View(func(tx store.ReadTx) {
                Severity: Major
                Found in manager/allocator/network.go - About 35 mins to fix

                  Method Node.saveToStorage has 5 return statements (exceeds 4 allowed).
                  Open

                  func (n *Node) saveToStorage(
                      ctx context.Context,
                      raftConfig *api.RaftConfig,
                      hardState raftpb.HardState,
                      entries []raftpb.Entry,
                  Severity: Major
                  Found in manager/state/raft/raft.go - About 35 mins to fix

                    Function Parse has 5 return statements (exceeds 4 allowed).
                    Open

                    func Parse(env []string) ([]Constraint, error) {
                        exprs := []Constraint{}
                        for _, e := range env {
                            found := false
                            // each expr is in the form of "key op value"
                    Severity: Major
                    Found in manager/constraint/constraint.go - About 35 mins to fix

                      Method testSuite.TestServiceUpdatePort has 5 return statements (exceeds 4 allowed).
                      Open

                      func (suite *testSuite) TestServiceUpdatePort() {
                          s := store.NewMemoryStore(nil)
                          suite.NotNil(s)
                          defer s.Close()
                      
                      
                      Severity: Major
                      Found in manager/allocator/allocator_test_suite.go - About 35 mins to fix

                        Method SecretDriver.Get has 5 return statements (exceeds 4 allowed).
                        Open

                        func (d *SecretDriver) Get(spec *api.SecretSpec, task *api.Task) ([]byte, bool, error) {
                            if spec == nil {
                                return nil, false, fmt.Errorf("secret spec is nil")
                            }
                            if task == nil {
                        Severity: Major
                        Found in manager/drivers/secrets.go - About 35 mins to fix

                          Method portSpace.allocate has 5 return statements (exceeds 4 allowed).
                          Open

                          func (ps *portSpace) allocate(p *api.PortConfig) (err error) {
                              if p.PublishedPort != 0 {
                                  // If it falls in the dynamic port range check out
                                  // from dynamic port space first.
                                  if p.PublishedPort >= dynamicPortStart && p.PublishedPort <= dynamicPortEnd {
                          Severity: Major
                          Found in manager/allocator/portallocator.go - About 35 mins to fix

                            Method Cluster.UpdateMember has 5 return statements (exceeds 4 allowed).
                            Open

                            func (c *Cluster) UpdateMember(id uint64, m *api.RaftMember) error {
                                c.mu.Lock()
                                defer c.mu.Unlock()
                            
                                if c.removed[id] {
                            Severity: Major
                            Found in manager/state/raft/membership/cluster.go - About 35 mins to fix

                              Method Node.TransferLeadership has 5 return statements (exceeds 4 allowed).
                              Open

                              func (n *Node) TransferLeadership(ctx context.Context) error {
                                  ctx, cancelTransfer := context.WithTimeout(ctx, n.reqTimeout())
                                  defer cancelTransfer()
                              
                                  n.stopMu.RLock()
                              Severity: Major
                              Found in manager/state/raft/raft.go - About 35 mins to fix

                                Method testSuite.TestAllocateServiceConflictingUserDefinedPorts has 5 return statements (exceeds 4 allowed).
                                Open

                                func (suite *testSuite) TestAllocateServiceConflictingUserDefinedPorts() {
                                    s := store.NewMemoryStore(nil)
                                    suite.NotNil(s)
                                    defer s.Close()
                                
                                
                                Severity: Major
                                Found in manager/allocator/allocator_test_suite.go - About 35 mins to fix

                                  Method Batch.Update has 5 return statements (exceeds 4 allowed).
                                  Open

                                  func (batch *Batch) Update(cb func(Tx) error) error {
                                      if batch.err != nil {
                                          return batch.err
                                      }
                                  
                                  
                                  Severity: Major
                                  Found in manager/state/store/memory.go - About 35 mins to fix

                                    Function WaitForCluster has 5 return statements (exceeds 4 allowed).
                                    Open

                                    func WaitForCluster(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[uint64]*TestNode) {
                                        err := testutils.PollFunc(clockSource, func() error {
                                            var prev *etcdraft.Status
                                            var leadNode *TestNode
                                        nodeLoop:
                                    Severity: Major
                                    Found in manager/state/raft/testutils/testutils.go - About 35 mins to fix

                                      Method controller.Logs has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                                      Open

                                      func (r *controller) Logs(ctx context.Context, publisher exec.LogPublisher, options api.LogSubscriptionOptions) error {
                                          if err := r.checkClosed(); err != nil {
                                              return err
                                          }
                                      
                                      
                                      Severity: Minor
                                      Found in swarmd/dockerexec/controller.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

                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language