Laravel Pint: The Secret Weapon for Clean Code!
May 16, 2024
Laravel Pint: PHP Code Style Fixer
Laravel Pint is an opinionated PHP code style fixer for Laravel applications.
What does opinionated mean?
- It enforces a specific coding style
- Minimal configuration needed
- Encourages consistency in Laravel projects
In other words Laravel Pint comes with strong defaults and expect you to follow a specific set of best practices.
It is built on top of PHP-CS-Fixer.
It is designed to automatically format PHP code according to Laravelβs coding standards.
Key Features of Laravel Pint
- Zero configuration required
- Opinionated
- Fast and minimal
- Customizable
- PSR Compliance - PSR-1, PSR-2, and PSR-12 standards.
How to Use Laravel Pint
1. Install Laravel Pint
composer require laravel/pint --dev
2. Run Laravel Pint
vendor/bin/pint
3. Custom Configuration (Optional)
Create a pint.json
file in the root of your project (sample config file):
{
"preset": "laravel",
"rules": {
"array_syntax": {"syntax": "short"}
},
"exclude": ["vendor"]
}
Go to the docs for more.
4. Dry Run (Check Without Fixing)
vendor/bin/pint --test
5. Running Pint on Specific Files
vendor/bin/pint app/Http/Controllers
Why Use Laravel Pint?
- Saves Time β No manual formatting needed.
- Maintains Consistency β Ensures all developers in a project follow the same style.
- Improves Readability
Integrates with CI/CD β Can be used in GitHub Actions or pipelines.
Reach out to me! Find me on linkedin!
Want to stay updated? Join my newsletter and get a weekly report on the most exciting industry news! π