Configure gofumpt in Helix
masterModify your ~/.config/helix/languages.toml to enable gofumpt via gopls.
[language-server.gopls.config]
"formatting.gofumpt" = truerepository·master·Indexed 26 days ago
https://github.com/mvdan/gofumptA stricter formatter for Go code that acts as a drop-in replacement for gofmt. It enforces additional formatting rules to improve code consistency while remaining backwards compatible with gofmt output. Requires Go 1.25 or later.
Modify your ~/.config/helix/languages.toml to enable gofumpt via gopls.
[language-server.gopls.config]
"formatting.gofumpt" = trueTo use gofumpt in VS Code, enable the language server and configure the gopls settings to use gofumpt formatting.
"go.useLanguageServer": true,
"gopls": {
"formatting.gofumpt": true,
},For lsp-mode users (version 8.0.0+):
(setq lsp-go-use-gofumpt t)For eglot users:
(setq-default eglot-workspace-configuration
'((:gopls . ((gofumpt . t)))))Install the gofumpt CLI tool using go install. It requires Go 1.25 or later.
go install mvdan.cc/gofumpt@latestInstall the Sublime Text LSP extension and enable gofumpt in the LSP package settings, ensuring lsp_format_on_save is true.
"lsp_format_on_save": true,
"clients":
{
"gopls":
{
"enabled": true,
"initializationOptions": {
"gofumpt": true,
}
}
}If using nvim-lspconfig, pass the gofumpt setting to the gopls setup.
require('lspconfig').gopls.setup({
settings = {
gopls = {
gofumpt = true
}
}
})GoLand requires a custom File Watcher since it does not use gopls. After installing gofumpt, add a new File Watcher with a Custom Template using these settings:
.go filesgofumpt executable-w $FilePath$$FilePath$$ProjectFileDir$GOROOT=$GOROOT$;GOPATH=$GOPATH$;PATH=$GoBinDirs$Note: Disable all checkboxes in the 'Advanced' section to avoid unnecessary runs.
Set the gofumpt option in the LSP settings by providing it in initialization_options for gopls.
"lsp": {
"gopls": {
"initialization_options": {
"gofumpt": true
}
}
}To report a formatting bug or get debugging information, insert the //gofumpt:diagnose comment into your Go file. When you run gofumpt on that file, the comment will be rewritten to include version and language information.
//gofumpt:diagnose
package p-d flag to see the differences between the current file content and the formatted output without modifying the files. This is useful for CI/CD pipelines to check if code adheres to the style guide. When -d is used and differences are found, the program exits with a non-zero exit code.-extra flag. This allows for more aggressive formatting, such as grouping parameters or specific return statement styles. The available rules are passed as a comma-separated list.-w flag to overwrite the source files with the formatted version. Note that -w cannot be used when formatting standard input.