Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement gofumpt Fixer #3968

Merged
merged 4 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['go'],
\ 'description': 'Fix Go files with go fmt.',
\ },
\ 'gofumpt': {
\ 'function': 'ale#fixers#gofumpt#Fix',
\ 'suggested_filetypes': ['go'],
\ 'description': 'Fix Go files with gofumpt, a stricter go fmt.',
\ },
\ 'goimports': {
\ 'function': 'ale#fixers#goimports#Fix',
\ 'suggested_filetypes': ['go'],
Expand Down
17 changes: 17 additions & 0 deletions autoload/ale/fixers/gofumpt.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
" Author: David Houston <houstdav000>
" Description: A stricter gofmt implementation.

call ale#Set('go_gofumpt_executable', 'gofumpt')
call ale#Set('go_gofumpt_options', '')

function! ale#fixers#gofumpt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'go_gofumpt_executable')
let l:options = ale#Var(a:buffer, 'go_gofumpt_options')

return {
\ 'command': ale#Escape(l:executable)
\ . ale#Pad(l:options)
\ . ' -w -- %t',
\ 'read_temporary_file': 1,
\}
endfunction
20 changes: 19 additions & 1 deletion doc/ale-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ g:ale_go_gofmt_options *g:ale_go_gofmt_options*
This variable can be set to pass additional options to the gofmt fixer.


===============================================================================
gofumpt *ale-go-gofumpt*

g:ale_go_gofumpt_executable *g:ale_go_gofumpt_executable*
*b:ale_go_gofumpt_executable*
Type: |String|
Default: `'gofumpt'`

Executable to run to use as the gofumpt fixer.

g:ale_go_gofumpt_options *g:ale_go_gofumpt_options*
*b:ale_go_gofumpt_options*
Type: |String|
Default: `''`

Options to pass to the gofumpt fixer.


===============================================================================
golangci-lint *ale-go-golangci-lint*

Expand Down Expand Up @@ -148,7 +166,7 @@ g:ale_go_golines_options *g:ale_go_golines_options*
Type: |String|
Default: ''

Additional options passed to the golines command. By default golines has
Additional options passed to the golines command. By default golines has
--max-length=100 (lines above 100 characters will be wrapped)

===============================================================================
Expand Down
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Notes:
* `go mod`!!
* `go vet`!!
* `gofmt`
* `gofumpt`
* `goimports`
* `golangci-lint`!!
* `golangserver`
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2748,6 +2748,7 @@ documented in additional help files.
bingo.................................|ale-go-bingo|
gobuild...............................|ale-go-gobuild|
gofmt.................................|ale-go-gofmt|
gofumpt...............................|ale-go-gofumpt|
golangci-lint.........................|ale-go-golangci-lint|
golangserver..........................|ale-go-golangserver|
golines...............................|ale-go-golines|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ formatting.
* [go mod](https://golang.org/cmd/go/) :warning: :floppy_disk:
* [go vet](https://golang.org/cmd/vet/) :floppy_disk:
* [gofmt](https://golang.org/cmd/gofmt/)
* [gofumpt](https://github.com/mvdan/gofumpt)
* [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports) :warning:
* [golangci-lint](https://github.com/golangci/golangci-lint) :warning: :floppy_disk:
* [golangserver](https://github.com/sourcegraph/go-langserver) :warning:
Expand Down
27 changes: 27 additions & 0 deletions test/fixers/test_gofumpt_fixer.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Before:
call ale#assert#SetUpFixerTest('go', 'gofumpt')

After:
call ale#assert#TearDownFixerTest()

Execute(The gofumpt callback should return the correct default values):
AssertFixer {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('gofumpt') . ' -w -- %t'
\}

Execute(The gofumpt callback should allow custom gofumpt executables):
let g:ale_go_gofumpt_executable = 'foo/bar'

AssertFixer {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('foo/bar') . ' -w -- %t'
\}

Execute(The gofumpt callback should allow custom gofumpt options):
let g:ale_go_gofumpt_options = '--foobar'

AssertFixer {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('gofumpt') . ' --foobar -w -- %t'
\}