Core prettier does not support PHP1, and thus neither does the plugin for VSCode/VSCodium. Luckily the designers of prettier seems to have thought of this and implemented a plugin system2.
According to the prettier-vscode repo, all you need to do to use a plugin is to add it and prettier to your package.json3
So for php support your package.json would need to contain:
{
"devDependencies": {
"@prettier/plugin-php": "0.14.3",
"prettier": "2.0.5"
}
}
Answer from fredrik on Stack OverflowCore prettier does not support PHP1, and thus neither does the plugin for VSCode/VSCodium. Luckily the designers of prettier seems to have thought of this and implemented a plugin system2.
According to the prettier-vscode repo, all you need to do to use a plugin is to add it and prettier to your package.json3
So for php support your package.json would need to contain:
{
"devDependencies": {
"@prettier/plugin-php": "0.14.3",
"prettier": "2.0.5"
}
}
Prettier for HTML, CSS, and JavaScript files
change your settings.json
"editor.defaultFormatter": "esbenp.prettier-vscode",
// add this code
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
}
The settings use Intelephense as the formatter for PHP files and use Prettier as the formatter for all other files.
Now I use Shift + Alt + F to format the files like everybody else.
if you dont know ho to open setting.json lets see : I usually just press ctrl + , to get to settings and then click the "Open Settings (JSON)" icon that appears in the top right hand corner under the title bar Here's another option... VS Code: How to open settings.json file? How can I open Visual Studio Code's 'settings.json' file?
Is there a way to prettify PHP code using VS Code?
How to install Prettier PHP Plugin in Visual Studio Code
I don't like prettier
Nobody loves what prettier does to their syntax
Everyone loves what prettier does to their coworkers' syntax
More on reddit.comprettier-standard - format with prettier with standard.js rules
Videos
Hi, I'm new to VS Code.
Is there a way to prettify my PHP code? Any extensions or a hidden function to do the job?
Thank you very much! :)
» npm install @prettier/plugin-php
» npm install @prettier/plugin-php