com um clique
code-formatting
Format code according to project standards and fix linting issues
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Menu
Format code according to project standards and fix linting issues
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Baseado na classificação ocupacional SOC
Debug code using detailed profiling and critical path timing before making suggestions
Workflow for investigating and fixing failing tests in this project
Making Python or TypeScript packages shareable (pip/npm)
Setup pytest with coverage reporting and watch mode for this Python project
Commands to execute tests in this project with various options and configurations
Git branch strategy, commit conventions, and PR process for this project
| name | code-formatting |
| description | Format code according to project standards and fix linting issues |
| auto-activates | ["format code","fix formatting","run formatter","code style","linting errors"] |
This skill activates when you need to:
Check project for existing formatting configuration:
.prettierrc, .eslintrc (JavaScript/TypeScript).black, pyproject.toml, ruff.toml (Python).rustfmt.toml (Rust).gofmt settings (Go)Check {{lint_command}} or look for:
package.json scripts: "format", "lint", "lint:fix".pre-commit-config.yaml for pre-commit hooksOption A: Black (Opinionated)
# Install
pip install black
# Format all Python files
black .
# Format specific file
black myfile.py
# Check without modifying
black --check .
# Preview changes
black --diff .
Add to pyproject.toml:
[tool.black]
line-length = 88
target-version = ['py310']
include = '\.pyi?$'
extend-exclude = '''
/(
# directories
\.eggs
| \.git
| \.venv
| build
| dist
)/
'''
Option B: Ruff (Fast, Modern)
# Install
pip install ruff
# Format code
ruff format .
# Check and fix linting
ruff check --fix .
# Check only
ruff check .
Add ruff.toml:
line-length = 88
target-version = "py310"
[lint]
select = ["E", "F", "I", "N", "W"]
ignore = ["E501"]
[format]
quote-style = "double"
indent-style = "space"
Option C: autopep8
# Install
pip install autopep8
# Format file
autopep8 --in-place --aggressive --aggressive myfile.py
# Format all files
find . -name '*.py' -exec autopep8 --in-place --aggressive --aggressive {} \;
Option A: Prettier
# Install
npm install --save-dev prettier
# Format all files
npx prettier --write .
# Format specific files
npx prettier --write "src/**/*.{js,jsx,ts,tsx,json,css,md}"
# Check formatting
npx prettier --check .
Add .prettierrc:
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2,
"useTabs": false
}
Option B: ESLint (with autofix)
# Install
npm install --save-dev eslint
# Fix all fixable issues
npx eslint --fix .
# Fix specific files
npx eslint --fix src/**/*.js
Combined (Prettier + ESLint):
# Format with Prettier, then lint with ESLint
npx prettier --write . && npx eslint --fix .
Add to package.json:
{
"scripts": {
"format": "prettier --write .",
"lint": "eslint .",
"lint:fix": "eslint --fix ."
}
}
Built-in gofmt:
# Format all Go files
gofmt -w .
# Format specific file
gofmt -w main.go
# Check formatting (returns files that need formatting)
gofmt -l .
Alternative: goimports (adds/removes imports)
# Install
go install golang.org/x/tools/cmd/goimports@latest
# Format and fix imports
goimports -w .
Option: golangci-lint (comprehensive)
# Install
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Run linters and auto-fix
golangci-lint run --fix
Built-in rustfmt:
# Format all Rust files
cargo fmt
# Check formatting without modifying
cargo fmt -- --check
Add rustfmt.toml:
max_width = 100
hard_tabs = false
tab_spaces = 4
edition = "2021"
Clippy (Rust linter):
# Run Clippy
cargo clippy
# Auto-fix some issues
cargo clippy --fix
RuboCop:
# Install
gem install rubocop
# Auto-fix
rubocop -A
# Check only
rubocop
# Fix safe issues only
rubocop --safe-auto-correct
Add .rubocop.yml:
AllCops:
TargetRubyVersion: 3.0
NewCops: enable
Style/StringLiterals:
EnforcedStyle: single_quotes
Google Java Format:
# Download
wget https://github.com/google/google-java-format/releases/download/v1.17.0/google-java-format-1.17.0-all-deps.jar
# Format file
java -jar google-java-format-1.17.0-all-deps.jar -i MyFile.java
# Format all Java files
find . -name "*.java" -exec java -jar google-java-format-1.17.0-all-deps.jar -i {} \;
Create .vscode/settings.json:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[go]": {
"editor.formatOnSave": true
}
}
Install pre-commit:
pip install pre-commit
Create .pre-commit-config.yaml:
For Python:
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.280
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
For JavaScript/TypeScript:
repos:
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0
hooks:
- id: prettier
types_or: [javascript, jsx, ts, tsx, json, css, markdown]
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.44.0
hooks:
- id: eslint
args: [--fix]
Install hooks:
pre-commit install
Run on all files:
pre-commit run --all-files
GitHub Actions example (.github/workflows/format-check.yml):
Python:
name: Format Check
on: [push, pull_request]
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: pip install black ruff
- run: black --check .
- run: ruff check .
JavaScript:
name: Format Check
on: [push, pull_request]
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm ci
- run: npm run lint
- run: npx prettier --check .
Solutions:
pip install black or npm install -D prettiernpm cache clean --forceSolutions:
Solutions:
Solutions:
| Language | Format Command | Check Command |
|---|---|---|
| Python (Black) | black . | black --check . |
| Python (Ruff) | ruff format . | ruff check . |
| JavaScript | prettier --write . | prettier --check . |
| Go | gofmt -w . | gofmt -l . |
| Rust | cargo fmt | cargo fmt -- --check |
| Ruby | rubocop -A | rubocop |