laravel/pint
Laravel Pint is an opinionated PHP code style fixer built on PHP-CS-Fixer. It helps keep Laravel and PHP projects clean and consistent with minimal configuration, making it easy to enforce a unified coding style across your codebase.
Installation:
composer require --dev laravel/pint
Pint is automatically registered as a dev command (pint).
First Run:
php artisan pint
This applies the default Laravel preset to all PHP files in the project.
Key Files:
pint.json (auto-generated config file).pint.json (optional custom config)Run Pint as a pre-commit hook to ensure consistent code style before merging:
php artisan pint --test # Dry run to check for changes
git add .
git commit -m "Fixed code style with Pint"
Daily Code Formatting:
php artisan pint # Auto-fixes files in-place
tasks.json:
{
"label": "Run Pint",
"type": "shell",
"command": "php artisan pint",
"group": {
"kind": "build",
"isDefault": true
}
}
Custom Presets:
Extend the default preset in .pint.json:
{
"preset": "laravel",
"rules": {
"@PHPUnit": true,
"yoda_style": ["always"]
}
}
php artisan pint --preset=custom
CI/CD Integration:
# .github/workflows/pint.yml
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: php artisan pint --test
# Fails if changes detected
php artisan pint --parallel
php artisan pint app/Http/Controllers # Format only controllers
php artisan pint --path=tests/Unit # Format unit tests
php artisan pint --cache-file=/tmp/pint.cache
False Positives in --test Mode:
.pint.json:
{
"ignore": ["legacy/**"]
}
Performance with Large Projects:
php artisan pint --no-parallel
Config Overrides:
pint.json:
php artisan pint --preset=psr12 --rules=@Symfony # Overrides preset
php artisan pint -v # Shows applied rules
php artisan pint --test --diff # Shows changes without applying
Custom Rules:
Extend the Laravel preset in .pint.json:
{
"preset": "laravel",
"rules": {
"no_unused_imports": true,
"ordered_imports": ["sort_algorithm" => "alpha"]
}
}
Preset Management:
php artisan pint --list-presets
php artisan pint --preset=psr12
IDE Integration:
php artisan pint to "Before Commit" hooks.git add .
php artisan pint
git commit -m "feat: implement X" --no-verify
composer.json scripts:
"scripts": {
"post-install-cmd": [
"@php artisan pint --no-interaction"
]
}
--dirty with caution on Windows:
php artisan pint --dirty --ignore="C:\\path\\to\\exclude"
How can I help you explore Laravel packages today?