Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niklaspor/prettier-plugin-go-template
Fixes prettier formatting for go templates 🐹
https://github.com/niklaspor/prettier-plugin-go-template
gohugo golang-template hugo prettier
Last synced: 2 days ago
JSON representation
Fixes prettier formatting for go templates 🐹
- Host: GitHub
- URL: https://github.com/niklaspor/prettier-plugin-go-template
- Owner: NiklasPor
- License: mit
- Created: 2020-06-05T17:59:43.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-07-26T13:18:10.000Z (over 1 year ago)
- Last Synced: 2025-01-26T20:04:08.135Z (2 days ago)
- Topics: gohugo, golang-template, hugo, prettier
- Language: TypeScript
- Homepage: prettier-plugin-go-template-niklaspor.vercel.app
- Size: 548 KB
- Stars: 351
- Watchers: 7
- Forks: 24
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# prettier-plugin-go-template
[![NPM Badge](https://img.shields.io/npm/v/prettier-plugin-go-template)](https://www.npmjs.com/package/prettier-plugin-go-template) [![CodeCov Badge](https://img.shields.io/codecov/c/github/niklaspor/prettier-plugin-go-template)](https://codecov.io/gh/NiklasPor/prettier-plugin-go-template) [![Contributions Badge](https://img.shields.io/github/all-contributors/niklaspor/prettier-plugin-go-template)](#contributors-)
Formatter plugin for go template files. The only peer dependency is [prettier](https://www.npmjs.com/package/prettier).
```bash
npm install --save-dev prettier prettier-plugin-go-template
```Starting with Prettier 3 auto-discovery has been removed. Configuration is required ⬇️
```json
// .prettierrc
{
"plugins": ["prettier-plugin-go-template"]
}
```The following file types will be detected automatically:
`.gohtml`, `.gotmpl`, `.go.tmpl`, `.tmpl`, `.tpl`, `.html.tmpl`
If you want to add support for `.html` read the section on it below the examples.Input
Output```html
{{ if or .Prev .Next -}}
{{ $p := where site.Pages }}
{{ end -}}
``````html
{{ if or .Prev .Next -}}
{{ $p := where site.Pages }}
{{ end -}}
```## GoHugo / `.html`
To use it with GoHugo and basic `.html` files, you'll have to override the used parser inside your `.prettierrc` file:
```json
{
"plugins": ["prettier-plugin-go-template"],
"overrides": [
{
"files": ["*.html"],
"options": {
"parser": "go-template",
},
},
],
}
```## VSCode
Make sure to always have installed **both** dependencies:
- `prettier`
- `prettier-plugin-go-template`Also make sure that they are installed inside the same scope.
Install both globally (`npm i -g`) or locally – otherwise prettier may not pick up the plugin.> Note: The global setup additional requires setting your VSCode prettier path to your global prettier path. You can read in [this issue](https://github.com/NiklasPor/prettier-plugin-go-template/issues/58#issuecomment-1085060511) how to set it up – should be doable in less than a minute if you have npm & VSCode already running.
## Additional Options
```js
// .prettierrc
{
/**
* Enables & disables spacing between go statements.
* E.g. {{ statement }} vs {{statement}}.
* Default: true
*/
"goTemplateBracketSpacing": true
}
```## Ignoring Code
#### Single Block
```html
{{if }}
{{end }}
```#### Multiline
```html
{{/* prettier-ignore-start */}}
{{if }}
Whatever.
{{else }}
Psych.
{{end }}
{{/* prettier-ignore-end */}}```
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
alqu
🐛 ⚠️ 💻
Gabriel Monteagudo
🐛
Bryan
🐛
Andreas Richter
🐛
Noah Brenner
💻 📖
silverwind
🤔
Charles Pence
🐛
Caleb Jasik
🐛 📖 💡 🤔 🚧 💬
Dan Gold
🐛
Michael Lynch
🐛
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!