ホーム

Blog

Laravel Pint

Laravel Pint is an opinionated PHP code style fixer for minimalists. It is designed to ensure that your code style remains clean and consistent within your Laravel application

更新日:2025/10/15

Laravel Pint

Laravel Pint is an opinionated PHP code style fixer for minimalists. It is designed to ensure that your code style remains clean and consistent within your Laravel application

Pint is built on top of PHP CS Fixer and is listed as one of the available packages within the Laravel ecosystem documentation

1 Installation and Basic Usage

Laravel Pint is automatically installed with all new Laravel applications, meaning it typically requires no configuration and can be used immediately. If you are working with an older application, you may install Pint using Composer with the development flag

composer require laravel/pint --dev

1.1 Running Pint

To instruct Pint to fix code style issues, you invoke the pint binary located in your project's vendor/bin directory: 

./vendor/bin/pint

Pint will display a list of all the files it updates. For more detailed information about the changes, you can use the -v option

./vendor/bin/pint -v

1.2 Execution Modes

Pint supports several modes of execution:

1.2.1 Parallel Mode

For improved performance (experimental), Pint can run in parallel mode using the --parallel option. You can specify the maximum number of processes using --max-processes=[number], otherwise Pint will use every available core on your machine

./vendor/bin/pint --parallel --max-processes=4

1.2.2 Specific Files/Directories

Pint can be run against specific files or directories

./vendor/bin/pint app/Models
./vendor/bin/pint app/Models/User.php

1.2.3 Testing/Inspection

The --test option instructs Pint to inspect code for style errors without making any changes to the files. If errors are found, Pint will return a non-zero exit code

./vendor/bin/pint --test

1.2.4 Fix and Exit (CI)

The --repair option fixes any style errors but exits with a non-zero exit code if any files needed fixing

./vendor/bin/pint --repair

1.2.5  Git Integration

  • --diff=[branch]: Modifies only the files that differ from the specified branch (e.g., --diff=main). This is useful in Continuous Integration (CI) environments to save time by only inspecting new or modified files
./vendor/bin/pint --diff=main
  • --dirty: Modifies only the files that currently have uncommitted changes according to Git
./vendor/bin/pint --dirty

2 Configuration

By default, Pint follows the opinionated coding style of Laravel. While Pint requires no configuration, you can customize its behavior by creating a pint.json file in the root directory of your project

2.1 Presets

Presets define a collection of rules used to fix code style issues. The default preset is laravel. You can change the preset either by using the --preset option when running Pint (e.g., ./vendor/bin/pint --preset psr12) or by defining it in the pint.json file

{
    "preset": "laravel"
}

Pint currently supports the following presets: laravel, per, psr12, symfony, and empty

2.2 Rules

Presets are generally sufficient for most projects, meaning you typically do not need to worry about individual rules. However, since Pint is built on PHP CS Fixer, you can enable, disable, or configure specific rules within your pint.json file. You can start from the default laravel preset and override rules, or use the empty preset to define rules from scratch

Example of configuring rules in pint.json:

{
    "preset": "laravel",
    "rules": {
        "simplified_null_return": true,
        "array_indentation": false,
        "new_with_parentheses": {
            "anonymous_class": true,
            "named_class": true
        }
    }
}

2.3 Excluding Files and Folders

By default, Pint inspects all .php files in a project, excluding the vendor directory. You can define exclusions in your pint.json file using:


  • exclude: Excludes specific folders
{
    "exclude": [
        "my-specific/folder"
    ]
}
  • notName: Excludes all files matching a given name pattern (e.g., *-my-file.php)
{
    "notName": [
        "*-my-file.php"
    ]
}
  • notPath: Excludes a file by providing its exact path (e.g., path/to/excluded-file.php)
{
    "notPath": [
        "path/to/excluded-file.php"
    ]
}

If you wish to use a configuration file located in a specific directory outside the project root, you can use the --config option when invoking Pint

./vendor/bin/pint --config vendor/my-company/coding-style/pint.json

3 Continuous Integration

Pint can be automated in Continuous Integration (CI) environments, such as GitHub Actions. This requires configuring a workflow file (e.g., .github/workflows/lint.yml) that includes steps to check out the code, set up PHP (using the shivammathur/setup-php@v2 action with tools: pint), run the pint command, and optionally commit the fixed files back to the repository using the stefanzweifel/git-auto-commit-action@v6. You must ensure "Read and write permissions" are granted to the workflow permissions in GitHub settings

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

 

オフショア開発のご紹介資料

氏名 *

会社名 *

部署 *

電話番号 *

メールアドレス *

資料を選ぶ

送信前に当サイトの、
プライバシーポリシーをご確認ください。