Git workflow, code quality, context management and testing commands: - commit, push, pr, issue - git operations - simplify, refactor, verify, check - code quality - catchup, onboard, save, cleanup - context management - test, format, sync - development utilities Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
112 lines
2.1 KiB
Markdown
112 lines
2.1 KiB
Markdown
---
|
|
description: Run code formatters (prettier, eslint --fix, black, etc.)
|
|
argument-hint: [path] - Optional path to format (defaults to .)
|
|
---
|
|
|
|
# Format Code
|
|
|
|
## Pre-computed Context
|
|
|
|
**Package.json Scripts:**
|
|
!`cat package.json 2>/dev/null | grep -E '"(format|lint|prettier)"' | head -5 || echo "No package.json"`
|
|
|
|
**Prettier Config:**
|
|
!`ls -la .prettierrc* prettier.config.* 2>/dev/null | head -3 || echo "No Prettier config"`
|
|
|
|
**ESLint Config:**
|
|
!`ls -la .eslintrc* eslint.config.* 2>/dev/null | head -3 || echo "No ESLint config"`
|
|
|
|
**Python Formatters:**
|
|
!`ls -la pyproject.toml setup.cfg .flake8 2>/dev/null | head -3 || echo "No Python config"`
|
|
|
|
**Modified Files:**
|
|
!`git diff --name-only | head -10`
|
|
|
|
---
|
|
|
|
## Instructions
|
|
|
|
You are running code formatters on the codebase.
|
|
|
|
### Detect Stack & Run Formatters
|
|
|
|
#### JavaScript/TypeScript
|
|
|
|
Check for and run in order:
|
|
|
|
1. **npm scripts** (preferred):
|
|
```bash
|
|
npm run format 2>/dev/null || npm run lint:fix 2>/dev/null
|
|
```
|
|
|
|
2. **Prettier directly**:
|
|
```bash
|
|
npx prettier --write "**/*.{js,jsx,ts,tsx,json,css,md}" 2>/dev/null
|
|
```
|
|
|
|
3. **ESLint fix**:
|
|
```bash
|
|
npx eslint --fix . 2>/dev/null
|
|
```
|
|
|
|
#### Python
|
|
|
|
1. **Black**:
|
|
```bash
|
|
black . 2>/dev/null || python -m black . 2>/dev/null
|
|
```
|
|
|
|
2. **isort** (import sorting):
|
|
```bash
|
|
isort . 2>/dev/null || python -m isort . 2>/dev/null
|
|
```
|
|
|
|
3. **Ruff** (fast linter + formatter):
|
|
```bash
|
|
ruff format . 2>/dev/null
|
|
ruff check --fix . 2>/dev/null
|
|
```
|
|
|
|
#### Go
|
|
|
|
```bash
|
|
go fmt ./... 2>/dev/null
|
|
goimports -w . 2>/dev/null
|
|
```
|
|
|
|
#### Rust
|
|
|
|
```bash
|
|
cargo fmt 2>/dev/null
|
|
```
|
|
|
|
### Path Argument
|
|
|
|
If a path argument is provided, format only that path:
|
|
```bash
|
|
npx prettier --write "$ARGUMENTS"
|
|
```
|
|
|
|
### Report Changes
|
|
|
|
After formatting, show what changed:
|
|
```bash
|
|
git diff --stat
|
|
```
|
|
|
|
---
|
|
|
|
## Common Issues
|
|
|
|
**Prettier vs ESLint conflicts:**
|
|
- Use `eslint-config-prettier` to disable conflicting rules
|
|
- Run Prettier first, then ESLint
|
|
|
|
**Format on save not working:**
|
|
- Check VS Code settings: `editor.formatOnSave`
|
|
- Verify default formatter is set
|
|
|
|
**Some files not formatted:**
|
|
- Check `.prettierignore` / `.eslintignore`
|
|
- Verify file extensions in config
|