1.8 KiB
1.8 KiB
Python Cleanup Skill
Clean up Python code by formatting, fixing lint issues, removing unused imports, and identifying dead code.
Usage
Invoke with /python-cleanup followed by an optional path or scope:
/python-cleanup- Clean up changed files (git diff)/python-cleanup src/- Clean up a specific directory/python-cleanup src/main.py- Clean up a specific file
Workflow
Step 1: Identify Target Files
If no path specified, find Python files with uncommitted changes:
git diff --name-only --diff-filter=ACMR HEAD | grep '\.py$'
If a path is specified, use that path directly.
Step 2: Format Code
Run ruff formatter to fix code style:
ruff format <target>
Step 3: Fix Lint Issues
Auto-fix all fixable lint issues including unused imports:
ruff check --fix --unsafe-fixes <target>
Key rules this fixes:
F401- Unused imports (removes them)F841- Unused variablesI001- Import sortingUP- Python upgrade suggestionsB- Bugbear issues
Step 4: Report Remaining Issues
Show any issues that couldn't be auto-fixed:
ruff check <target>
Step 5: Identify Dead Code (Optional)
Use vulture to find potentially unused code:
vulture <target> --min-confidence 80
If vulture is not installed, skip this step and note it in the summary.
Step 6: Summary
Provide a summary of:
- Files processed
- Issues auto-fixed (count by category)
- Remaining issues that need manual review
- Potential dead code identified (if vulture available)
Configuration
This skill respects project-level pyproject.toml or ruff.toml configuration if present.
Dependencies
ruff(required) - Install withuv add rufforpip install ruffvulture(optional) - Install withuv add vultureorpip install vulture