Skip to content

Proposal: Per function complexity override directive. #57

Description

@ichekrygin

Thank you for providing this useful tool.

I’d like to propose an enhancement to improve how gocyclo handles function-level complexity thresholds.

Currently, gocyclo offers two options: setting a global complexity threshold (--over) or ignoring a function entirely via gocyclo:ignore. However, this binary approach is limiting.

Consider a project where all functions stay below --over=10, except for one function with a complexity of 20.
If this function cannot be easily refactored without sacrificing other qualities, my only options are:

  • Raising --over to 20, allowing all functions to double in complexity.
  • Ignoring the function via gocyclo:ignore, which removes all complexity checks for it.

Neither option is ideal. To address this, I propose a per-function override:

// Foo - a complex function.
//gocyclo:max-complexity=20
func Foo() { ... }

This would:

  • Allow case-by-case complexity adjustments while keeping the global threshold.
  • Enforce limits even for overridden functions, preventing unchecked complexity growth.

I’d love to hear your thoughts on this proposal.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions