How to automatically run Laravel Pint on file save in VSCode?

1.4k Views Asked by At

The Laravel Pint docs specifies that you can run Pint by invoking the binary located in the vendor/bin directory like this:

./vendor/bin/pint

I would like to set this up in VSCode so that it automatically runs Pint when a specific file is saved. How can I achieve this?

1

There are 1 best solutions below

1
Shaya Ulman On BEST ANSWER

One possible solution is to use an extension that let's you run commands on file saves:

For example, you can use the Run on Save extension, then in the settings.json (preferably the local one), add the following command:

"emeraldwalk.runonsave": {
  "commands": [
    {
      "match": "\\.php$",
      "cmd": "${workspaceFolder}/vendor/bin/pint ${file}"
    }
  ]
}

This should invoke Pint only on the specific file that was saved.