[ANN] CodeComplexity.jl – Cyclomatic complexity for Julia

[ANN] CodeComplexity.jl – Cyclomatic complexity for Julia

I’ve released CodeComplexity.jl, a small package to measure cyclomatic complexity of Julia code. It helps find overly complex functions, set complexity limits in tests or CI, and scan files, directories, or whole packages.

What it does

  • Per-function complexity – Counts decision points (if/elseif, for/while, try/catch, short-circuit &&/||, ternary, @goto) plus one.

  • Scopes – Single expression, code string, file, directory (recursive), or package (by name or loaded module).

  • CI-friendlycheck_complexity(pkg; max_complexity=10) throws if any function exceeds the limit, so you can fail tests or CI when complexity gets too high.

  • Pairs well with LLMs – When using AI coding assistants, complexity metrics give you a concrete threshold to enforce: reject or refactor generated code that exceeds your limit, and use per-function reports to prompt “simplify this” where it matters.

Quick start


using Pkg; Pkg.add("CodeComplexity")

using CodeComplexity

# Per-function report from a file

fc = file_complexity("src/MyModule.jl")

# Scan a package and enforce a limit (e.g. in tests)

using MyPackage

check_complexity(MyPackage; max_complexity=10)

Links

If you care about keeping functions understandable and testable, or want a single check to gate complexity in CI, CodeComplexity.jl is there. Feedback and contributions welcome.

4 Likes