Skip to content

Fix go:S3776: Cognitive Complexity of functions should not be too high #428

Open

Description

@lhein

Summary

Sonar rule go:S3776 flags functions with a cognitive complexity above 15. Four functions were affected.

Changes

KaotoReconciler.Reconcile (complexity 33 → ≤15)

Extracted three private helpers:

  • handleFinalizer(ctx, rr) — finalizer add/remove and deletion cleanup
  • runActions(ctx, rr) — actions loop and error collection
  • updateReconcileStatus(rr, allErrors) — condition and phase computation

ingressAction.Apply (complexity 16 → ≤15)

Extracted handleNotRequired(ctx, rr, condition) for the cleanup path when ingress is not required.

routeAction.Apply (complexity 16 → ≤15)

Same pattern: extracted handleNotRequired(ctx, rr, condition).

ConditionStatus in test/support/support_conditions.go (complexity 17 → ≤15)

Extracted deploymentConditionStatus(d, conditionType) helper for the Deployment case.

All refactors are purely structural — behavior is identical.

Prevention

  • Go equivalent: gocognit linter (currently disabled in .golangci.yml). Enabling it would catch this at lint time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions