mirror of
https://github.com/dense-analysis/ale.git
synced 2026-08-12 19:06:53 +08: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:
@@ -246,6 +246,11 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['go'],
|
\ 'suggested_filetypes': ['go'],
|
||||||
\ 'description': 'Fix Go files with go fmt.',
|
\ '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': {
|
\ 'goimports': {
|
||||||
\ 'function': 'ale#fixers#goimports#Fix',
|
\ 'function': 'ale#fixers#goimports#Fix',
|
||||||
\ 'suggested_filetypes': ['go'],
|
\ 'suggested_filetypes': ['go'],
|
||||||
|
|||||||
@@ -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
|
||||||
+19
-1
@@ -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.
|
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*
|
golangci-lint *ale-go-golangci-lint*
|
||||||
|
|
||||||
@@ -148,7 +166,7 @@ g:ale_go_golines_options *g:ale_go_golines_options*
|
|||||||
Type: |String|
|
Type: |String|
|
||||||
Default: ''
|
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)
|
--max-length=100 (lines above 100 characters will be wrapped)
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ Notes:
|
|||||||
* `go mod`!!
|
* `go mod`!!
|
||||||
* `go vet`!!
|
* `go vet`!!
|
||||||
* `gofmt`
|
* `gofmt`
|
||||||
|
* `gofumpt`
|
||||||
* `goimports`
|
* `goimports`
|
||||||
* `golangci-lint`!!
|
* `golangci-lint`!!
|
||||||
* `golangserver`
|
* `golangserver`
|
||||||
|
|||||||
@@ -2748,6 +2748,7 @@ documented in additional help files.
|
|||||||
bingo.................................|ale-go-bingo|
|
bingo.................................|ale-go-bingo|
|
||||||
gobuild...............................|ale-go-gobuild|
|
gobuild...............................|ale-go-gobuild|
|
||||||
gofmt.................................|ale-go-gofmt|
|
gofmt.................................|ale-go-gofmt|
|
||||||
|
gofumpt...............................|ale-go-gofumpt|
|
||||||
golangci-lint.........................|ale-go-golangci-lint|
|
golangci-lint.........................|ale-go-golangci-lint|
|
||||||
golangserver..........................|ale-go-golangserver|
|
golangserver..........................|ale-go-golangserver|
|
||||||
golines...............................|ale-go-golines|
|
golines...............................|ale-go-golines|
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ formatting.
|
|||||||
* [go mod](https://golang.org/cmd/go/) :warning: :floppy_disk:
|
* [go mod](https://golang.org/cmd/go/) :warning: :floppy_disk:
|
||||||
* [go vet](https://golang.org/cmd/vet/) :floppy_disk:
|
* [go vet](https://golang.org/cmd/vet/) :floppy_disk:
|
||||||
* [gofmt](https://golang.org/cmd/gofmt/)
|
* [gofmt](https://golang.org/cmd/gofmt/)
|
||||||
|
* [gofumpt](https://github.com/mvdan/gofumpt)
|
||||||
* [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports) :warning:
|
* [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports) :warning:
|
||||||
* [golangci-lint](https://github.com/golangci/golangci-lint) :warning: :floppy_disk:
|
* [golangci-lint](https://github.com/golangci/golangci-lint) :warning: :floppy_disk:
|
||||||
* [golangserver](https://github.com/sourcegraph/go-langserver) :warning:
|
* [golangserver](https://github.com/sourcegraph/go-langserver) :warning:
|
||||||
|
|||||||
@@ -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'
|
||||||
|
\}
|
||||||
Reference in New Issue
Block a user