How to use Laravel Pint in VSCode?
Laravel Pint is an opinionated PHP code style fixer based on PHP-CS-Fixer. It helps maintain consistent code style across your Laravel projects by automatically formatting your code to follow Laravel's coding standards.
Why Use Pint?
Pros
- Zero configuration needed - works out of the box with Laravel standards
- Consistent code style across team members
- Saves time on code reviews by eliminating style discussions
- Integrates well with CI/CD pipelines
- Highly customizable through configuration file
- Fast execution compared to other formatters
Cons
- May conflict with other PHP formatters if not configured properly
- Some developers prefer different styling conventions
- Initial setup required for IDE integration
- Can cause large git diffs on first run
Installation
Install Laravel Pint in your project:
composer require laravel/pint --dev
VSCode Setup
-
Install "Laravel Pint" extension from VSCode marketplace
-
Configure default formatter in VSCode settings:
{
"[php]": {
"editor.defaultFormatter": "open-southeners.laravel-pint"
}
}
- Create task configuration:
- Create
.vscode/tasks.json
:
{
"version": "2.0.0",
"tasks": [
{
"label": "Pint Formatter",
"type": "shell",
"command": "./vendor/bin/pint",
"problemMatcher": [],
"presentation": {
"reveal": "silent"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- Install "Run on Save" extension to auto-format on file save
Manual Usage
From terminal:
# Format all files
./vendor/bin/pint
# Format specific file
./vendor/bin/pint app/Models/User.php
# Format with verbose output
./vendor/bin/pint -v
# Test without making changes
./vendor/bin/pint --test
In VSCode
-
Using Command Palette (Cmd/Ctrl + Shift + P):
- Type "Format Document"
- Or use shortcut: Shift + Alt + F
-
Using Task:
- Press Cmd/Ctrl + Shift + P
- Type "Run Task"
- Select "Pint Formatter"