Prettier Go Template
raw JSON → 0.0.15 verified Sat Apr 25 auth: no javascript
Prettier plugin for formatting Go and GoHugo templates. Current stable version 0.0.15, compatible with Prettier ^3.0.0. Requires Node >=14. Automatically formats .gohtml, .gotmpl, .go.tmpl, .tmpl, .tpl, .html.tmpl files. Supports bracket spacing option. For .html files, parser override is needed. No other dependencies beyond Prettier. Actively maintained.
Common errors
error Cannot find module 'prettier-plugin-go-template' ↓
cause Plugin not installed or not in same scope as prettier.
fix
Run: npm install --save-dev prettier prettier-plugin-go-template
error Couldn't resolve parser "go-template" ↓
cause The plugin is not loaded or parser name is incorrect.
fix
Add 'plugins': ['prettier-plugin-go-template'] to .prettierrc.
Warnings
breaking Starting with Prettier 3, auto-discovery has been removed. Configuration is required. ↓
fix Add 'plugins': ['prettier-plugin-go-template'] to .prettierrc.
gotcha For GoHugo .html files, the default HTML parser is used unless overridden. Mixed templates may break. ↓
fix Add parser override in .prettierrc: overrides [{ files: ['*.html'], options: { parser: 'go-template' } }].
gotcha Global and local installations must match. VSCode may not detect plugin if installed in different scope. ↓
fix Install both prettier and plugin either both globally or both locally.
Install
npm install prettier-plugin-go-template yarn add prettier-plugin-go-template pnpm add prettier-plugin-go-template Quickstart
npm install --save-dev prettier prettier-plugin-go-template
# .prettierrc
{
"plugins": ["prettier-plugin-go-template"],
"goTemplateBracketSpacing": true
}