Skip to content

chore: migrate pre-commit + lint stack to ruff#153

Open
cmyui wants to merge 1 commit intomasterfrom
chore-ruff-migration
Open

chore: migrate pre-commit + lint stack to ruff#153
cmyui wants to merge 1 commit intomasterfrom
chore-ruff-migration

Conversation

@cmyui
Copy link
Copy Markdown
Member

@cmyui cmyui commented Apr 17, 2026

Summary

Replaces five pre-commit hooks (black, pyupgrade, reorder-python-imports, add-trailing-comma, blacken-docs) with ruff-check + ruff-format. Two orders of magnitude faster, single config file, no more in-fighting hooks.

Config

New `pyproject.toml` (project's first) with ruff config that keeps the existing style:

  • `F` / `I` / `UP` / `COM` rulesets cover what the old hooks did.
  • `COM812` disabled (conflicts with formatter).
  • `F401` disabled for now — codebase has ~16 real unused imports that predate ruff. Cleaning them up deserves its own PR rather than landing as churn here.
  • isort: `force-single-line = true` + `required-imports = ["from future import annotations"]` to mirror reorder-python-imports.
  • `docstring-code-format = true` replaces blacken-docs.

What ruff autofix changed

Small, mechanical: 2× `UP017` (`datetime.timezone.utc` → `datetime.UTC`), 1× `F541` (redundant `f""`), 4× `I001` (minor import reorderings). Net ~15 lines across 10 files.

Follow-ups I'd do next

  • Enable `F401` + remove the ~16 genuinely unused imports.
  • Rename `app/models/_init.py` (three underscores, typo) to `init.py`. Currently a dead barrel file; `app.models` works as an implicit namespace package by accident.
  • Drop `from future import annotations` entirely — the `required-imports` rule is the single place to remove it from now, and on Python 3.11+ it's cosmetic.

Test plan

  • `make utest` — 31 pass
  • `make itest` — 7 pass
  • `mypy .` clean
  • `pre-commit run --all-files` clean (two hooks instead of nine)

🤖 Generated with Claude Code

Replaces five separate hooks (black, pyupgrade, reorder-python-imports,
add-trailing-comma, blacken-docs) with ruff-check + ruff-format. Ruff
does the work of all five in one pass, two orders of magnitude faster,
with a single config file.

pyproject.toml added (the project's first) with ruff config that keeps
the existing style:

  - F/I/UP/COM rulesets cover what the old hooks covered. COM812 is
    disabled because it conflicts with ruff-format; F401 is disabled
    because the codebase has ~16 real unused imports that predate ruff
    — worth cleaning up in a follow-up rather than in this PR.
  - isort settings mirror reorder-python-imports: one import per line,
    required `from __future__ import annotations`.
  - docstring-code-format = true replaces blacken-docs.

Ruff's autofix applied small cleanups along the way (UP017
`timezone.utc` → `UTC`, F541 redundant f-strings, a few I001 import
reorderings). Net diff is ~15 lines across ten files. All tests still
green.

Follow-ups for future PRs:

  - Enable F401 + fix the ~16 genuinely unused imports.
  - Rename the accidentally-tri-underscored app/models/___init__.py to
    __init__.py (currently a dead barrel file; the package works as an
    implicit namespace).
  - Drop `from __future__ import annotations` altogether now that the
    required-imports rule lives in one place.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cmyui cmyui requested a review from infernalfire72 as a code owner April 17, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant