Prettier Plugin Go Template screenshot

Prettier Plugin Go Template

Author Avatar Theme by Niklaspor
Updated: 26 Jul 2023
391 Stars

Fixes prettier formatting for go templates

Categories

Overview

The prettier-plugin-go-template is a formatter plugin for go template files. It is designed to work with Prettier, requiring it to be installed as a peer dependency. Starting with Prettier 3, auto-discovery has been removed, so configuration is now required. This plugin automatically detects certain file types like .gohtml, .gotmpl, .go.tmpl, .tmpl, .tpl, and .html.tmpl.

To use the plugin with GoHugo and basic .html files, you need to override the parser used in your .prettierrc file. It is recommended to have both Prettier and prettier-plugin-go-template installed globally or locally. If installed globally, you also need to set your VSCode prettier path to the global prettier path.

Features

  • Formatter plugin for go template files
  • Auto-detection of file types: .gohtml, .gotmpl, .go.tmpl, .tmpl, .tpl, .html.tmpl
  • Support for GoHugo and basic .html files
  • Configuration required with Prettier 3

Installation

To install prettier-plugin-go-template, you need to have Prettier installed as a peer dependency. You can install both globally or locally using the following command:

npm install -g prettier prettier-plugin-go-template

Make sure that Prettier and prettier-plugin-go-template are installed in the same scope. If you choose the global installation, you also need to set your VSCode prettier path to the global prettier path.

Note: For GoHugo and basic .html files, you need to override the used parser in your .prettierrc file. Additional details can be found in the issue linked above.

Summary

prettier-plugin-go-template is a formatter plugin for go template files that works with Prettier. It requires configuration and supports auto-detection of various file types. It can be installed globally or locally, and supports GoHugo and basic .html files with some additional configuration. Contributions to the project are welcome.