Skip to content

chore: enforce repo-wide Ruff checks in CI - #12

Merged
iktakahiro merged 1 commit into
mainfrom
chore/ruff-ci-and-lint-cleanup
Apr 10, 2026
Merged

chore: enforce repo-wide Ruff checks in CI#12
iktakahiro merged 1 commit into
mainfrom
chore/ruff-ci-and-lint-cleanup

Conversation

@iktakahiro

@iktakahiro iktakahiro commented Apr 10, 2026

Copy link
Copy Markdown
Owner

Summary

This PR enables repository-wide ruff check . enforcement in CI and removes the existing Ruff violations that were preventing that from being a reliable quality gate.

The original motivation came from review feedback: the SQLAlchemy-related files touched in the previous work were already Ruff-clean, but the repository as a whole still had outstanding lint findings. Instead of documenting that exception and leaving the gap in place, this change clears the backlog and makes Ruff part of the normal CI flow.

What changed

  • added a dedicated make lint target so Ruff can be run consistently in local development and CI
  • added a matching mise task for the same repository-wide lint command
  • updated the GitHub Actions workflow to run Ruff before the type check and test steps
  • fixed the remaining repository-wide Ruff findings rather than limiting checks to the recently touched files
  • applied the required cleanup across domain, use case, infrastructure, presentation, and test code

Implementation notes

Most of the cleanup is mechanical and intended to make the codebase compatible with the currently configured Ruff rule set:

  • modernized type annotations and import usage
  • removed unused imports and formatting issues
  • replaced hard-coded comparison values that Ruff flagged with named constants where appropriate
  • reduced route registration complexity by splitting the large FastAPI route registration method into smaller helper methods
  • simplified the Todo entity implementation so it remains lint-clean without introducing ignore rules

While doing that cleanup, I also aligned a couple of HTTP error branches with the corresponding use case behavior so the route handler continues to return the expected 400 responses for invalid lifecycle transitions.

Why this approach

The alternative would have been to keep CI scoped to only a subset of files or to add temporary exclusions. That would preserve the existing gap and make future enforcement harder.

By fixing the current backlog now and turning on repository-wide Ruff checks in CI, we get a straightforward rule going forward: new changes should keep the entire repository lint-clean.

Impact

  • CI now fails when new Ruff errors or warnings are introduced anywhere in the repository
  • local development now has an explicit make lint / mise run lint entry point
  • no intentional feature changes were introduced; the primary goal is quality-gate enforcement and lint debt removal

Validation

  • make format
  • make lint
  • make test

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for Todo API endpoints, including better validation for already-completed and not-started todo states.
  • Chores

    • Added linting infrastructure and modernized codebase type annotations to current Python standards.
    • Refactored code organization with improved constant definitions for validation messages and limits.
    • Cleaned up unused test imports.

@coderabbitai

coderabbitai Bot commented Apr 10, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b8df83f9-4383-4809-8d00-d56810a97879

📥 Commits

Reviewing files that changed from the base of the PR and between 56dd0ce and a557426.

📒 Files selected for processing (24)
  • .github/workflows/test.yaml
  • .mise.toml
  • Makefile
  • dddpy/domain/todo/entities/todo.py
  • dddpy/domain/todo/repositories/todo_repository.py
  • dddpy/domain/todo/value_objects/todo_description.py
  • dddpy/domain/todo/value_objects/todo_title.py
  • dddpy/infrastructure/di/injection.py
  • dddpy/infrastructure/sqlite/todo/todo_repository.py
  • dddpy/presentation/api/todo/handlers/todo_api_route_handler.py
  • dddpy/usecase/todo/__init__.py
  • dddpy/usecase/todo/create_todo_usecase.py
  • dddpy/usecase/todo/find_todos_usecase.py
  • dddpy/usecase/todo/update_todo_usecase.py
  • tests/domain/todo/entities/test_todo.py
  • tests/domain/todo/value_objects/test_todo_id.py
  • tests/domain/todo/value_objects/test_todo_status.py
  • tests/usecase/todo/test_complete_todo_usecase.py
  • tests/usecase/todo/test_create_todo_usecase.py
  • tests/usecase/todo/test_delete_todo_usecase.py
  • tests/usecase/todo/test_find_todo_by_id_usecase.py
  • tests/usecase/todo/test_find_todos_usecase.py
  • tests/usecase/todo/test_start_todo_usecase.py
  • tests/usecase/todo/test_update_todo_usecase.py

Walkthrough

This PR modernizes type hints to Python 3.10+ syntax (replacing Optional[X] with X | None and List[X] with list[X]), adds linting infrastructure across CI/build tools, refactors the Todo entity from a private-field class to a @dataclass, extracts validation constants, and reorganizes the API route handler into helper methods.

Changes

Cohort / File(s) Summary
CI/CD & Build Configuration
.github/workflows/test.yaml, .mise.toml, Makefile
Added lint task and workflow step that invokes ruff check . with configurable RUFF_FLAGS.
Type Hint Modernization
dddpy/domain/todo/repositories/todo_repository.py, dddpy/infrastructure/sqlite/todo/todo_repository.py, dddpy/usecase/todo/create_todo_usecase.py, dddpy/usecase/todo/find_todos_usecase.py, dddpy/usecase/todo/update_todo_usecase.py, dddpy/infrastructure/di/injection.py
Replaced Optional[X] with X | None, List[X] with list[X], and migrated Iterator import from typing to collections.abc.
Todo Entity Refactoring
dddpy/domain/todo/entities/todo.py
Converted Todo from class with private fields and property getters to @dataclass(eq=False) with public attributes; added explicit __hash__ method and extracted error message constant ALREADY_COMPLETED_ERROR_MESSAGE.
Value Object Constants
dddpy/domain/todo/value_objects/todo_title.py, dddpy/domain/todo/value_objects/todo_description.py
Extracted magic numbers and error strings into module-level constants (MAX_TITLE_LENGTH, TITLE_REQUIRED_ERROR_MESSAGE, MAX_DESCRIPTION_LENGTH, DESCRIPTION_TOO_LONG_ERROR_MESSAGE).
API Handler Refactoring
dddpy/presentation/api/todo/handlers/todo_api_route_handler.py
Refactored register_routes to delegate to six private helper methods; added _build_todo_description helper; updated error handling to catch TodoAlreadyCompletedError in start_todo and TodoNotStartedError in complete_todo; changed validation error conversion to use str(e).
Test Cleanup & Constants
tests/domain/todo/entities/test_todo.py, tests/domain/todo/value_objects/test_todo_id.py, tests/domain/todo/value_objects/test_todo_status.py, tests/usecase/todo/test_*.py
Removed unused imports (patch, datetime, pytest, Todo); introduced module-level constants for test assertions (UUID4_VERSION, EXPECTED_TODO_STATUS_COUNT); updated assertions to use constants instead of hardcoded literals.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • V2 #8 — Overlapping modifications to the same Todo domain entities, repositories, value objects, and infrastructure/usecase modules at the code level.

Poem

🐰 With linting now in guard and types so bright and clean,
Our dataclasses hop with modern syntax never seen!
Error messages as constants, helpers both small and neat,
From private hides to public light—refactoring complete! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/ruff-ci-and-lint-cleanup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@iktakahiro
iktakahiro marked this pull request as ready for review April 10, 2026 02:26
@iktakahiro
iktakahiro merged commit a6ffbd4 into main Apr 10, 2026
4 checks passed
@iktakahiro
iktakahiro deleted the chore/ruff-ci-and-lint-cleanup branch April 10, 2026 02:27
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