4

How to set up PhpStorm code style (Code alignment) to work with Laravel Pint?

Is there a scheme for Pint Code Style and code alignment in a file?

Does PhpStorm's Laravel Code Style is up to date?

The docs says that it uses Laravel preset.

By default, Pint uses the Laravel preset, which fixes issues by following the opinionated coding style of Laravel.

But, when I set the Code style from Laravel, some fixes are made again by Pint.

enter image description here

Example:

Laravel default:

(!$var)

Pint:

(! $var)

Is there some set of rules or schema for PhpStorm to work the same as Pint?

mare96
  • 3,749
  • 1
  • 16
  • 28
  • 1
    As I can see, there's no such thing as Pint Code Style, as Pint is simply a tool. Perhaps you can use an IDE editorconfig integration (see https://www.jetbrains.com/help/phpstorm/settings-code-style.html#EditorConfig) and add this editorconfig file to your project: https://github.com/laravel/laravel/blob/9.x/.editorconfig – Dmitrii Jul 25 '22 at 16:45
  • 1
    @Dmitrii *"...as Pint is simply a tool"* But it has own rules/config -- Laravel ones. From https://laravel.com/docs/9.x/pint -- *"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**."* Based on the screenshot/code fragment, the question might be -- "does PhpStorm's Laravel Code Style is up to date?" – LazyOne Jul 26 '22 at 10:01
  • @LazyOne good question. My PhpStorm version is 2022.1.4 (Updated yesterday), so I'll update my question too with your observation. – mare96 Jul 26 '22 at 10:21
  • 2
    @mare96 *"Is there a scheme for Pint Code Style and code alignment in a file?"* No. And TBH unlikely to be (since Pint uses Laravel rules). The same as why you do not see PHP-CS-Fixer schema there. So you will have to use `Set from... | Laravel` and adjust any differences there by manually changing the most appropriate options. – LazyOne Jul 26 '22 at 10:39
  • @mare96 Then you can **try** using a Pint instead of PHP-CS-Fixer at `Settings (Preferences on macOS) | PHP | Quality Tools`. That's if they both use the same parameters of course (have not used Pint yet, so do not know). If that's not the case, consider making a Feature Request ticket at the PhpStorm Issue Tracker at https://youtrack.jetbrains.com/issues/WI **P.S.** You may integrate it using External Tools (manual invocation) or File Watcher (automatic on save) -- try and see how it will work. – LazyOne Jul 26 '22 at 10:44
  • Enable pint in phpStorm on save action: https://gilbitron.me/blog/running-laravel-pint-in-phpstorm/ – mare96 Oct 19 '22 at 18:16

0 Answers0