Laravel Pint config for teams, with a real pint.json

A practical Laravel Pint config guide. Presets, a team pint.json with strict rules explained, --test and --dirty, composer scripts, CI and Rector order.

Updated

On this page

Laravel Pint ships with every new Laravel application and works with zero configuration. A Laravel Pint config only becomes necessary when the team wants more than the default style: strict types everywhere, final classes, imported functions. That config lives in one file, pint.json, in the project root. This guide shows a real team pint.json, explains each rule and its cost, and covers the flags, composer scripts, editor and CI setup, and how Pint fits next to Rector.

How Pint is configured

Pint is a wrapper around PHP CS Fixer. Without a pint.json it applies the laravel preset to every .php file outside vendor/. With one, it reads three kinds of settings:

  • preset — the base rule set.
  • rules — PHP CS Fixer rules switched on, off, or configured on top of the preset.
  • exclude, notName, notPath — what to skip.

To use a config file from somewhere else, for example a shared company package, pass --config:

vendor/bin/pint --config vendor/acme/coding-style/pint.json

Presets

Pint currently supports five presets:

Preset Use it when
laravel The default. Laravel's own opinionated style. Right for almost every Laravel app.
per You follow the PHP-FIG PER Coding Style.
psr12 You need plain PSR-12, for example in a framework-agnostic package.
symfony The codebase follows Symfony's style.
empty You want to define every rule yourself.

Start from laravel and add rules. Starting from empty means maintaining a long rule list that drifts from what the rest of the Laravel ecosystem looks like.

You can also try a preset for one run without editing the file:

vendor/bin/pint --preset psr12 --test

A team pint.json

This is the pint.json used in this site's own Laravel 13 project. It is also the file kalimera ships into every application it scaffolds.

{
    "preset": "laravel",
    "exclude": [
        "bootstrap/cache",
        "storage"
    ],
    "rules": {
        "declare_strict_types": true,
        "final_class": true,
        "fully_qualified_strict_types": true,
        "global_namespace_import": {
            "import_classes": true,
            "import_constants": true,
            "import_functions": true
        },
        "strict_comparison": true,
        "strict_param": true
    }
}

exclude

bootstrap/cache and storage hold generated and cached PHP. Formatting them is wasted time and produces noisy diffs. vendor/ is already skipped by default.

declare_strict_types

Adds declare(strict_types=1); to the top of every PHP file. Scalar type hints then stop coercing: passing "5" to an int parameter throws a TypeError instead of silently converting. This pairs well with PHPStan, which assumes your types mean what they say. See /guides/larastan-phpstan-laravel.

The cost: code that relied on coercion breaks at runtime. On a fresh application that is nothing. On an existing one, run it on a branch with the test suite.

final_class

Marks every non-abstract class final. Inheritance becomes a decision you make on purpose, by removing final, rather than a default anyone can use.

The cost: Mockery cannot mock a final class. If your tests mock concrete classes, either mock interfaces instead or drop this rule.

strict_comparison and strict_param

strict_comparison rewrites == to === and != to !==. strict_param sets the strict flag on functions that take one, such as in_array() and array_search().

Both change behavior, not just formatting. '1' == 1 is true; '1' === 1 is false. That is the point: loose comparison bugs are hard to spot in review. But run the tests after enabling them on existing code.

fully_qualified_strict_types and global_namespace_import

These two keep class references short and consistent. fully_qualified_strict_types replaces fully qualified names in type hints and docblocks with the imported short name. global_namespace_import adds use statements for global classes, constants and functions, so \sprintf() becomes sprintf() with use function sprintf; at the top.

Imported functions look unusual at first. They make every external symbol a file depends on visible in its import block, and they resolve at compile time.

Rules worth knowing about

Pint also has its own rules, prefixed Pint/, that are off by default:

  • Pint/laravel_blade formats Blade templates. It uses Prettier under the hood, so it needs Node. Try it for one run with vendor/bin/pint --blade.
  • Pint/phpdoc_type_annotations_only strips comment prose and keeps only @ annotation lines. Aggressive; read its documentation before enabling it.

Any PHP CS Fixer rule works in rules. The PHP CS Fixer Configurator lists them with their options.

Flags you will actually use

