Skip to content

Commit

Permalink
feat(prettier): add target to style Go templates
Browse files Browse the repository at this point in the history
Use package prettier-plugin-go-template[1] for *.html and *.tmpl files.

[1]: https://www.npmjs.com/package/prettier-plugin-go-template
  • Loading branch information
radhus committed Sep 10, 2024
1 parent 81a2228 commit 1ef2b39
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tools/sgprettier/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import (
const packageJSONContent = `{
"devDependencies": {
"@einride/prettier-config": "2.1.0",
"prettier": "3.0.3"
"prettier": "3.0.3",
"prettier-plugin-go-template": "0.0.15"
}
}`

const prettierConfigContent = `module.exports = {
plugins: [require("prettier-plugin-go-template")],
...require("@einride/prettier-config"),
}`

Expand All @@ -31,6 +33,20 @@ func Command(ctx context.Context, args ...string) *exec.Cmd {
return sg.Command(ctx, sg.FromBinDir(name), args...)
}

func FormatGoTemplates(ctx context.Context) *exec.Cmd {
args := []string{
"--config",
prettierrc,
"--parser",
"go-template",
"--write",
"**/*.html",
"**/*.tmpl",
"!" + sg.FromSageDir(),
}
return Command(ctx, args...)
}

func FormatMarkdownCommand(ctx context.Context) *exec.Cmd {
args := []string{
"--config",
Expand Down

0 comments on commit 1ef2b39

Please sign in to comment.