Laravel Pint - Code style fixer

Description

Laravel Pint is a code-style fixer that’s included with the latest version of the Laravel framework by default.

To run Pint use the following command while the current directory is set to an existing Laravel framework.

./vendor/bin/pint

To make the command easier to type up I created an alias that I would use.

alias pint="./vendor/bin/pint"

Running the Pint command will automatically go through the Laravel project and apply fixes to the files.

Or the command can be added locally to a Laravel project by adding the following script commands in the composer.json file.

"scripts": {
    "pint": "./vendor/bin/pint --test",
    "pint-apply": "./vendor/bin/pint"
}

Coding Standards

No configuration is needed as the default coding standard set up for Laravel Pint is “laravel”.

The coding standards supported by Pint are Laravel, PER, PSR-12, and Symfony.

Also, coding rules can be changed but again not needed as default rules will be set up already.

How to change the default coding standard

To change the coding standard and apply it to a project, create a pint.json file inside of the project root folder and add the following content which will set the coding standard to PSR12.

{
    "preset": "psr12"
}

Commands

To check for errors run the following.

./vendor/bin/pint --test

To apply code style changes.

./vendor/bin/pint

To apply code style changes and output changes to the terminal add a -v flag.

./vendor/bin/pint -v

To check and view files that fail the code style check.

./vendor/bin/pint --test

To apply changes to uncommitted Git files, if no uncommitted files are available then no file changes.

./vendor/bin/pint --dirty

Extras

There is a VSCode extension that integrates Laravel Pint called vscode-laravel-pint.