![]() You can also set up the code styling rules that everyone should follow, and you can use Pint to validate that too. You can set up workflows that can detect code styling issues before merging a pull request. Pint could be a very handy tool especially when you are working with teams. You can find more details on configuring Pint according to your requirements on the official Laravel Pint documentation. You can use the below command, it will fix the code styling for only the files that have uncommitted changes according to Git./vendor/bin/pint -dirty You can run pint to fix your code style just by issuing the below command./vendor/bin/pintīased on your preference you may only want to update the files that are changed. However, if you want to install it on your existing project, you may install Laravel Pint via Composer: composer require laravel/pint -dev Formatting code using Pintīy adding the composer package, the pint binary is added to your vendor/bin directory. So you can use it without any effort on configuring it. ![]() I was thinking to add the process for installing Pint on the Laravel project, but as I was doing research for this post, I found that the new Laravel projects already have it installed by default. How to install and use Laravel Pint on your project? With the clarification on why you need Pint on your project, let’s see how you can install and use Laravel Pint on your project. So Pint or basically any linting tool takes this responsibility off your shoulders and allows you to think and work on solutions rather than wasting time on code styling and formatting. And you should not keep going back and forth on formatting your code here and there, also not to mention to review those linting/formatting manually before the commits or merging a pull request. Your role as a developer on a project is to work on the solution that adds value to the project. Pint is installed by default on the new Laravel applications, so you can use it immediately as soon as you create a new Laravel project. It is built on top of PHP-CS-Fixer and makes it simple to ensure your code style is clean and consistent. github/workflows/laravel-pint.Laravel Pint is a first-party package from the Laravel core team for PHP code style fixing. Commits any changes to the repo using the Git Auto Commit action.Runs Laravel Pint, fixing all code styling issues.Checks out the code from the repository.Here’s the GitHub Actions workflow I’ve implemented to run Laravel Pint each time code in a pull request is updated. Automating Laravel Pint in your CI with GitHub Actions In this case, it shows that 1 style issue was fixed in my User model. Pint will scan each of your files for potential style updates, and produce output like this when complete: Laravel Pint ouput, showing 1 style issue fixed. Or, if you’re using Laravel Sail, run this instead: sail bin pint To run Pint, and update your PHP code style, run. Or, if you’re using Laravel Sail: sail composer require laravel/pint -dev Running Pint on your local machine: To add Pint to your existing project, install the composer package as a development dependency: composer require laravel/pint -dev We’ve already laid the foundation freeing you to create without sweating the small things. It can also style for PSR12 or Symfony standards, if you’d prefer. Laravel is a PHP web application framework with expressive, elegant syntax. Under the hood, it’s still PHP-CS-Fixer, but just pre-configured to style things “The Laravel Way”. The team at Laravel have released a new product called Laravel Pint, which is an opinionated code style fixer. ![]() I’ve used PHP-CS-Fixer to do this for many years. It makes the code easier to read, which you’ll be thankful for, either when doing a code review, or having to go back and update your own code later. Keeping your application’s code styled consistently is important, especially when the project has multiple developers. I upgraded my CI Pipeline to use Laravel Pint today, and I love it!
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |