mirror of
https://github.com/dense-analysis/ale
synced 2025-02-05 23:12:39 +00:00
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:
parent
f37cd1fd4f
commit
8b3b16d71c
@ -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'],
|
||||
|
17
autoload/ale/fixers/gofumpt.vim
Normal file
17
autoload/ale/fixers/gofumpt.vim
Normal 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
|
@ -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)
|
||||
|
||||
===============================================================================
|
||||
|
@ -182,6 +182,7 @@ Notes:
|
||||
* `go mod`!!
|
||||
* `go vet`!!
|
||||
* `gofmt`
|
||||
* `gofumpt`
|
||||
* `goimports`
|
||||
* `golangci-lint`!!
|
||||
* `golangserver`
|
||||
|
@ -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|
|
||||
|
@ -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:
|
||||
|
27
test/fixers/test_gofumpt_fixer.vader
Normal file
27
test/fixers/test_gofumpt_fixer.vader
Normal 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'
|
||||
\}
|
Loading…
Reference in New Issue
Block a user