> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel Pint

> A code style fixer built on top of PHP CS Fixer. Learn how to maintain consistent coding style across your team.

## What is Laravel Pint

[Laravel Pint](https://github.com/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.

```mermaid theme={null}
flowchart LR
    A["PHP file"] --> B["Run pint"]
    B --> C{Style<br>errors?}
    C -- Yes --> D["Auto-fix"]
    C -- No --> E["No changes"]
    D --> F["Formatted file"]
    E --> F
```

## Installation

Newly created Laravel applications include Pint out of the box. For older projects, install it with Composer.

```shell theme={null}
composer require laravel/pint --dev
```

## How to run it

### Basic usage

Automatically fixes all `.php` files in the project.

```shell theme={null}
./vendor/bin/pint
```

You can also target specific files or directories.

```shell theme={null}
./vendor/bin/pint app/Models
./vendor/bin/pint app/Models/User.php
```

### Available options

| Option              | Description                                                                                         |
| ------------------- | --------------------------------------------------------------------------------------------------- |
| `--test`            | Only detects style errors without modifying files. Returns a non-zero exit code if errors are found |
| `--dirty`           | Only targets files with uncommitted changes in Git                                                  |
| `--diff=[branch]`   | Only targets files that differ from the specified branch                                            |
| `--repair`          | Fixes style errors and returns a non-zero exit code if any fixes were made                          |
| `--parallel`        | Improves performance with parallel execution mode (experimental)                                    |
| `--max-processes=4` | Combined with `--parallel`, specifies the maximum number of processes                               |
| `-v`                | Shows detailed information about the changes                                                        |
| `--config`          | Specifies the path to the `pint.json` file to use                                                   |
| `--preset`          | Specifies the preset to use                                                                         |

```shell theme={null}
# Check only, without modifying files
./vendor/bin/pint --test

# Only target uncommitted files
./vendor/bin/pint --dirty

# Parallel execution
./vendor/bin/pint --parallel
```

## Configuration

You can customize behavior by creating a `pint.json` file at the root of your project.

```json theme={null}
{
    "preset": "laravel"
}
```

You can also explicitly specify the path to the configuration file.

```shell theme={null}
./vendor/bin/pint --config vendor/my-company/coding-style/pint.json
```

### Presets

A preset is a set of rules. The default is the `laravel` preset, which applies rules optimized for Laravel projects.

| Preset    | Description                                  |
| --------- | -------------------------------------------- |
| `laravel` | Laravel's recommended coding style (default) |
| `psr12`   | The PSR-12 coding standard                   |
| `per`     | PER Coding Style                             |
| `symfony` | Symfony's coding style                       |
| `empty`   | No rules. Define rules individually          |

```shell theme={null}
# Specify a preset from the command line
./vendor/bin/pint --preset psr12
```

### Customizing rules

You can enable or disable individual rules in `pint.json`. For the available rules, see the [PHP CS Fixer Configurator](https://mlocati.github.io/php-cs-fixer-configurator).

```json theme={null}
{
    "preset": "laravel",
    "rules": {
        "simplified_null_return": true,
        "array_indentation": false,
        "new_with_parentheses": {
            "anonymous_class": true,
            "named_class": true
        }
    }
}
```

### Excluding files and folders

You can exclude specific folders from being checked.

```json theme={null}
{
    "exclude": [
        "my-specific/folder"
    ]
}
```

To exclude by file name pattern, use `notName`.

```json theme={null}
{
    "notName": [
        "*-my-file.php"
    ]
}
```

To exclude by specific file path, use `notPath`.

```json theme={null}
{
    "notPath": [
        "path/to/excluded-file.php"
    ]
}
```

## Recommended settings

Here's an example of a `pint.json` configuration that works well in real-world development.

```json theme={null}
{
    "preset": "laravel",
    "rules": {
        "no_unused_imports": false,
        "strict_comparison": true,
        "declare_strict_types": true
    }
}
```

The reasons for adding each rule:

| Rule                   | Effect                                                                                                                                                                           |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `no_unused_imports`    | When set to `false`, keeps unused `use` statements instead of removing them. Pint's default is `true` (removes them), so this setting is not needed in ordinary Laravel projects |
| `strict_comparison`    | Converts `==` to `===` and `!=` to `!==` to prevent bugs from unexpected type juggling                                                                                           |
| `declare_strict_types` | Automatically adds `declare(strict_types=1);` at the top of the file to increase type safety                                                                                     |

<Tip>
  `strict_comparison` and `declare_strict_types` enforce type-strict code, so the initial fix volume can be large when adding them to an existing project. Introducing them from the start is recommended for new projects.
</Tip>

<Info>
  **`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.
</Info>

## Setting up scripts in composer.json

By registering scripts for Pint in `composer.json`, you can run it with just `composer pint`.

```json theme={null}
{
    "scripts": {
        "pint": "./vendor/bin/pint",
        "pint:test": "./vendor/bin/pint --test"
    }
}
```

Once registered, you can run it as follows:

```shell theme={null}
# Auto-fix the code
composer pint

# Check only (no fixing)
composer pint:test
```

<Info>
  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.
</Info>

## Automatic execution with GitHub Actions

You can use GitHub Actions to automatically fix and commit code style on every push.

<Steps>
  <Step title="Set workflow permissions">
    In your GitHub repository, go to **Settings > Actions > General > Workflow permissions** and enable "Read and write permissions."
  </Step>

  <Step title="Create the workflow file">
    Create `.github/workflows/lint.yml`.

    ```yaml theme={null}
    name: Fix Code Style

    on: [push]

    jobs:
      lint:
        runs-on: ubuntu-latest
        strategy:
          fail-fast: true
          matrix:
            php: [8.4]

        steps:
          - name: Checkout code
            uses: actions/checkout@v5

          - name: Setup PHP
            uses: shivammathur/setup-php@v2
            with:
              php-version: ${{ matrix.php }}
              tools: pint

          - name: Run Pint
            run: pint

          - name: Commit linted files
            uses: stefanzweifel/git-auto-commit-action@v6
    ```
  </Step>
</Steps>

This workflow runs Pint on every push and automatically commits any files that were fixed for style violations.

<Tip>
  Since fixes happen before pull request review, the number of style-related review comments decreases. When rolling out to a team, run Pint on all files locally first, then add the workflow to avoid extra commits.
</Tip>


## Related topics

- [Laravel and AI development](/en/ai.md)
- [Laravel Package Skeleton — the official starter template for packages](/en/blog/package-skeleton-introduction.md)
- [Laravel Boost](/en/boost.md)
- [Laravel Telescope](/en/telescope.md)
- [Laravel Bluesky](/en/packages/laravel-bluesky/index.md)
