I'm assuming you already have installed Laravel Pint on your project, if not, follow the official installation guide
To set up the integration with Laravel Pint, you have 2 options:
- VS Code Plugin: Just install Laravel Pint Formatter
- Creating VS Code task
- Create a .vscode directory in the root of your project;
- Create a file
tasks.json
to the .vscode directory
{
"version": "2.0.0",
"tasks": [
{
"label": "Pint Auto Formatter",
"type": "shell",
"command": "./vendor/bin/pint --dirty",
"problemMatcher": [],
"presentation": {
"reveal": "silent"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
The command above will work on the uncommitted files only. If you want to validate all your files, just remove the
--dirty
instruction.
- Access the Keyboard Shortcuts panel. You can do this by navigating through the menu via
File
→Preferences
→Keyboard Shortcuts
or by using the shortcut Ctrl+K Ctrl+S. - Once the panel is open, click on the file icon located at the top to access the JSON file containing the keyboard shortcuts.
- With the JSON file open, you will need to insert specific lines of code to define the new keyboard shortcut for Laravel Pint. Unfortunately, the text you provided ends before specifying these lines. However, typically, you would add a JSON object that specifies the command to run Laravel Pint, along with your desired key combination. For example:
[
{
"key": "ctrl+shift+l",
"command": "workbench.action.tasks.runTask",
"args": "Pint Auto Formatter"
}
]
You can define custom rules for your Pint validation. Just create a pint.json file on your project root, here is an example:
{
"preset": "laravel",
"rules": {
"simplified_null_return": true,
"braces": false,
"new_with_braces": {
"anonymous_class": false,
"named_class": false
}
}
}