Skip to content

Commit

Permalink
feat: add gofumpt formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
rcholla committed Oct 7, 2023
1 parent 6b95e25 commit 8d14894
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions lua/guard-collection/formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ M.gofmt = {
stdin = true,
}

M.gofumpt = {
cmd = 'gofumpt',
stdin = true,
}

M.golines = {
cmd = 'golines',
args = { '--max-len=80' },
Expand Down
28 changes: 28 additions & 0 deletions test/formatter/gofumpt_spec.lua
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down

0 comments on commit 8d14894

Please sign in to comment.