Last Updated: November 24, 2025
Auto-formatting and linting setup for minimal manual review.
# Activate AutoTrader conda environment
conda activate AutoTrader
# Install pre-commit
pip install pre-commit
# Install the git hooks
pre-commit install
# Test the setup
pre-commit run --all-filesWhat this does:
- Automatically formats code before every commit
- Fixes markdown linting issues (MD022, MD032)
- Sorts Python imports
- Removes trailing whitespace
- Fixes end-of-file formatting
- Runs security scans with Bandit
Already configured! When you push to:
feature/**branchesdevelopmentmain
GitHub Actions will:
- Auto-fix any issues you missed locally
- Commit and push the fixes automatically
- Add
[skip ci]to prevent infinite loops
Runs before every commit:
git commit -m "your message"
# ↓
# Auto-fixes run automatically:
# ✓ Ruff lint auto-fixes, including import order (rule I)
# ✓ Ruff formatting (Black-compatible, line length 100)
# ✓ Markdown linting
# ✓ Whitespace cleanup
# ✓ Bandit security scan
# ↓
# Files fixed and staged automatically
# ↓
# Commit completes with fixed filesBypass if needed:
git commit --no-verify -m "urgent fix"Runs after you push:
git push
# ↓
# GitHub Actions triggered
# ↓
# All formatters run on entire codebase
# ↓
# If changes needed:
# - Commit created: "style: Auto-fix code quality issues [skip ci]"
# - Changes pushed automatically
# ↓
# Your local branch gets behind by 1 commit
# ↓
# Next pull: git pull (fast-forward merge)Important: After pushing, wait 2-3 minutes then:
git pull # Pull the auto-fix commitDefines which auto-fixes run locally:
- ruff-check: linter with auto-fix, including import order (rule I); replaces isort (#603)
- ruff-format: Black-compatible formatter (line length 100); replaces black (#603)
- trailing-whitespace: Removes trailing spaces
- end-of-file-fixer: Ensures newline at EOF
- check-yaml/json: Validates config files
- bandit: Security vulnerability scanning
The workflows run ruff through these hooks, so the rev here is the version CI uses. Keep the
ruff== pin in pyproject.toml and requirements-dev.txt equal to it for manual runs. The
hooks need pre-commit 3.2 or newer.
Markdown rules:
- MD032: Blank lines around lists ✅
- MD022: Blank lines around headings ✅
- MD013: Line length ❌ (disabled for docs)
- MD033: Allow HTML tags for special formatting
Tool configuration:
- Ruff: lint rules, import order (
[tool.ruff.lint.isort],srcandconfigas local folders) and formatting; line length 100, Python 3.12 target; Markdown is excluded - pytest: Test configuration, coverage settings
- mypy: Type checking rules
- bandit: Security scanning exclusions
Triggers: Push to main, development, feature/**
Actions:
- Runs the
ruff-checkandruff-formatpre-commit hooks (the version pinned in.pre-commit-config.yaml) on the tracked Python files insrc/,tests/,scripts/,config_defaults/andmain.py - Auto-commits and pushes fixes if changes detected Time: ~2-3 minutes
Triggers: Pull requests to main, development
Actions:
- Non-blocking checks (warnings only)
- Runs ruff (the pinned version; findings as PR annotations), the
ruff-formatcheck, pylint, mypy - Security scanning with bandit
- Code complexity analysis with radon Time: ~3-5 minutes
# Make changes
echo "new code" >> src/new_file.py
# Commit (pre-commit auto-fixes run)
git commit -am "feat: Add new feature"
# [INFO] ruff check...............................................Passed
# [INFO] ruff format..............................................Passed
# Push
git push
# GitHub Actions runs, no additional fixes needed# Make changes with bad formatting
echo "x=1" >> src/bad_format.py
# Commit triggers auto-fix
git commit -am "feat: Add feature"
# [INFO] ruff format..............................................Failed
# - hook id: ruff-format
# - files were modified by this hook
# 1 file reformatted
# Files auto-fixed and staged
# Commit again (now passes)
git commit -am "feat: Add feature"
# [INFO] ruff format..............................................Passed
git push# Urgent commit, skip local checks
git commit --no-verify -m "fix: Critical bug"
# Push
git push
# GitHub Actions detects issues
# Auto-fix commit pushed: "style: Auto-fix code quality issues [skip ci]"
# Pull the fix
git pull
# Fast-forward merge, now in sync# Update to latest versions
pre-commit autoupdate
# Run updated hooks
pre-commit run --all-filesEdit .pre-commit-config.yaml and comment out:
# - repo: https://github.com/DavidAnson/markdownlint-cli2
# rev: v0.12.1
# hooks:
# - id: markdownlint-cli2# Dry run (no changes)
pre-commit run --all-files --verbose# Only run on changed files (default)
git commit -am "message"
# Skip if urgent
git commit --no-verify -m "urgent"# Pull before pushing
git pull --rebase
git pushAdd [skip ci] to your commit message:
git commit -m "wip: Work in progress [skip ci]"If mypy or other tools fail due to missing imports:
# Install project in editable mode
pip install -e .
# Re-run hooks
pre-commit run --all-files- Free tier: 2,000 minutes/month
- Auto-fix workflow: ~2-3 min per push
- Quality check workflow: ~3-5 min per PR
- Estimated usage: ~10-20 pushes/week = 50-100 min/month
- Verdict: Well within free tier ✅
- Pre-commit hooks: ~5-15 seconds per commit
- Impact: Minimal, runs in background
- Verdict: Negligible ✅
| Situation | Use Pre-Commit | Use Auto-Fix on Push | Use --no-verify |
|---|---|---|---|
| Normal development | ✅ Yes | ✅ Yes (safety net) | ❌ No |
| Urgent hotfix | ✅ Yes | ✅ Yes | |
| WIP commits | ✅ Yes | ❌ No ([skip ci]) |
|
| Large refactoring | ✅ Yes | ✅ Yes | ❌ No |
| Documentation only | ✅ Yes | ✅ Yes | ❌ No |
# Only run the formatter
pre-commit run ruff-format --all-files
# Only run the linter
pre-commit run ruff-check --all-files
# Only run security scan
pre-commit run bandit --all-filesEdit .pre-commit-config.yaml:
- repo: local
hooks:
- id: check-api-keys
name: Check for hardcoded API keys
entry: bash -c 'grep -r "API_KEY.*=" src/ && exit 1 || exit 0'
language: systemEdit pyproject.toml:
[tool.ruff]
line-length = 120 # Change from 100 to 120 (lint and format)Use the OptionsCommander conda environment (conda activate is broken on the main host, so
call its Python directly):
PY=~/miniconda3/envs/OptionsCommander/bin/python
$PY -m pip install -e ".[dev]" # project + dev dependencies from pyproject.toml
$PY -m pre_commit install # the git hook then runs this env's pre-commit (3.2+)Trading configuration files in config_defaults/ are formatted by ruff:
trading_config.pymarket_hours.yamlcli_messages.yaml
The src/deprecated/ directory is excluded from:
- Pre-commit hooks
- Linting checks
- Test coverage
This preserves legacy V0-V4 sentiment framework for reference.
- Install pre-commit:
conda activate AutoTrader && pip install -r requirements-dev.txt - Setup hooks:
pre-commit install - Test it:
pre-commit run --all-files - Make a commit: Watch it auto-fix
- Push to GitHub: Watch Actions auto-fix remotely
- Pull changes:
git pullafter Actions complete
- Codebase Structure
- Project Status
- CLAUDE.md - AI assistant instructions
Last Updated: November 24, 2025