Skip to content

mridang/dprint-go

Repository files navigation

dprint-plugin-goat

dprint-plugin-goat provides five formatter plugins for dprint: one for Go files using Go's canonical formatter, one for shell scripts using shfmt, one for Terraform/HCL files using HashiCorp's hclwrite, one for CUE files using the official CUE formatter, and one for Protobuf files using a Buf-compatible formatter. All are compiled to WebAssembly with TinyGo and plug into dprint like any other plugin.

Why?

Using dprint plugins lets you keep a single, consistent formatting workflow across polyglot repos. The gofmt plugin applies go/format so your Go code follows the exact same rules as gofmt, the shfmt plugin formats shell scripts with the same power as the standalone shfmt tool, and the tffmt plugin formats Terraform and HCL files using the same logic as terraform fmt.

Usage

gofmt

Add the gofmt plugin to your dprint configuration to format Go files.

{
  "$schema": "https://dprint.dev/schemas/v0.json",
  "plugins": [
    "https://github.com/mridang/dprint-goat/releases/download/v1.0.0/gofmt.wasm"
  ],
  "includes": [
    "**/*.go"
  ],
  "excludes": [
    "**/vendor"
  ]
}
dprint fmt --log-level=debug

Options

This plugin mirrors gofmt and does not add custom options. If you pass an override config from dprint, it is accepted but ignored.

shfmt

Add the shfmt plugin to your dprint configuration to format shell scripts.

{
  "$schema": "https://dprint.dev/schemas/v0.json",
  "plugins": [
    "https://github.com/mridang/dprint-goat/releases/download/v1.0.0/shfmt.wasm"
  ],
  "includes": [
    "**/*.sh"
  ]
}
dprint fmt --log-level=debug

Options

This plugin mirrors shfmt and supports standard dprint indentation settings (tabs vs spaces, indent width). Additional shfmt-specific options are not exposed.

tffmt

Add the tffmt plugin to your dprint configuration to format Terraform files.

{
  "$schema": "https://dprint.dev/schemas/v0.json",
  "plugins": [
    "https://github.com/mridang/dprint-goat/releases/download/v1.0.0/tffmt.wasm"
  ],
  "includes": [
    "**/*.tf"
  ]
}
dprint fmt --log-level=debug

Options

This plugin mirrors terraform fmt and does not add custom options. If you pass an override config from dprint, it is accepted but ignored.

cuefmt

Add the cuefmt plugin to your dprint configuration to format CUE files.

{
  "$schema": "https://dprint.dev/schemas/v0.json",
  "plugins": [
    "https://github.com/mridang/dprint-goat/releases/download/v1.0.0/cuefmt.wasm"
  ],
  "includes": [
    "**/*.cue"
  ]
}
dprint fmt --log-level=debug

Options

This plugin uses cuelang.org/go/cue/format and supports standard dprint indentation settings (tabs vs spaces, indent width).

protofmt

Add the protofmt plugin to your dprint configuration to format Protobuf files.

{
  "$schema": "https://dprint.dev/schemas/v0.json",
  "plugins": [
    "https://github.com/mridang/dprint-goat/releases/download/v1.0.0/protofmt.wasm"
  ],
  "includes": [
    "**/*.proto"
  ]
}
dprint fmt --log-level=debug

Options

This plugin implements a custom formatter designed to match buf format style and supports standard dprint indentation settings.

Caveats

None.

Contributing

Contributions are welcome! If you find a bug or have suggestions for improvement, please open an issue or submit a pull request.

License

Apache License 2.0 © 2025 Mridang Agarwalla