Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

pun format

Fix code style.

Fix code style in your PHP files. It changes layout only, never behaviour.

Usage

pun format [paths] [options]
pun format              # whole project
pun format app/Models   # one folder
pun format --test       # check only, change nothing

Options

Option Description
--test Check only. Exit 1 if a file needs formatting. Alias: --check.
--repair Format, and exit 1 if a file changed.
--dirty Only files with uncommitted changes.
--staged Only files with staged changes, also in a project inside a subfolder of the repository.
--diff=<branch> Only files changed since <branch>. With --dirty, --staged and --diff, a changed symlink to a file outside the project is skipped.
--watch Format again when files change.
--preset=<name> Use laravel, psr12 or empty instead of pun.toml.
--config=<path> Use this pun.toml.
--no-config Use the laravel preset, no config file.
--format=<fmt> Report as json, agent, checkstyle, junit, gitlab or github.
--output-to-file=<path> Also write the report to a file. A symlink in the project that leads outside it is refused.
--no-cache Check every file again.
--explain Show the rules the run applies.
--max-processes=<n> Limit threads. Default: one per core.
--color=<when> auto, always or never.
-v Also show unchanged files and diffs.
-q Quiet.

What happens

  • Reads the [format] rules from pun.toml.
  • Formats each file and saves it.
  • Prints one line per changed file and a summary.
  • Skips files that did not change since the last run (cached).
  • Blade files are formatted only when the laravel/blade rule is on.
$ pun format
 ✔ app/Http/Kernel.php    format/whitespace/no-trailing
 ✔ app/Models/User.php    format/imports/ordered
Formatted 2 files, 482 unchanged · 484 files in 0.21s

Limitations

  • A rule that Pun doesn’t implement is a config error. Pun names it and exits 2 before editing any file.
  • Pint’s risky and code-deleting fixers are lint rules. pun format alone doesn’t apply a full Pint config. Use pun check --fix.
  • Blade formatting with Prettier needs Node.js. [format] blade = "native" needs none, but doesn’t sort Tailwind classes.
  • No Pint txt or xml formats, and no --bail, --cache-file, --ansi or --no-ansi.

Exit codes

Code Meaning
0 Done, or nothing to change.
1 --test found a file to format, --repair changed a file, or a syntax error.
2 Pun could not run, for example no pun.toml.

Last updated on

Was this page helpful?