Tasks: Ruff Integration for Python Linting & Formatting¶
Feature Overview¶
Replace flake8 (linter) and black (formatter) with ruff for Python file processing in linthis, providing 10-100x speed improvements.
Status: COMPLETED¶
All tasks have been implemented.
User Stories¶
| ID | Priority | Story | Status |
|---|---|---|---|
| US1 | P1 | As a developer, I want Python linting to use ruff instead of flake8 so that lint checks are faster | Done |
| US2 | P1 | As a developer, I want Python formatting to use ruff instead of black so that formatting is faster | Done |
| US3 | P2 | As a developer, I want ruff configuration generated by --init-configs so that I can customize rules | Done |
| US4 | P3 | As a developer, I want to benchmark ruff vs flake8+black so that I can see the speed improvement | Done |
Phase 1: Setup¶
- [x] T001 Verify ruff is installed and accessible via
ruff --version - [x] T002 Review existing Python checker implementation in
src/checkers/python.rs - [x] T003 Review existing Python formatter implementation in
src/formatters/python.rs
Phase 2: Foundational - Data Types for Ruff JSON Parsing¶
- [x] T004 [P] Add RuffIssue struct for JSON deserialization in
src/checkers/python.rs - [x] T005 [P] Add RuffLocation struct for JSON deserialization in
src/checkers/python.rs - [x] T006 [P] Add RuffFix and RuffEdit structs for JSON deserialization in
src/checkers/python.rs
Phase 3: User Story 1 - Python Linting with Ruff¶
Goal: Replace flake8 with ruff check for Python linting
Test Criteria: cargo test passes, linthis correctly detects Python lint issues using ruff
Tasks¶
- [x] T007 [US1] Update
name()method to return "ruff" insrc/checkers/python.rs - [x] T008 [US1] Update
is_available()to check for ruff binary insrc/checkers/python.rs - [x] T009 [US1] Implement
parse_ruff_json_output()method to parse ruff JSON output insrc/checkers/python.rs - [x] T010 [US1] Implement severity mapping from ruff codes (E/F->Error, W/N/B/S/A->Warning, others->Info) in
src/checkers/python.rs - [x] T011 [US1] Update
check()method to runruff check --output-format jsoninsrc/checkers/python.rs - [x] T012 [US1] Remove old
parse_flake8_output()andparse_flake8_line()methods insrc/checkers/python.rs - [x] T013 [US1] Update module docstring from "pylint/flake8" to "ruff" in
src/checkers/python.rs - [x] T014 [US1] Manual test: run
cargo run -- --check-only --lang pythonon Python files with issues
Phase 4: User Story 2 - Python Formatting with Ruff¶
Goal: Replace black with ruff format for Python formatting
Test Criteria: cargo test passes, linthis correctly formats Python files using ruff
Tasks¶
- [x] T015 [US2] Update
name()method to return "ruff" insrc/formatters/python.rs - [x] T016 [US2] Update
is_available()to check for ruff binary insrc/formatters/python.rs - [x] T017 [US2] Update
format()method to runruff formatinsrc/formatters/python.rs - [x] T018 [US2] Update
check()method to runruff format --checkinsrc/formatters/python.rs - [x] T019 [US2] Remove hard-coded
--line-length 120argument (use ruff config instead) insrc/formatters/python.rs - [x] T020 [US2] Update module docstring from "black" to "ruff" in
src/formatters/python.rs - [x] T021 [US2] Manual test: run
cargo run -- --format-only --lang pythonon unformatted Python files
Phase 5: User Story 3 - Configuration Updates¶
Goal: Update default config and --init-configs for ruff
Test Criteria: linthis --init-configs generates valid ruff configuration
Tasks¶
- [x] T022 [US3] Add [python] section with ruff settings in
defaults/config.toml - [x] T023 [US3] Update
generate_tool_configs()to create ruff.toml instead of .flake8 insrc/main.rs - [x] T024 [US3] Update
generate_tool_configs()to update pyproject.toml [tool.ruff] section insrc/main.rs - [x] T025 [US3] Remove .flake8 generation from
generate_tool_configs()insrc/main.rs - [x] T026 [US3] Manual test: run
cargo run -- --init-configsand verify ruff.toml is created
Phase 6: User Story 4 - Benchmark Mode¶
Goal: Add --benchmark flag to compare ruff vs flake8+black performance
Test Criteria: linthis --benchmark --lang python outputs comparison table
Tasks¶
- [x] T027 [US4] Add
--benchmarkCLI flag insrc/main.rs - [x] T028 [US4] Create
src/benchmark.rsmodule for benchmark logic - [x] T029 [US4] Implement
run_flake8_benchmark()to time flake8 execution insrc/benchmark.rs - [x] T030 [US4] Implement
run_black_benchmark()to time black execution insrc/benchmark.rs - [x] T031 [US4] Implement
run_ruff_check_benchmark()to time ruff check execution insrc/benchmark.rs - [x] T032 [US4] Implement
run_ruff_format_benchmark()to time ruff format execution insrc/benchmark.rs - [x] T033 [US4] Implement
format_benchmark_table()to output ASCII table comparison insrc/benchmark.rs - [x] T034 [US4] Add benchmark module to
src/lib.rs - [x] T035 [US4] Wire --benchmark flag to benchmark execution in
src/main.rs - [x] T036 [US4] Manual test: run
cargo run -- --benchmark --lang pythonon a Python project
Phase 7: Polish & Documentation¶
- [x] T037 Update README.md to document ruff as the Python linter/formatter
- [x] T038 Add migration notes for users switching from flake8+black to ruff in README.md
- [x] T039 Run
cargo clippyand fix any warnings - [x] T040 Run
cargo testto verify all tests pass - [x] T041 Final manual test: run full linthis workflow on a Python project
Summary¶
| Metric | Count | Status |
|---|---|---|
| Total Tasks | 41 | Completed |
| Phase 1 (Setup) | 3 | Completed |
| Phase 2 (Foundational) | 3 | Completed |
| Phase 3 (US1 - Linting) | 8 | Completed |
| Phase 4 (US2 - Formatting) | 7 | Completed |
| Phase 5 (US3 - Config) | 5 | Completed |
| Phase 6 (US4 - Benchmark) | 10 | Completed |
| Phase 7 (Polish) | 5 | Completed |
Files Modified¶
src/checkers/python.rs- Replaced flake8 with ruff checksrc/formatters/python.rs- Replaced black with ruff formatsrc/benchmark.rs- New module for benchmark comparisonsrc/lib.rs- Added benchmark modulesrc/main.rs- Added --benchmark flag and ruff config generationdefaults/config.toml- Added Python/ruff configurationREADME.md- Updated documentationsrc/utils/walker.rs- Fixed clippy warning