| name | python-ruff-linter |
| description | Ensure Python code follows industry standards using Ruff linter with linting-workflow framework Use when this capability is needed. |
| metadata | {"author":"darellchua2"} |
What I do
I implement Python-specific Ruff linting by extending the linting-workflow framework:
- Detect Python Environment: Identify Python project (Poetry or pip)
- Detect Ruff Linter: Check if Ruff is installed and configured
- Delegate to Linting Workflow: Use
linting-workflow for core linting functionality
- Provide Python-Specific Guidance: Help interpret Ruff error codes (F401, E501, etc.)
- Ensure PEP 8 Compliance: Guide on Python style standards
When to use me
Use this workflow when:
- Writing or modifying Python code that needs to follow industry standards
- Before committing Python changes to ensure code quality
- When you see Ruff linting errors and need help fixing them
- Setting up a new Python project with proper linting configuration
- You want to ensure code quality in automated workflows
Framework: This skill extends linting-workflow for generic linting, adding Python-specific Ruff guidance.
Steps
Step 1: Detect Python Environment
Verify this is a Python project:
ls *.py 2>/dev/null
[ -f pyproject.toml ] || [ -f requirements.txt ] || [ -f setup.py ]
Step 2: Detect Ruff Configuration
Check for Ruff in project:
grep -q "ruff" pyproject.toml || grep -q "ruff" requirements.txt
Step 3: Detect Poetry
Check if Poetry is installed:
poetry --version 2>/dev/null
Step 4: Delegate to Linting Workflow
Use linting-workflow framework for:
- Language detection (Python)
- Linter detection (Ruff)
- Package manager detection (Poetry or pip)
- Running linting with appropriate commands
- Auto-fix application
- Error resolution guidance
- Verification and re-running
Step 5: Python-Specific Ruff Error Guidance
Common Ruff Error Codes:
| Error Code | Description | Common Fix |
|---|
| F401 | Unused imports | Remove or use import |
| F841 | Unused variables | Remove or use variable |
| E501 | Line too long (>default 88) | Break into multiple lines |
| E722 | Do not use bare except | Use specific exception types |
| W291 | Trailing whitespace | Remove trailing spaces |
| E731 | Do not assign a lambda expression | Use def instead of lambda assignment |
| F821 | Undefined name | Define the name or add missing import |
| E231 | Whitespace after ':' | Fix whitespace around punctuation |
| I001 | Import block is unsorted | Run ruff check --select I001 --fix |
| S101 | Use of assert detected | Use pytest.raises or remove assert |
| N801 | Class name should use CapWords | Rename class to CapWords convention |
| SIM | Code can be simplified | Apply suggested simplification |
Error Resolution Template:
For each Ruff error found:
1. **File**: <file>
Line: <line>
Error: <error message>
Code: <F401 | E501 | etc.>
2. **Ruff Rule Explanation**:
<Description of what Ruff is checking>
3. **Recommended Fix**:
<Step-by-step fix instructions>
4. **Example**:
```python
# Before (incorrect)
<code>
# After (corrected)
<code>
- Apply Fix:
## Best Practices
**Refer to `linting-workflow` for general linting best practices.**
Python-specific best practices:
- **PEP 8**: Follow Python Enhancement Proposal 8 style guide
- **Type Hints**: Use type hints for better code quality and IDE support
- **Docstrings**: Follow PEP 257 for docstring conventions
- **Import Order**: Use `ruff check --select I001` or configure `isort`
- **Code Organization**: Separate concerns into modules/packages
- **Virtual Environments**: Use Poetry for dependency management and isolation
- **Ruff Configuration**: Tailor Ruff settings for your project needs
## Common Ruff Issues
### Poetry Not Detected
**Issue**: Poetry is installed but `linting-workflow` doesn't detect it
**Solution**: Ensure Poetry is detected:
```bash
poetry --version
Ruff Not Installed
Issue: Ruff is not available
Solution: Install Ruff:
poetry add --group dev ruff
pip install ruff
Ruff Configuration Issues
Issue: Ruff doesn't follow project style
Solution: Update pyproject.toml:
[tool.ruff]
line-length = 88
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "W"]
ignore = []
Troubleshooting Checklist
Before linting:
After linting:
Related Commands
poetry run ruff check .
poetry run ruff check . --fix
poetry add --group dev ruff
ruff check .
ruff check . --fix
ruff check --select E,F,W .
ruff check --ignore E501 .
Converted and distributed by TomeVault — claim your Tome and manage your conversions.