Command What it does
vendor/bin/pint Fix every file.
vendor/bin/pint --test Report style errors without changing files. Non-zero exit on errors.
vendor/bin/pint --dirty Fix only files with uncommitted changes in Git.
vendor/bin/pint --diff=main Fix only files changed since branching off main.
vendor/bin/pint --repair Fix files, but exit non-zero if anything changed.
vendor/bin/pint --parallel Run in parallel (experimental). Add --max-processes=4 to cap it.
vendor/bin/pint -v Show the changes in detail.
vendor/bin/pint app/Models Fix one directory or file.

--dirty is the everyday command: it touches only what you are working on, so it is fast and keeps diffs focused. --test is for gates. --repair is useful in a pre-commit hook, where you want the fix applied and the commit stopped so you can look at it.

Under Sail, run Pint inside the container so the PHP version matches the app:

vendor/bin/sail bin pint --dirty

Laravel Boost's Pint guideline tells AI agents to run vendor/bin/pint --dirty --format agent after editing PHP, which produces output meant for an agent to read. See /guides/laravel-boost-ai-agents.

Composer scripts

Put the commands in composer.json so nobody has to remember flags. These are the scripts in this project:

{
    "scripts": {
        "pint:dry": "vendor/bin/pint --test",
        "pint:fix": "vendor/bin/pint",
        "phpstan": "vendor/bin/phpstan analyse",
        "rector:dry": "vendor/bin/rector --dry-run",
        "rector:fix": "vendor/bin/rector process",
        "quality": [
            "@pint:dry",
            "@phpstan",
            "@rector:dry"
        ]
    }
}

composer quality is the single gate: style, static analysis and pending refactors, all read-only. Run it before pushing and in CI.

Editor integration

Format on save is the cheapest way to keep --test green.

  • PhpStorm has built-in Laravel Pint support under the PHP quality tools settings. Point it at vendor/bin/pint; it picks up pint.json from the project root.
  • VS Code has community Pint extensions that run vendor/bin/pint on save.

If the project runs under Sail and your host PHP differs from the container's, configure the editor to use the Docker interpreter, or results can differ from CI.

CI integration

Fail the build on style errors rather than auto-committing fixes. A failed check is visible in the pull request; a bot commit is easy to miss.

name: Code style

on: [push, pull_request]

jobs:
  pint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.5'
      - run: composer install --no-interaction --prefer-dist
      - run: vendor/bin/pint --test

Install dependencies and use the project's own vendor/bin/pint so CI runs the exact Pint version in composer.lock. On a large codebase, --diff=origin/main limits the check to changed files, provided the checkout fetches enough history.

Running Pint with Rector

Rector rewrites code: it modernizes syntax, removes dead code, adds type declarations. It does not format its output to your style. Pint does nothing but formatting. So the order is:

  1. rector process
  2. pint

Run Pint last, so whatever Rector produced ends up in your style. Running Pint first means Rector's changes may fail pint --test afterwards.

Rector sometimes needs a second pass: one rewrite can make another rule apply. Kalimera's finalize step does exactly this on a fresh scaffold: Rector twice, then Pint, then composer quality, so the first commit is green. More on Rector setup in /guides/rector-laravel.

Checks are different. pint --test and rector --dry-run change nothing, so their order in composer quality does not matter.

If you want one command for fixing, add it next to the dry scripts:

{
    "scripts": {
        "fix": [
            "@rector:fix",
            "@pint:fix"
        ]
    }
}

Adopting strict rules on an existing codebase

On a fresh app, enable everything on day one. On an existing app:

  1. Commit the new pint.json with only the preset and exclude. Run pint and commit the result on its own, so the formatting commit is separate from real changes.
  2. Add the purely cosmetic rules (fully_qualified_strict_types, global_namespace_import). Run, commit.
  3. Add the behavior-changing rules (declare_strict_types, strict_comparison, strict_param, final_class) one at a time, running the test suite after each.

Large formatting commits can be listed in a .git-blame-ignore-revs file so git blame skips them.

For the full list of what a new project should have in place, see /guides/laravel-project-setup-checklist. If you would rather not wire this by hand each time, kalimera installs this pint.json, the composer scripts and the Rector and PHPStan configs in one unattended run.

All of it, in one unattended run.

kalimera makes these choices once, upfront, then scaffolds a fresh Laravel app with every piece wired and committed.

$ composer global require welldigit/kalimera

Read the docs