Elixir Complexity Analyzer

A powerful CLI tool for analyzing cyclomatic and cognitive complexity in Elixir projects. Perfect for CI/CD pipelines and code quality monitoring.

Quick Start

# Analyze current directory (default: cyclomatic complexity)
mix complexity

# Analyze cognitive complexity with custom thresholds
mix complexity ./lib --type cognitive --error-threshold 15 --warning-threshold 10

# Generate detailed report
mix complexity ./lib --report complexity-report.json

# Or use the --default-report option
mix complexity ./lib --default-report

Features

CLI Options

Option Description Default
--type <type> Complexity type to analyze (cyclomatic or cognitive) cyclomatic
--error-threshold <number> Error threshold for complexity 20
--warning-threshold <number> Warning threshold for complexity 10
--ignore <patterns> Comma-separated glob patterns to ignore ""
--report <file> Save detailed JSON report to file -
--default-report Save report to default location (complexity-report.json) -

Usage Examples

CI/CD Integration

# GitHub Actions example
- name: Check code complexity
  run: mix complexity ./lib --type cognitive --error-threshold 20

Local Development

# Quick check with default settings (cyclomatic complexity)
mix complexity ./lib

# Analyze cognitive complexity with strict thresholds
mix complexity ./lib --type cognitive --error-threshold 15 --warning-threshold 8

# Generate report for tracking
mix complexity ./lib --report "reports/complexity-$(date +%Y%m%d).json"

# Generate report to default location
mix complexity ./lib --default-report

Advanced Filtering

# Ignore test files and external libraries
mix complexity ./lib --ignore "**/test/**,**/*.spec.ex,**/vendor/**"

# Focus on specific file types (ignore test files)
mix complexity ./lib --ignore "**/*_test.exs,**/test_helper.exs"

Configuration File

Create a complexity.config.json file in the root of your analyzed directory:

{
  "type": "cognitive",
  "errorThreshold": 25,
  "warningThreshold": 15,
  "ignore": [
    "**/test/**",
    "**/*_test.exs",
    "**/vendor/**"
  ]
}

CLI options will override configuration file settings.

Exit Codes

Output Examples

Success:

✓ No complexity threshold violations found

Warnings and Errors:

🟠 [12/10] parseComplexConfig @ lib/utils/parser.ex:45
🟠 [16/10] render_rows @ lib/components/data_table.ex:23
🔴 [25/20] process_data @ lib/legacy/processor.ex:156
🔴 [28/20] convert_legacy_data @ lib/legacy/converter.ex:89

The format shows: [actual_complexity/threshold] function_name @ file_path:line

Note: All violations are collected and displayed, then exits with code 1 if any errors exist