Biblioteca Python para análise de qualidade e saúde de código
Project description
CodeHealthAnalyzer
Biblioteca Python para análise de saúde de código com foco em três frentes:
- violações de tamanho em módulos, classes, funções e templates
- CSS/JS inline em templates HTML
- erros de linting coletados via Ruff
O que a biblioteca entrega hoje
- API Python com
CodeAnalyzer,ViolationsAnalyzer,TemplatesAnalyzereErrorsAnalyzer - CLI com os comandos
analyze,violations,templates,errors,score,info,dashboard,formatelint - relatórios em
json,html,markdownecsv - dashboard FastAPI opcional com métricas agregadas
- contrato de relatório tipado e versão centralizada
Instalação
pip install codehealthanalyzer
Com dashboard:
pip install "codehealthanalyzer[web]"
Para desenvolvimento:
pip install -e ".[dev,web]"
Uso rápido
CLI
Use cha como comando recomendado (alias curto de codehealthanalyzer).
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 .
API Python
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"])
Configuração
Exemplo de 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
}
Ordem de precedência
- Flags da CLI (maior prioridade)
- Arquivo
--config - Defaults da biblioteca
Campos suportados
| Campo | Tipo | Padrão | O que controla |
|---|---|---|---|
limits |
objeto | limites internos | Limites de tamanho por tipo de arquivo/estrutura |
target_dir |
string | "." |
Diretório alvo para análise de código (incluindo Ruff) |
templates_dir |
string ou lista | autodetecção | Diretórios HTML/Jinja a varrer |
exclude_dirs |
string ou lista | [] |
Exclusões adicionais além das exclusões padrão |
ruff_fix |
boolean | false |
Executa ruff check --fix antes da coleta de erros |
no_default_excludes |
boolean | false |
Remove exclusões padrão (tests, venv, dist, etc.) |
Configurações rápidas por cenário
Projeto Flask/Django com templates em múltiplas pastas:
{
"templates_dir": ["templates", "app/templates", "src/templates"],
"exclude_dirs": ["migrations", "node_modules"]
}
Monorepo (analisar apenas um subprojeto):
{
"target_dir": "services/billing",
"templates_dir": ["services/billing/templates"]
}
Controle de detalhamento dos relatórios
No comando analyze, o JSON completo agora é opcional:
--detail summary: gera resumo + arquivos por domínio (violations/templates/errors)--detail standard(padrão): idem +analysis_report.json--detail full: idem +full_report.json
Arquivos gerados por modo:
summary:summary_report.json,violations_report.json,templates_report.json,errors_report.jsonstandard: todos dosummary+analysis_report.jsonfull: todos dostandard+full_report.json
Exemplos:
cha analyze . --config cha_config.json --detail summary
cha analyze . --detail full --format all --output reports
Troubleshooting
Error: Invalid value for '--config' ... Path 'cha_config.json' does not exist
- Crie o arquivo no diretório atual, ou passe caminho absoluto em
--config.
WARNING: Ignoring invalid distribution ~odehealthanalyzer
- É lixo de instalação antiga no
site-packages; remova diretórios~odehealthanalyzer*.
Contrato de relatório
O relatório consolidado sempre contém:
{
"metadata": {...},
"summary": {...},
"violations": {...},
"templates": {...},
"errors": {...},
"priorities": [...],
"quality_score": 0,
}
Os schemas tipados ficam em codehealthanalyzer/schemas.py.
Desenvolvimento
pytest -q
ruff check codehealthanalyzer tests
black --check codehealthanalyzer tests
isort --check-only codehealthanalyzer tests
Limitações atuais
- a análise de erros depende do executável
ruffestar disponível no ambiente - o dashboard mostra métricas agregadas, não histórico persistente completo
- a análise de templates é baseada em heurísticas simples de HTML e regex
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codehealthanalyzer-1.2.6.tar.gz.
File metadata
- Download URL: codehealthanalyzer-1.2.6.tar.gz
- Upload date:
- Size: 62.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8b825b839bc0c6718bab6f3f61c75bc5de80f327643e40100921c560f882e67
|
|
| MD5 |
b48c24d2dbf7b0851b79d89f047aebce
|
|
| BLAKE2b-256 |
6ad001e7c1bb77ae3d262afd838f90c770fda439f069d7b603aa527aca48b124
|
Provenance
The following attestation bundles were made for codehealthanalyzer-1.2.6.tar.gz:
Publisher:
auto-tag-from-version.yml on imparcialista/codehealthanalyzer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codehealthanalyzer-1.2.6.tar.gz -
Subject digest:
e8b825b839bc0c6718bab6f3f61c75bc5de80f327643e40100921c560f882e67 - Sigstore transparency entry: 1292016282
- Sigstore integration time:
-
Permalink:
imparcialista/codehealthanalyzer@c89fc12c2722d831fdefa96d6b04f97f162c61c1 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/imparcialista
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
auto-tag-from-version.yml@c89fc12c2722d831fdefa96d6b04f97f162c61c1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codehealthanalyzer-1.2.6-py3-none-any.whl.
File metadata
- Download URL: codehealthanalyzer-1.2.6-py3-none-any.whl
- Upload date:
- Size: 52.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8885e17b9562c50975e03a307a73a2432009aa142f93937eb7b2d33eaa57d3c9
|
|
| MD5 |
8df325af4f5d8b39a387c4f6c6459e15
|
|
| BLAKE2b-256 |
40b36b382db011a085c9e272e183038ceadb9573e5231f1b66aae0970b001185
|
Provenance
The following attestation bundles were made for codehealthanalyzer-1.2.6-py3-none-any.whl:
Publisher:
auto-tag-from-version.yml on imparcialista/codehealthanalyzer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codehealthanalyzer-1.2.6-py3-none-any.whl -
Subject digest:
8885e17b9562c50975e03a307a73a2432009aa142f93937eb7b2d33eaa57d3c9 - Sigstore transparency entry: 1292016361
- Sigstore integration time:
-
Permalink:
imparcialista/codehealthanalyzer@c89fc12c2722d831fdefa96d6b04f97f162c61c1 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/imparcialista
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
auto-tag-from-version.yml@c89fc12c2722d831fdefa96d6b04f97f162c61c1 -
Trigger Event:
push
-
Statement type: