Laravel Packages

Pun: Format, Lint, and Analyze PHP With One Rust Binary

Published
Pun: Format, Lint, and Analyze PHP With One Rust Binary image

Pun is one Rust binary that formats, lints, and analyzes PHP code and installs Composer packages, and it keeps its settings in one pun.toml file. Pun is now in public beta.

The documentation says Pun replaces Pint, PHP-CS-Fixer, Rector, PHPStan, Larastan, and Composer, and that each command aims to give the same results as the tool it replaces, so you can switch one command at a time. It supports projects that target PHP 8.3 or later, and the format, lint, and analyse commands don't need PHP installed. Pun uses the parser and analysis libraries from Mago and ports rules and test fixtures from the other projects.

Nuno also recently made a video on it:

Pun Commands

  • pun format fixes layout, casing, and spelling. The README says it formats code byte for byte like Laravel Pint, and pun format --test checks files without changing them
  • pun lint reports code you could write a better way, and pun lint --fix applies the fixes. Lint presets are essential, recommended, and strict
  • pun analyse reports type errors such as undefined methods, the way PHPStan does. It never edits a file, and --generate-baseline saves the current errors so you can fix them later
  • pun check runs format, lint, and analyse together, and pun check --fix applies the format and lint fixes
  • pun install reads composer.json and composer.lock and installs the packages into vendor/. It downloads packages in parallel, checks each checksum, and keeps one copy of each package in a shared store that it links into your project
  • pun require, pun update, and pun remove add, update, and remove packages

Here are the pun check options for checking only the files you changed:

pun check --dirty
pun check --staged
pun check --diff=main

--dirty selects files with uncommitted changes, --staged selects staged files, and --diff=main selects files changed since you branched from main. Every command exits with 0 when the run is clean, 1 when it finds problems, and 2 when Pun could not run.

Migrating From Pint, Rector, and PHPStan

pun migrate reads your pint.json, .php-cs-fixer.php, rector.php, and phpstan.neon files and writes one pun.toml. You can preview the result first:

pun migrate --dry-run
pun migrate

Migration leaves your old config files and composer.json alone. It does rewrite @phpstan-ignore and @php-cs-fixer-ignore comments in your PHP files to @pun-ignore, so the docs tell you to start from a clean Git working tree. It prints every rule it could not move.

Migration does not move everything:

  • PHPStan baselines are not copied. You create a new one with pun analyse --generate-baseline
  • Pint's symfony preset is not supported, and migration stops with an error
  • Custom rules and closures are skipped with a warning

For a project with none of those configs, pun init asks which presets you want and writes the file. On a Laravel app with Pest it looks like this:

[extensions]
laravel = "on"
pest = "on"

[files]
exclude = ["tmp", "temp"]

[format]
preset = "laravel"

[lint]
preset = "recommended"

[analyse]
preset = "recommended"

If you want the exact rule set of a PHPStan level, you can set the analyse preset to a value such as phpstan/level_5.

Laravel Support

Both pun migrate and pun init turn on the laravel, pest, and phpunit extensions when they find those packages in composer.lock. With the laravel extension on, pun analyse also runs Larastan's checks without a separate install, and pun lint adds Laravel rules such as laravel/no-request-all.

Pun doesn't run PHP, so it finds macros by reading X::macro() and X::mixin() calls in your service providers and bootstrap files. The docs list the cases it misses, including macros with computed names and macros registered by other vendor files.

The Composer package also includes a Laravel Boost guideline that tells a coding agent to run pun check --fix --dirty after it edits PHP. When Pun detects Claude Code, Cursor, or Codex, it prints one summary line and one line per problem.

Beta Limitations

  • Pun doesn't have every Rector, PHP-CS-Fixer, PHPStan, or Larastan rule yet. The rule reference marks the missing ones as Planned
  • A format rule Pun doesn't implement is a config error, and Pun exits before it edits any file
  • pun install doesn't support custom installer paths such as composer/installers, and a package locked with only a VCS source fails
  • Blade formatting needs Node.js with Prettier unless you set blade = "native"

You can read the full command reference in the Pun documentation and view the source code on GitHub.

Eric L. Barnes photo

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Sponsored

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
Form Request Model Lookups and PHP 8.6 Support in Laravel 13.44 image

Form Request Model Lookups and PHP 8.6 Support in Laravel 13.44

Read article
Generate Laravel Validation Rules From a JSON Schema image

Generate Laravel Validation Rules From a JSON Schema

Read article
Laravel Suspicious Login: Detect and Block Risky Logins image

Laravel Suspicious Login: Detect and Block Risky Logins

Read article
Decide with Jev: Make Failed AI Requests Safe in Laravel image

Decide with Jev: Make Failed AI Requests Safe in Laravel

Read article
Black Friday: Learn the habits behind AI workflows that work image

Black Friday: Learn the habits behind AI workflows that work

Read article
Laravel Black Friday and Cyber Monday Deals 2026 image

Laravel Black Friday and Cyber Monday Deals 2026

Read article