Implement gofumpt Fixer (#3968)

* Implement gofumpt Fixer

Add an implementation with test and documentation for the gofumpt go
code formatter, a stricter formatter than your standard "go fmt".

Signed-off-by: David Houston <houstdav000@gmail.com>

* Add gofumpt to ale.txt TOC

Forgot to add gofumpt to the ALE vim help Table of Contents, so do so.

Signed-off-by: David Houston <houstdav000@gmail.com>

* Fix Test Setup Method Capitalization

I had put "Setup" instead of "SetUp" for "ale#assert#SetUpFixerTests".
Fix such.

Signed-off-by: David Houston <houstdav000@gmail.com>

* Fix typos

Add a missing space, remove an extra bracket by actually running tests
locally first. Would've been smart to do that from the beginning...

Signed-off-by: David Houston <houstdav000@gmail.com>
This commit is contained in:
David Houston 2021-11-09 02:53:44 -05:00 committed by GitHub
parent f37cd1fd4f
commit 8b3b16d71c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 1 deletions

View File

@ -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'],

View File

@ -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

View File

@ -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*
@ -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)
===============================================================================

View File

@ -182,6 +182,7 @@ Notes:
* `go mod`!!
* `go vet`!!
* `gofmt`
* `gofumpt`
* `goimports`
* `golangci-lint`!!
* `golangserver`

View File

@ -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|

View File

@ -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:

View File

@ -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'
\}