I have enjoyed using the go-template prettier plugin to highlight and format html templates (Thanks!) and I would like to also use it to edit json templates that I am writing to setup a Hugo API. I tried the obvious - added “*.json” to plugins.overrides.files but that does not seem to work. Any help in getting this wonderful plugin to work with json files?
I am sorry, I probably did not explain my problem clearly. My question is not about formatting JSON with prettier. My question was about formatting (and highlighting) a Hugo template that generates JSON output.
The lookup order for such templates all have the .json extension and VSCode treats the Hugo template as a JSON file, despite the overrides configured in my Hugo template plugin (go-template) configuration (in .prettierrc).
With that background, my question is - “Why are overrides in the go-template config not overriding?”. If you still think this is a question for generic support forums, I will try there, but I doubt that is the case here.
Your question has obviously nothing to do with Hugo, but with VSCode and the prettier/prettier-go-template. Better ask their developers or raise an issue on their GitHub repo.
you have to tell VSCODE to use prettier for the files. and you could restrict that to .json files in .prettierrc beneath layouts folder (see the rest example above)
formatter selection by folder is not possible in VSCODE
{
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
# EITHER
"editor.defaultFormatter": "esbenp.prettier-vscode",
# OR
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
#
highlighting
Highlighting is NOT done by prettier/plugin itself but by VSCODE
First, a huge Thank You for taking the time to address an issue that might well be marginally OT.
So setting the VSCode setting editor.defaultFormatteralmost worked. I mean - the setting removed all the prettier errors (as displayed in the Output Tab of the Terminal window) and left only the JSON validation errors behind. So I took the last small step and set json.validate.enable = false for my Hugo workspace only. That removed all errors and everything works like I wanted. That will obviously restrict my ability to debug generated JSON files in the public folder, but I can live (dangerously?) with that
Glad to see someone chimed in with an answer; to me this is very much on topic/relevant re. Hugo. I would be lost if I hadn’t had the go-template plugin to format my Hugo templates.