1

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?

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
Shaya Ulman
  • 1,299
  • 1
  • 12
  • 24

1 Answers1

2

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.

Shaya Ulman
  • 1,299
  • 1
  • 12
  • 24
  • 2
    Personal preference, but I would use the `--dirty` flag to avoid accidentally formatting files. `"${workspaceFolder/vendor/bin/pint --dirty ${file}"` – wizardzeb Jul 31 '23 at 14:57