CodeHealthAnalyzer Documentation
CodeHealthAnalyzer is a Python library for code health analysis focused on three areas:
size violations in modules, classes, functions, and templates
inline CSS and JavaScript in HTML templates
linting issues collected through Ruff
Key Features
Stable Python API with
CodeAnalyzerand specialized analyzersComplete CLI with
analyze,violations,templates,errors,score,info,dashboard,format, andlintReports in JSON, HTML, Markdown, and CSV
Optional FastAPI dashboard for aggregated metrics
Typed report contract and centralized versioning
JSON configuration for limits, directories, and exclusions
Installation
pip install codehealthanalyzer
With dashboard support:
pip install "codehealthanalyzer[web]"
Quick Start
CLI (Command Line Interface)
cha analyze .
cha analyze . --format all --output reports
cha violations . --format csv
cha templates . --config cha_config.json
cha errors . --no-json --format markdown
cha dashboard .
Python API
from codehealthanalyzer import CodeAnalyzer
analyzer = CodeAnalyzer(
".",
config={"target_dir": ".", "templates_dir": ["templates"]},
)
report = analyzer.generate_full_report(output_dir="reports")
print(report["summary"]["quality_score"])
Configuration
Example cha_config.json:
{
"limits": {
"python_function": { "yellow": 30, "red": 50 },
"python_class": { "yellow": 300, "red": 500 },
"python_module": { "yellow": 500, "red": 1000 },
"html_template": { "yellow": 150, "red": 200 },
"test_file": { "yellow": 400, "red": 600 }
},
"target_dir": ".",
"templates_dir": ["templates", "app/templates"],
"exclude_dirs": ["legacy", "vendor"],
"ruff_fix": false,
"no_default_excludes": false
}
Supported fields:
limits: overrides size thresholdstarget_dir: directory analyzed by Rufftemplates_dir: string or list of template directoriesexclude_dirs: string or list of extra directories to ignoreruff_fix: runsruff check --fixbefore collectionno_default_excludes: disables the default exclusions
Report detail modes for analyze:
--detail summary: generatessummary_report.json+ domain files--detail standard: addsanalysis_report.json--detail full: addsfull_report.json
Report Contract
The consolidated report always contains:
{
"metadata": {...},
"summary": {...},
"violations": {...},
"templates": {...},
"errors": {...},
"priorities": [...],
"quality_score": 0,
}
Typed schemas live in codehealthanalyzer/schemas.py.