Code formatting with Prettier for TypeScript/NestJS projects. Trigger: After editing/creating files, before committing code, ensuring code style consistency.
Use this skill when:
CRITICAL: Format code IMMEDIATELY after editing, not at the end of session
Rule: Format IMMEDIATELY after modifying each file
# After editing/creating a single file
npm run format -- path/to/file.ts
# After modifying multiple files
npm run format -- path/to/file1.ts path/to/file2.ts
# Format entire directory
npm run format -- src/@app/tesla/model/**/*.ts
Workflow:
❌ NEVER:
npm run format -- <file-path>
# Example
npm run format -- src/@app/tesla/model/application/create/tesla-create-model.handler.ts
npm run format -- <file1> <file2> <file3>
# Example
npm run format -- src/@app/tesla/model/application/create/*.ts
npm run format -- <directory>/**/*.ts
# Example - Format all TypeScript files in module
npm run format -- src/@app/tesla/model/**/*.ts
npm run format:check -- <file-path>
# Useful for CI/CD or verification
npm run format:check -- src/@app/tesla/model/**/*.ts
// 1. Edit the file
/* #region AI-generated code */
async execute(command: CreateTeslaModelCommand): Promise<void> {
if (command.payload.price <= 0) {
throw new InvalidPriceException();
}
await this.service.main(command.payload, command.cQMetadata);
}
/* #endregion */
// 2. IMMEDIATELY format
npm run format -- src/@app/tesla/model/application/create/tesla-create-model.handler.ts
# 1. Create exception file
# 2. Write content
# 3. IMMEDIATELY format
npm run format -- src/@app/tesla/model/domain/exceptions/tesla-invalid-price.exception.ts
# 1. Regenerate module
aurora load back module -n=tesla/model -t
# 2. Format ALL generated files
npm run format -- src/@app/tesla/model/**/*.ts
npm run format -- src/@api/tesla/model/**/*.ts
# 1. Check which files were modified
git status
# 2. Format all modified files
npm run format -- src/@app/tesla/model/application/create/tesla-create-model.handler.ts \
src/@app/tesla/model/domain/exceptions/tesla-invalid-price.exception.ts
# 3. Verify formatting succeeded
# 4. Create commit
git add .
git commit -m "feat(tesla/model): add price validation"
aurora-developmentAfter implementing business logic:
1. Edit handler/service/guard
2. Use **prettier** skill to format immediately
3. Continue to next file
aurora-cliAfter regenerating code:
1. Run aurora load command
2. Use **prettier** skill to format all generated files
3. Verify no errors
jest-nestjsAfter writing tests:
1. Write test file
2. Use **prettier** skill to format test file
3. Run tests
conventional-commitsBefore creating commit:
1. Format all modified files with **prettier** skill
2. Verify git diff shows only logical changes (not formatting)
3. Create conventional commit
Prettier configuration is in project root:
# Configuration file (check this for project rules)
.prettierrc
# Ignore patterns
.prettierignore
Common Aurora/NestJS Configuration:
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 4,
"semi": true,
"printWidth": 120,
"arrowParens": "avoid"
}
DO NOT modify prettier config without team approval.
# Check file path is correct
ls -la src/@app/tesla/model/application/create/
# Use absolute path if needed
npm run format -- $(pwd)/src/@app/tesla/model/application/create/tesla-create-model.handler.ts
# File has syntax errors - fix them first
# Check for:
# - Missing closing braces
# - Missing semicolons
# - Incomplete statements
# Format all staged files
npm run format -- $(git diff --cached --name-only --diff-filter=ACM | grep '\.ts$')
# Or format all modified files
npm run format -- $(git diff --name-only --diff-filter=ACM | grep '\.ts$')
| When | Command |
|---|---|
| After editing file | npm run format -- <file> |
| Multiple files | npm run format -- <file1> <file2> |
| Entire directory | npm run format -- <dir>/**/*.ts |
| Check only | npm run format:check -- <file> |
| Before commit | Format all modified files |
// .vscode/settings.json
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
Still run npm run format to be sure!
Integration: