Showing 1,008 of 1,820 total issues
Function Merge
has 73 lines of code (exceeds 50 allowed). Consider refactoring. Open
func Merge(cmd *cobra.Command, spec *api.ServiceSpec, c api.ControlClient) error {
flags := cmd.Flags()
if flags.Changed("force") {
force, err := flags.GetBool("force")
Method testSuite.TestAllocateServiceConflictingUserDefinedPorts
has 73 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (suite *testSuite) TestAllocateServiceConflictingUserDefinedPorts() {
s := store.NewMemoryStore(nil)
suite.NotNil(s)
defer s.Close()
Method testSuite.TestNodeAttachmentOnLeadershipChange
has 73 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (suite *testSuite) TestNodeAttachmentOnLeadershipChange() {
s := store.NewMemoryStore(nil)
suite.NotNil(s)
defer s.Close()
Function EventFromStoreAction
has 21 return statements (exceeds 4 allowed). Open
func EventFromStoreAction(sa StoreAction, oldObject StoreObject) (Event, error) {
switch v := sa.Target.(type) {
case *StoreAction_Node:
switch sa.Action {
case StoreActionKindCreate:
Method Endpoint_VirtualIP.Unmarshal
has 21 return statements (exceeds 4 allowed). Open
func (m *Endpoint_VirtualIP) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
Function WatchMessageEvent
has 21 return statements (exceeds 4 allowed). Open
func WatchMessageEvent(c Event) *WatchMessage_Event {
switch v := c.(type) {
case EventCreateNode:
return &WatchMessage_Event{Action: WatchActionKindCreate, Object: &Object{Object: &Object_Node{Node: v.Node}}}
case EventUpdateNode:
Method StoreSnapshot.CopyFrom
has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring. Open
func (m *StoreSnapshot) CopyFrom(src interface{}) {
o := src.(*StoreSnapshot)
*m = *o
if o.Nodes != 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 LogAttr.Unmarshal
has 21 return statements (exceeds 4 allowed). Open
func (m *LogAttr) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
Method ContainerSpec_Ulimit.Unmarshal
has 21 return statements (exceeds 4 allowed). Open
func (m *ContainerSpec_Ulimit) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
Method Allocator.allocateNode
has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring. Open
func (a *Allocator) allocateNode(ctx context.Context, node *api.Node, existingAddressesOnly bool, networks []*api.Network) bool {
var allocated bool
nc := a.netCtx
- 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 MemoryStore.update
has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring. Open
func (s *MemoryStore) update(proposer state.Proposer, cb func(Tx) error) error {
defer metrics.StartTimer(updateLatencyTimer)()
s.updateLock.Lock()
memDBTx := s.memDB.Txn(true)
- 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 portAllocator.isPortsAllocatedOnInit
has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring. Open
func (pa *portAllocator) isPortsAllocatedOnInit(s *api.Service, onInit bool) bool {
// If service has no user-defined endpoint and allocated endpoint,
// we assume it is allocated and return true.
if s.Endpoint == nil && s.Spec.Endpoint == nil {
return true
- 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 StoreSnapshot.CopyFrom
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (m *StoreSnapshot) CopyFrom(src interface{}) {
o := src.(*StoreSnapshot)
*m = *o
if o.Nodes != nil {
Method Supervisor.DelayStart
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (r *Supervisor) DelayStart(ctx context.Context, _ store.Tx, oldTask *api.Task, newTaskID string, delay time.Duration, waitStop bool) <-chan struct{} {
ctx, cancel := context.WithCancel(context.Background())
doneCh := make(chan struct{})
r.mu.Lock()
Method Manager.handleVolume
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (vm *Manager) handleVolume(ctx context.Context, id string) error {
var volume *api.Volume
vm.store.View(func(tx store.ReadTx) {
volume = store.GetVolume(tx, id)
})
Method Allocator.allocateTasks
has 71 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (a *Allocator) allocateTasks(ctx context.Context, existingAddressesOnly bool) error {
var (
nc = a.netCtx
tasks []*api.Task
allocatedTasks []*api.Task
Function Do
has 20 return statements (exceeds 4 allowed). Open
func Do(ctx context.Context, task *api.Task, ctlr Controller) (*api.TaskStatus, error) {
status := task.Status.Copy()
// stay in the current state.
noop := func(errs ...error) (*api.TaskStatus, error) {
Method Server.ListNodes
has 20 return statements (exceeds 4 allowed). Open
func (s *Server) ListNodes(ctx context.Context, request *api.ListNodesRequest) (*api.ListNodesResponse, error) {
var (
nodes []*api.Node
err error
)
Function processIPAMOptions
has 70 lines of code (exceeds 50 allowed). Consider refactoring. Open
func processIPAMOptions(cmd *cobra.Command) (*api.IPAMOptions, error) {
flags := cmd.Flags()
var ipamOpts *api.IPAMOptions
if flags.Changed("ipam-driver") {
Function dumpSnapshot
has 70 lines of code (exceeds 50 allowed). Consider refactoring. Open
func dumpSnapshot(swarmdir, unlockKey string, redact bool) error {
_, snapshot, err := loadData(swarmdir, unlockKey)
if err != nil {
return err
}