diff --git a/README.md b/README.md index cd7c150..bc9613f 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ - [ ] [fish_indent](https://fishshell.com/docs/current/cmds/fish_indent.html) - [ ] [fnlfmt](https://git.sr.ht/~technomancy/fnlfmt) - [ ] [gofmt](https://pkg.go.dev/cmd/gofmt) +- [x] [gofumpt](https://pkg.go.dev/mvdan.cc/gofumpt) - [ ] [golines](https://pkg.go.dev/github.com/segmentio/golines) - [ ] [google-java-format](https://github.com/google/google-java-format) - [ ] [isort](https://github.com/PyCQA/isort) diff --git a/lua/guard-collection/formatter.lua b/lua/guard-collection/formatter.lua index c66dd9f..8fecac6 100644 --- a/lua/guard-collection/formatter.lua +++ b/lua/guard-collection/formatter.lua @@ -59,6 +59,11 @@ M.gofmt = { stdin = true, } +M.gofumpt = { + cmd = 'gofumpt', + stdin = true, +} + M.golines = { cmd = 'golines', args = { '--max-len=80' }, diff --git a/test/formatter/gofumpt_spec.lua b/test/formatter/gofumpt_spec.lua new file mode 100644 index 0000000..231e2ee --- /dev/null +++ b/test/formatter/gofumpt_spec.lua @@ -0,0 +1,28 @@ +describe('gofumpt', function() + it('can format', function() + local ft = require('guard.filetype') + ft('go'):fmt('gofumpt') + require('guard').setup() + + local formatted = require('test.formatter.helper').test_with('go', { + [[package main]], + [[]], + [[ import "fmt" ]], + [[]], + [[func main() {]], + [[ x:= 1;]], + [[ fmt.Println(x);]], + [[}]], + }) + assert.are.same({ + [[package main]], + [[]], + [[import "fmt"]], + [[]], + [[func main() {]], + [[ x := 1]], + [[ fmt.Println(x)]], + [[}]], + }, formatted) + end) +end) diff --git a/test/setup.sh b/test/setup.sh index 45e34b9..7110c69 100644 --- a/test/setup.sh +++ b/test/setup.sh @@ -7,7 +7,7 @@ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" sudo apt-get install -qqq \ clang-format clang-tidy fish elixir & luarocks install luacheck & -go install github.com/segmentio/golines@latest & +go install github.com/segmentio/golines@latest mvdan.cc/gofumpt@latest & pip -qqq install autopep8 black djhtml flake8 isort pylint yapf codespell ruff & npm install -g --silent \ prettier @fsouza/prettierd sql-formatter shellcheck shfmt &