网页 综合 更新时间 2026-11-13 17:32:25

Laravel Pint | Laravel 13.x - The clean stack for Artisans and agents

自动蜘蛛 laravel.com 正文约 6000 字
Laravel Pint | Laravel 13.x - The clean stack for Artisans and agents
Laravel Pint is an opinionated PHP code style fixer for minimalists. Pint is built on top of PHP CS Fixer and makes it simple to ensure that your code style stays clean and consistent.
Pint is automatically installed with all new Laravel applications so you may start using it immediately. By default, Pint does not require any configuration and will fix code style issues in your code by following the opinionated coding style of Laravel.
Pint is included in recent releases of the Laravel framework, so installation is typically unnecessary. However, for older applications, you may install Laravel Pint via Composer:
You can instruct Pint to fix code style issues by invoking the pint binary that is available in your project's vendor/bin directory:
If you would like Pint to run in parallel mode (experimental) for improved performance, you may use the --parallel option:
Parallel mode also allows you to specify the maximum number of processes to run via the --max-processes option. If this option is not provided, Pint will use every available core on your machine:
You may also run Pint on specific files or directories:
By default, Pint does not format Blade templates. If you would like to format your .blade.php files as well, you may use the --blade option, which enables the Pint/laravel_blade rule for the current run without modifying your pint.json file:
Pint will display a thorough list of all of the files that it updates. You can view even more detail about Pint's changes by providing the -v option when invoking Pint:
If you would like Pint to simply inspect your code for style errors without actually changing the files, you may use the --test option. Pint will return a non-zero exit code if any code style errors are found:
If you would like Pint to only modify the files that differ from the provided branch according to Git, you may use the --diff=[branch] option. This can be effectively used in your CI environment (like GitHub actions) to save time by only inspecting new or modified files:
If you would like Pint to only modify the files that have uncommitted changes according to Git, you may use the --dirty option:
If you would like Pint to fix any files with code style errors but also exit with a non-zero exit code if any errors were fixed, you may use the --repair option:
As previously mentioned, Pint does not require any configuration. However, if you wish to customize the presets, rules, or inspected folders, you may do so by creating a pint.json file in your project's root directory:
In addition, if you wish to use a pint.json from a specific directory, you may provide the --config option when invoking Pint:
Presets define a set of rules that can be used to fix code style issues in your code. By default, Pint uses the laravel preset, which fixes issues by following the opinionated coding style of Laravel. However, you may specify a different preset by providing the --preset option to Pint:
If you wish, you may also set the preset in your project's pint.json file:
Pint's currently supported presets are: laravel, per, psr12, symfony, and empty.
Rules are style guidelines that Pint will use to fix code style issues in your code. As mentioned above, presets are predefined groups of rules that should be perfect for most PHP projects, so you typically will not need to worry about the individual rules they contain.
However, if you wish, you may enable or disable specific rules in your pint.json file or use the empty preset and define the rules from scratch:
Pint is built on top of PHP CS Fixer. Therefore, you may use any of its rules to fix code style issues in your project: PHP CS Fixer Configurator.
In addition to PHP CS Fixer rules, Pint provides custom rules prefixed with Pint/. These rules are not enabled by default, but you may enable them in your pint.json file.
This rule formats your Blade templates, applying consistent indentation, spacing, and attribute formatting to your .blade.php files. By default, Pint does not format Blade files, so you must enable this rule in your pint.json file to opt in:
Once enabled, Pint will format your Blade templates in addition to your PHP files whenever it runs:
Alternatively, if you would like to enable this rule for a single run without modifying your pint.json file, you may use the --blade option:
Under the hood, this rule uses Prettier along with the prettier-plugin-blade and prettier-plugin-tailwindcss plugins, so Node.js must be installed on your machine. The first time you run Pint with this rule enabled, Pint will detect any missing Prettier dependencies and prompt you to install them.
This rule automatically skips files that typically rely on their own formatting, such as Laravel Boost guidelines and email views located in the resources/views/emails and resources/views/mail directories.
This rule removes all comments and docblock prose from your code, keeping only lines that contain @ annotations such as @param, @return, @var, @phpstan-type, etc:
Single-line comments and block comments without @ annotations are removed entirely. If you would like to keep a specific comment, you may prefix it with @note, @warning, or @todo:
To enable this rule, add it to your pint.json file:
This rule automatically skips files in the config directory, as configuration files typically rely on comments for documentation.
By default, Pint will inspect all .php files in your project except those in the vendor directory. If you wish to exclude more folders, you may do so using the exclude configuration option:
If you wish to exclude all files that contain a given name pattern, you may do so using the notName configuration option:
If you would like to exclude a file by providing an exact path to the file, you may do so using the notPath configuration option:
To automate linting your project with Laravel Pint, you can configure GitHub Actions to run Pint whenever new code is pushed to GitHub. First, be sure to grant "Read and write permissions" to workflows within Gi
访问原文 返回搜索 https://laravel.com/framework/docs/pint
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。