What is Laravel Pint
Laravel Pint is a code style fixer built on top of PHP CS Fixer. It’s designed to work with zero configuration and automatically formats code to follow Laravel’s coding style. By automating the “coding style review comments” that so often come up in team development, you can focus code review on what really matters.Installation
Newly created Laravel applications include Pint out of the box. For older projects, install it with Composer.How to run it
Basic usage
Automatically fixes all.php files in the project.
Available options
Configuration
You can customize behavior by creating apint.json file at the root of your project.
Presets
A preset is a set of rules. The default is thelaravel preset, which applies rules optimized for Laravel projects.
Customizing rules
You can enable or disable individual rules inpint.json. For the available rules, see the PHP CS Fixer Configurator.
Excluding files and folders
You can exclude specific folders from being checked.notName.
notPath.
Recommended settings
Here’s an example of apint.json configuration that works well in real-world development.
no_unused_imports is a setting for package development. Pint’s default is true (removes unused use statements), so this setting itself is unnecessary in ordinary Laravel projects. In package development, patterns that turn features on/off by importing traits or interfaces are common, so it’s convenient to keep false as the default and switch to true for individual packages as appropriate.Setting up scripts in composer.json
By registering scripts for Pint incomposer.json, you can run it with just composer pint.
In CI environments, use
composer pint:test to detect style violations without modifying files. The --test option returns a non-zero exit code if errors are found, so it can be used for CI pass/fail checks.Automatic execution with GitHub Actions
You can use GitHub Actions to automatically fix and commit code style on every push.1
Set workflow permissions
In your GitHub repository, go to Settings > Actions > General > Workflow permissions and enable “Read and write permissions.”
2
Create the workflow file
Create
.github/workflows/lint.yml.