# Python Ruff Linter

> Ensure Python code follows industry standards using Ruff linter with linting-workflow framework Use when this capability is needed.

- Skill: `tomevault-io/python-ruff-linter` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/python-ruff-linter`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/python-ruff-linter/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Productivity
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/python-ruff-linter

---


## What I do

I implement Python-specific Ruff linting by extending the `linting-workflow` framework:

1. **Detect Python Environment**: Identify Python project (Poetry or pip)
2. **Detect Ruff Linter**: Check if Ruff is installed and configured
3. **Delegate to Linting Workflow**: Use `linting-workflow` for core linting functionality
4. **Provide Python-Specific Guidance**: Help interpret Ruff error codes (F401, E501, etc.)
5. **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:
```bash
# Check for Python files
ls *.py 2>/dev/null

# Check for Python project files
[ -f pyproject.toml ] || [ -f requirements.txt ] || [ -f setup.py ]
```

### Step 2: Detect Ruff Configuration

Check for Ruff in project:
```bash
# Check pyproject.toml for Ruff
grep -q "ruff" pyproject.toml || grep -q "ruff" requirements.txt
```

### Step 3: Detect Poetry

Check if Poetry is installed:
```bash
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>
   ```

5. **Apply Fix**:
   <Action to take>
```

## 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:
```bash
# With Poetry
poetry add --group dev ruff

# With pip
pip install ruff
```

### Ruff Configuration Issues

**Issue**: Ruff doesn't follow project style

**Solution**: Update `pyproject.toml`:
```toml
[tool.ruff]
line-length = 88
target-version = "py311"

[tool.ruff.lint]
select = ["E", "F", "W"]
ignore = []
```

## Troubleshooting Checklist

Before linting:
- [ ] Python project is identified
- [ ] Ruff is installed
- [ ] Poetry is detected (if applicable)
- [ ] Configuration files exist

After linting:
- [ ] Linting completed successfully
- [ ] Auto-fix applied (if errors found)
- [ ] Errors are categorized and displayed
- [ ] User receives Python-specific guidance
- [ ] Linting is re-run after fixes

## Related Commands

```bash
# Poetry + Ruff
poetry run ruff check .
poetry run ruff check . --fix
poetry add --group dev ruff

# Direct Ruff
ruff check .
ruff check . --fix

# Ruff checks
ruff check --select E,F,W .
ruff check --ignore E501 .
```

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/darellchua2) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-13 -->

