What is Laravel Pint?
Laravel Pint is an opinionated PHP code style fixer built on top of PHP CS Fixer. It fixes code style issues automatically, following Laravel’s opinionated coding style by default. Pint removes the need for style-related review comments, so your team can focus on what matters in code review.Installation
Pint is automatically installed with all new Laravel applications. For older projects, install it via Composer:Running Pint
Basic usage
Fix code style issues in all.php files in your project:
Options
| Option | Description |
|---|---|
--test | Inspect without making changes. Returns a non-zero exit code if errors are found |
--dirty | Only inspect files with uncommitted changes according to Git |
--diff=[branch] | Only inspect files that differ from the given branch |
--repair | Fix errors but also exit with a non-zero code if any fixes were applied |
--parallel | Run in parallel mode (experimental) for better performance |
--max-processes=4 | Limit the number of parallel processes (used with --parallel) |
-v | Show a detailed list of all changes made |
--config | Path to a custom pint.json configuration file |
--preset | Preset to use for this run |
Configuring Pint
Create apint.json file in the project root to customize behavior:
Presets
A preset is a predefined collection of rules. The default is thelaravel preset.
| Preset | Description |
|---|---|
laravel | Laravel’s opinionated coding style (default) |
psr12 | PSR-12 coding standard |
per | PER Coding Style |
symfony | Symfony coding style |
empty | No rules — define everything from scratch |
Rules
Override or add individual rules inpint.json. Browse available rules at the PHP CS Fixer Configurator.
Excluding files and folders
Exclude entire directories:Recommended configuration
A practicalpint.json used in real projects:
| Rule | Effect |
|---|---|
no_unused_imports | Set to false to keep unused use statements. Pint’s default is true (remove them), so this entry is not needed in a normal Laravel application |
strict_comparison | Replaces == with === and != with !==, preventing unexpected type-coercion bugs |
declare_strict_types | Adds declare(strict_types=1); to the top of every file, enforcing type safety |
no_unused_imports is primarily useful for package development. Pint’s default is true (removes unused use statements), so a normal Laravel application does not need this entry at all. In packages, traits and interfaces are sometimes imported specifically to toggle a feature on or off, so setting this to false preserves those intentional imports. A practical approach: add "no_unused_imports": false as a baseline and switch individual packages to true when you are sure all imports are used.Adding scripts to composer.json
Register Pint as a Composer script so you can run it withcomposer pint:
Use
composer pint:test in CI pipelines to detect style violations without modifying files. The --test option returns a non-zero exit code on failure, so your CI check will fail if any violations are found.CI/CD with GitHub Actions
Automatically fix and commit code style on every push using GitHub Actions.Enable workflow permissions
In your GitHub repository, go to Settings > Actions > General > Workflow permissions and enable Read and write permissions.