Skip to main content

Static Analysis

Goblin runs static analysis before the REVIEW stage to catch issues automatically.

Tools

Ruff

Fast Python linter:

  • Unused imports
  • Undefined variables
  • Style violations
  • Common errors

mypy

Static type checker:

  • Type mismatches
  • Missing annotations
  • Incompatible assignments

Configuration

# Enable static analysis (default: true)
goblin pipeline config -p PROJECT --config static_analysis_enabled=true

# Enable mypy (default: true)
goblin pipeline config -p PROJECT --config static_analysis_mypy=true

Execution

Run automatically before spawning Reviewer:

# In pipeline_runner.py
static_analysis_context = self._run_static_analysis(pipeline)
prompt = static_analysis_context + "\n\n" + review_prompt

Output Format

## Static Analysis Results

**Summary**: 2 error(s), 3 warning(s)

### Ruff Results

#### `app/models.py`
- Line 10: [F401] 'os' imported but unused
- Line 25: [E501] Line too long (120 > 100)

#### `app/views.py`
- Line 45: [W503] line break before binary operator

### mypy Results

#### `app/utils.py`
- Line 30: error: Incompatible types in assignment
- Line 55: error: Missing return statement

---

**Your focus areas** (tools cannot check these):
- Logic correctness and edge cases
- Breaking changes to existing functionality
- Security implications

Running Manually

# Ruff
ruff check goblin/ --output-format json

# mypy
mypy goblin/ --json-output

# Combined
python -m goblin.core.static_analysis /path/to/worktree

API

from goblin.core.static_analysis import (
run_ruff,
run_mypy,
run_static_analysis,
format_for_review_prompt,
)

# Run all
results = run_static_analysis(worktree_path)

# Format for prompt
context = format_for_review_prompt(results)

Result Structure

@dataclass
class StaticAnalysisResult:
ruff_findings: list[Finding]
mypy_findings: list[Finding]
total_errors: int
total_warnings: int

@dataclass
class Finding:
file: str
line: int
column: int
code: str
message: str
severity: str # error, warning

Reviewer Focus

Static analysis handles mechanical checks, so Reviewer focuses on:

  • Logic correctness
  • Edge cases
  • Security implications
  • Breaking changes
  • Architectural concerns

Limitations

Static analysis cannot detect:

  • Runtime behavior
  • Business logic errors
  • Integration issues
  • Performance problems
  • Security vulnerabilities (some)

The Reviewer's checklist covers these areas.