Showing 1,008 of 1,820 total issues
Method volumeSet.isVolumeAvailableOnNode
has 5 return statements (exceeds 4 allowed). Open
Open
func (vs *volumeSet) isVolumeAvailableOnNode(mount *api.Mount, node *NodeInfo) string {
source := mount.Source
// first, discern whether we're looking for a group or a volume
// try trimming off the "group:" prefix. if the resulting string is
// different from the input string (meaning something has been trimmed),
Method Server.UpdateNode
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
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 {
- 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 Manager.createVolume
has 5 return statements (exceeds 4 allowed). Open
Open
func (vm *Manager) createVolume(ctx context.Context, v *api.Volume) error {
l := log.G(ctx).WithField("volume.id", v.ID).WithField("driver", v.Spec.Driver.Name)
l.Info("creating volume")
p, err := vm.getPlugin(v.Spec.Driver.Name)
Function validateResources
has 5 return statements (exceeds 4 allowed). Open
Open
func validateResources(r *api.Resources) error {
if r == nil {
return nil
}
Method testSuite.TestAllocateServiceConflictingUserDefinedPorts
has 5 return statements (exceeds 4 allowed). Open
Open
func (suite *testSuite) TestAllocateServiceConflictingUserDefinedPorts() {
s := store.NewMemoryStore(nil)
suite.NotNil(s)
defer s.Close()
Method portSpace.allocate
has 5 return statements (exceeds 4 allowed). Open
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 {
Method Batch.Update
has 5 return statements (exceeds 4 allowed). Open
Open
func (batch *Batch) Update(cb func(Tx) error) error {
if batch.err != nil {
return batch.err
}
Method Node.StreamRaftMessage
has 5 return statements (exceeds 4 allowed). Open
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
Method Transport.AddPeer
has 5 return statements (exceeds 4 allowed). Open
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")
Method testSuite.TestServiceUpdatePort
has 5 return statements (exceeds 4 allowed). Open
Open
func (suite *testSuite) TestServiceUpdatePort() {
s := store.NewMemoryStore(nil)
suite.NotNil(s)
defer s.Close()
Method Cluster.UpdateMember
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Cluster) UpdateMember(id uint64, m *api.RaftMember) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[id] {
Function Parse
has 5 return statements (exceeds 4 allowed). Open
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"
Method Manager.IsStateDirty
has 5 return statements (exceeds 4 allowed). Open
Open
func (m *Manager) IsStateDirty() (bool, error) {
var (
storeSnapshot *api.StoreSnapshot
err error
)
Method Node.saveToStorage
has 5 return statements (exceeds 4 allowed). Open
Open
func (n *Node) saveToStorage(
ctx context.Context,
raftConfig *api.RaftConfig,
hardState raftpb.HardState,
entries []raftpb.Entry,
Function WaitForCluster
has 5 return statements (exceeds 4 allowed). Open
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:
Function CheckValuesOnNodes
has 5 return statements (exceeds 4 allowed). Open
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
Method SecretDriver.Get
has 5 return statements (exceeds 4 allowed). Open
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 {
Method Allocator.reallocateNode
has 5 return statements (exceeds 4 allowed). Open
Open
func (a *Allocator) reallocateNode(ctx context.Context, nodeID string) error {
var (
node *api.Node
)
a.store.View(func(tx store.ReadTx) {
Method Node.TransferLeadership
has 5 return statements (exceeds 4 allowed). Open
Open
func (n *Node) TransferLeadership(ctx context.Context) error {
ctx, cancelTransfer := context.WithTimeout(ctx, n.reqTimeout())
defer cancelTransfer()
n.stopMu.RLock()
Function ParseAddConfig
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
Open
func ParseAddConfig(cmd *cobra.Command, spec *api.ServiceSpec, flagName string) error {
flags := cmd.Flags()
if flags.Changed(flagName) {
configs, err := flags.GetStringSlice(flagName)
- 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"