ruff-formatting
Python code formatting with ruff format. Fast, Black-compatible formatter. Use when formatting Python files, enforcing style, or checking format compliance.
What this skill does
# ruff Formatting
Expert knowledge for using `ruff format` as an extremely fast Python code formatter with Black compatibility.
## When to Use This Skill
| Use this skill when... | Use another tool instead when... |
|------------------------|----------------------------------|
| Formatting Python files | Linting for code issues (use ruff check) |
| Checking format compliance in CI | Type checking (use basedpyright) |
| Migrating from Black | Detecting dead code (use vulture/deadcode) |
| Setting up format-on-save | Running tests (use pytest) |
## Core Expertise
**ruff format Advantages**
- 10-30x faster than Black
- Drop-in Black replacement (99.9% compatible)
- Written in Rust for performance
- Supports Black's configuration options
- Format checking and diff preview
- Respects `.gitignore` automatically
## Basic Usage
### Simple Formatting
```bash
# Format current directory
ruff format
# Format specific files or directories
ruff format path/to/file.py
ruff format src/ tests/
# IMPORTANT: Pass directory as parameter to stay in repo root
ruff format services/orchestrator
```
### Format Checking
```bash
# Check if files are formatted (exit code 1 if not)
ruff format --check
# Show diff without modifying files
ruff format --diff
# Check specific files
ruff format --check src/ tests/
# Preview changes before applying
ruff format --diff services/orchestrator
ruff format services/orchestrator # Apply after review
```
### Selective Formatting
```bash
# Format only Python files
ruff format src/**/*.py
# Format excluding tests
ruff format --exclude tests/
# Format only changed files (git)
git diff --name-only --diff-filter=d | grep '\.py$' | xargs ruff format
# Format files in specific directory
ruff format src/core/ src/utils/
```
## Configuration
### pyproject.toml
```toml
[tool.ruff]
line-length = 88
target-version = "py39"
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = true
docstring-code-line-length = "dynamic"
exclude = [
"*.pyi",
"**/__pycache__",
"**/node_modules",
".venv",
]
```
### ruff.toml (standalone)
```toml
line-length = 88
[format]
quote-style = "single"
indent-style = "space"
skip-magic-trailing-comma = false
docstring-code-format = true
```
### Black Compatibility
```toml
[tool.ruff]
line-length = 88
indent-width = 4
target-version = "py39"
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
```
## Format Workflow
1. **Preview**: `ruff format --diff` (see changes)
2. **Check**: `ruff format --check` (CI validation)
3. **Apply**: `ruff format` (modify files)
4. **Verify**: `ruff format --check` (confirm)
## Best Practices
- Pass directory parameter directly: `ruff format src/`
- Preview changes first with `--diff`
- Use one formatter per project (ruff format replaces Black)
- Exclude generated files in `pyproject.toml`
- Keep pre-commit config in sync with formatter choice
- Enable `docstring-code-format` for better docs
## Agentic Optimizations
| Context | Command |
|---------|---------|
| Format directory | `ruff format src/` |
| Check formatting | `ruff format --check` |
| Show diff | `ruff format --diff` |
| CI check + diff | `ruff format --check --diff` |
| Format + lint | `ruff format && ruff check` |
| Format changed files | `git diff --name-only --diff-filter=d \| grep '\.py$' \| xargs ruff format` |
## Quick Reference
### Essential Commands
```bash
ruff format # Format current directory
ruff format path/to/dir # Format specific directory
ruff format --check # Check if formatted
ruff format --diff # Show formatting changes
ruff format file1.py file2.py # Format specific files
ruff format --exclude tests/ # Exclude directory
ruff format --line-length 100 # Override line length
```
### Format vs Check
| Command | Purpose | Exit Code | Modifies Files |
|---------|---------|-----------|----------------|
| `ruff format` | Format files | 0 | Yes |
| `ruff format --check` | Validate formatting | 1 if unformatted | No |
| `ruff format --diff` | Show changes | 0 | No |
| `ruff format --check --diff` | Validate + show | 1 if unformatted | No |
### Configuration Quick Start
**Minimal (Black-compatible)**
```toml
[tool.ruff]
line-length = 88
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
```
**Recommended**
```toml
[tool.ruff]
line-length = 88
target-version = "py311"
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
docstring-code-format = true
line-ending = "auto"
exclude = [
"*.pyi",
"migrations/**/*.py",
]
```
For detailed examples, advanced patterns, integration guides, and migration checklists, see [REFERENCE.md](REFERENCE.md).
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.