Skip to content

Latest commit

 

History

History
84 lines (73 loc) · 2.59 KB

File metadata and controls

84 lines (73 loc) · 2.59 KB

CodeReviewGPT - Solution

Overview

This solution implements a Python CLI that blends static analysis with optional LLM review. It scans a file or directory, runs local analyzers when available, and produces a report in terminal, markdown, json, or html formats.

What Was Built

  • A modular Python package under src/codereviewgpt/.
  • CLI entrypoint with analyze and config-example commands.
  • Static analysis integration via pylint, bandit, flake8, and radon (best-effort).
  • Internal checks for long files/functions, TODO tags, missing docstrings, and syntax errors.
  • LLM client for Claude or OpenAI with JSON response parsing.
  • Report formatters for terminal, markdown, json, and html.
  • Lightweight tests covering config, formatter JSON, and internal analyzer checks.

Project Structure

code-review-gpt/
??? src/
?   ??? codereviewgpt/
?       ??? __init__.py
?       ??? analyzer.py
?       ??? cli.py
?       ??? config.py
?       ??? formatters.py
?       ??? llm_client.py
?       ??? models.py
??? tests/
?   ??? test_analyzer.py
?   ??? test_config.py
?   ??? test_formatters.py
??? requirements.txt
??? setup.py
??? README.md

How It Works

  1. CLI parses arguments and loads configuration.
  2. Analyzer runs internal checks and external static tools.
  3. LLM client is called only if enabled and a key exists.
  4. Formatter renders a report in the requested output format.

Key Design Decisions

  • Use best-effort integrations so the tool still works without every static tool installed.
  • Keep LLM optional and guarded by presence of API keys.
  • Return JSON from LLM so results can be parsed and merged.
  • Provide simple defaults with a JSON config override path.

Example Usage

# Analyze a directory
codereview analyze .

# Markdown report
codereview analyze . --format markdown --output report.md

# JSON report without LLM
codereview analyze script.py --format json --no-llm

# Generate a config file
codereview config-example > config.json

Configuration

The CLI can load a JSON config file. Example fields:

{
  "language": "python",
  "severity_threshold": "LOW",
  "output_format": "terminal",
  "provider": "claude",
  "llm_enabled": true,
  "max_lines_per_chunk": 500,
  "max_file_lines": 800,
  "max_function_lines": 120,
  "todo_tags": ["TODO", "FIXME", "HACK"],
  "file_exclude_globs": [".venv", "__pycache__", "node_modules"],
  "tool_paths": {}
}

Notes

  • Install pylint, bandit, flake8, and radon for fuller static analysis.
  • Set OPENAI_API_KEY or ANTHROPIC_API_KEY to enable LLM calls.
  • Use --no-llm to avoid API calls entirely.