Skip to content

refactor(backend): add ruff and apply lint autofixes and formatting - #112

Merged
klin2686 merged 10 commits into
mainfrom
refactor/backend-ruff
Oct 13, 2026
Merged

klin2686 merged 10 commits into
mainfrom
refactor/backend-ruff

Conversation

@klin2686

Copy link
Copy Markdown
Collaborator

Summary

Adds Ruff to the backend and applies it once across the codebase, so formatting and import order are enforced from here on.

  1. Ruff config, a pre-commit hook, and a CI check.
  2. One-time safe autofixes and a full reformat, kept in their own commits and listed in .git-blame-ignore-revs.
  3. Small cleanups: pytest config moved into pyproject.toml, backend design docs moved into backend/docs/.

Merge with a merge commit, not squash or rebase. .git-blame-ignore-revs lists two commit SHAs that have to survive the merge.

What changed

Backend

Tooling

  • Adds ruff as a dev dependency, configured in pyproject.toml (line length 100; rules E4, E7, E9, F, I, UP, B).
  • Ignores E712, because its fix (not Column) would break SQLAlchemy == True/False filters.
  • Marks FastAPI's Depends/Query/Body/Path as safe in default arguments, so B008 only flags real cases.
  • Treats alembic as third-party, since the local alembic/ folder would otherwise make Ruff sort it as first-party.
  • New Alembic revisions are auto-fixed and formatted on write (post_write_hooks in alembic.ini).
  • script.py.mako uses str | None and collections.abc.Sequence.
  • version_path_separator renamed to path_separator (the old name is deprecated in Alembic).
  • pytest config moved from pytest.ini into [tool.pytest]; the redundant root conftest.py is removed.

Mechanical changes

  • Safe Ruff autofixes: import sorting, Optional/Union to X | None, typing to collections.abc, timezone.utc to UTC, 56 unused imports removed. (16db72d4)
  • ruff format across the backend, including migrations. (3c6811f5)
  • No migration changes: the 96 revision and down-revision lines are identical to main.

Tests

  • Removes a second, identical copy of test_event_shifts_come_back_in_time_order; the first copy was being overridden and never ran.

Docs

  • Six design docs moved from backend/ into backend/docs/, with every reference in code comments updated.
  • Removes Alembic's boilerplate alembic/README.

Repo

  • .githooks/pre-commit formats staged backend files and sorts their imports.
  • A file with unstaged changes is checked, not fixed, and blocks the commit if its staged version needs fixing.
  • CI (pytest.yml) runs ruff format --check and ruff check --select I before pytest.
  • .git-blame-ignore-revs lists the autofix and format commits.
  • CONTRIBUTING documents the one-time setup: git config core.hooksPath .githooks and git config blame.ignoreRevsFile .git-blame-ignore-revs.

Frontend

  • Comment-only: six references updated to the new backend/docs/ paths.

Out of scope / follow up

  • The remaining 164 lint findings (mainly B904, B008 on Depends(require_permission(...)), and B023), left for a follow-up PR.
  • CI enforces formatting and import order only; full ruff check linting waits until those are fixed.
  • Comment cleanup and moving models.py to Mapped[] style.

Test plan

  • pytest passes locally
  • Migration included for every model change (no model changes)

Automated

  • All 1,734 tests collect; test_sheets_service, test_sheets, test_form_validation and test_auth pass after the autofixes (291 tests).
  • Every changed file in the format commit has the same AST as before, apart from whitespace inside docstrings.
  • ruff format --check and ruff check --select I pass on the branch.

Manual

  • Generated a throwaway Alembic revision; the post-write hook formatted it and kept its op/sa imports.
  • Ran the pre-commit hook against a scratch file in five staging states (fully staged, partly staged clean, partly staged unformatted, deleted locally, nothing staged); each passed or blocked as expected.

@railway-app

railway-app Bot commented Oct 13, 2026

Copy link
Copy Markdown

This PR was not deployed automatically as @klin2686 does not have access to the Railway project.

In order to get automatic PR deploys, please add @klin2686 to your workspace on Railway.

@vercel

vercel Bot commented Oct 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nexus Ready Ready Preview Oct 13, 2026 8:22am UTC

@klin2686
klin2686 merged commit 6fb37c3 into main Oct 13, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — 2f319523 Deployed Oct 13, 2026 by vercel[bot]
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