Search code examples
laravelpint

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


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?


Solution

  • 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.