Skip to main content

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, TemplatesAnalyzer e ErrorsAnalyzer
  • CLI com os comandos analyze, violations, templates, errors, score, info, dashboard, format e lint
  • relatórios em json, html, markdown e csv
  • 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

codehealthanalyzer analyze .
codehealthanalyzer analyze . --format all --output reports
codehealthanalyzer violations . --format csv
codehealthanalyzer templates . --config config.json
codehealthanalyzer errors . --no-json --format markdown
codehealthanalyzer 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 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
}

Campos suportados:

  • limits: sobrescreve limites de tamanho
  • target_dir: diretório analisado pelo Ruff
  • templates_dir: string ou lista de diretórios de templates
  • exclude_dirs: string ou lista de diretórios extras a ignorar
  • ruff_fix: roda ruff check --fix antes da coleta
  • no_default_excludes: desabilita as exclusões padrão

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 ruff estar 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codehealthanalyzer-1.2.3.tar.gz (60.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codehealthanalyzer-1.2.3-py3-none-any.whl (51.9 kB view details)

Uploaded Python 3

File details

Details for the file codehealthanalyzer-1.2.3.tar.gz.

File metadata

  • Download URL: codehealthanalyzer-1.2.3.tar.gz
  • Upload date:
  • Size: 60.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codehealthanalyzer-1.2.3.tar.gz
Algorithm Hash digest
SHA256 5d0b98f5a091c104af747d14faf407218e10d64a8c39da9e6d0d8b44473a7b72
MD5 545d5725c0b8d6641ac7581a5dd54476
BLAKE2b-256 f10dc79b1d04e8080e33ed07d7fc99df30284bcc74f8cb020f21aa41c72eaa66

See more details on using hashes here.

Provenance

The following attestation bundles were made for codehealthanalyzer-1.2.3.tar.gz:

Publisher: python-publish.yml on imparcialista/codehealthanalyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codehealthanalyzer-1.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for codehealthanalyzer-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 03e532774cb0d4f78e1ffdd19832fd9e8d9c6ca4d3a62e738a4f84d65bcba82a
MD5 63a2599c69cfa639621f77af303f49f2
BLAKE2b-256 a5a8cef558c7351c6118a2abd85b941dc0465144d1b1932b70af90c1a9d302cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for codehealthanalyzer-1.2.3-py3-none-any.whl:

Publisher: python-publish.yml on imparcialista/codehealthanalyzer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page