-
At the root of the repository, create a
.prettierrc
file:{ "plugins": ["prettier-plugin-go-template"], "overrides": [ { "files": ["*.html"], "options": { "printWidth": 240, "parser": "go-template", "singleQuote": false } } ], "goTemplateBracketSpacing": true }
-
Install the Prettier VS Code extension. Execute in terminal:
code --install-extension esbenp.prettier-vscode
-
Install
prettier
andprettier-plugin-go-template
withnpm
, globally:npm install -g prettier prettier-plugin-go-template
-
Configure the Prettier plugin so it uses the globally (and extension-enhanced) Prettier. In VS Code settings, write this value for the "Prettier Path" value:
/opt/homebrew/lib/node_modules/prettier/index.cjs
-
Check the "Format on save" option in VS Code settings.
-
Enjoy!
If the steps above don't work, here is another trick, a bit dirtier:
-
Go to your
Developement
folder in your home (the root for all your developement stuff). For me, it's:cd ~/Documents/Developement
-
In the terminal, create a fake NPM package in this directory, and let all the default information.
npm init
-
Install only `` in this fake NPM package:
npm i prettier-plugin-go-template --save-dev
-
Create a
.prettierrc
file in this folder.{ "plugins": ["prettier-plugin-go-template"], "overrides": [ { "files": ["*.html"], "options": { "printWidth": 240, "parser": "go-template", "singleQuote": false } } ], "goTemplateBracketSpacing": true }
-
Enjoy!