Hoping someone here has had this issue and solved formatting these templates. Currently, my setup will format on save, but in a terrible way. Example, say I have some variables defined like so:
{{/* Variables */}}
{{- $respSizes := slice "375" "640" "960" "1280" "1600" "1920" -}}
{{- $src := .Params.image -}}
{{- $alt := .Params.alt -}}
{{- $cap := .Params.caption -}}
{{- $dataSzes := "(min-width: 1024px) 50vw, 100vw" -}}
When I save, if everything in the file looks good with no errors, it will format lines joined together, but at parts that make no sense, sometimes causing Hugo errors
{{/* Variables */}} {{- $respSizes := slice "375" "640" "960" "1280" "1600"
"1920" -}} {{- $src := .Params.image -}} {{- $alt := .Params.alt -}} {{- $cap :=
.Params.caption -}} {{- $dataSzes := "(min-width: 1024px) 50vw, 100vw" -}}
This happens in any HTML file with some Go templating in it. And in any part of the file.
Using LazyVim, I have gotmpl
and go
installed and in ensure_installed
in Treesitter. I have prettier formatting with Conform. Prettier RC file currently like so
{
"singleQuote": false,
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "ignore",
"singleAttributePerLine": true,
{
"plugins": ["prettier-plugin-go-template"],
"overrides":
[{ "files": ["*.html"], "options": { "parser": "go-template" } }],
},
}
Any help or being pointed in the right direction is very much appreciated! Thanks