summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Houston <houstdav000@gmail.com>2021-11-09 02:53:44 -0500
committerGitHub <noreply@github.com>2021-11-09 16:53:44 +0900
commit8b3b16d71c4c683da6f3ca39662d207a3e894901 (patch)
treed221ad3ec518fcfff3c33bfe33e5e9ac5621271a
parentf37cd1fd4fc17173a98649d8a0b2f37ce7ba61cf (diff)
downloadale-8b3b16d71c4c683da6f3ca39662d207a3e894901.zip
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>
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/gofumpt.vim17
-rw-r--r--doc/ale-go.txt20
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_gofumpt_fixer.vader27
7 files changed, 71 insertions, 1 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index c6764daf..eb7d7f53 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -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'],
diff --git a/autoload/ale/fixers/gofumpt.vim b/autoload/ale/fixers/gofumpt.vim
new file mode 100644
index 00000000..99753209
--- /dev/null
+++ b/autoload/ale/fixers/gofumpt.vim
@@ -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
diff --git a/doc/ale-go.txt b/doc/ale-go.txt
index 2f1e4c1c..3ed48576 100644
--- a/doc/ale-go.txt
+++ b/doc/ale-go.txt
@@ -81,6 +81,24 @@ g:ale_go_gofmt_options *g:ale_go_gofmt_options*
===============================================================================
+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` is a `lint_file` linter, which only lints files that are
@@ -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)
===============================================================================
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 36ef83ea..0e1da319 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -182,6 +182,7 @@ Notes:
* `go mod`!!
* `go vet`!!
* `gofmt`
+ * `gofumpt`
* `goimports`
* `golangci-lint`!!
* `golangserver`
diff --git a/doc/ale.txt b/doc/ale.txt
index 6cc81784..71da263a 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -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|
diff --git a/supported-tools.md b/supported-tools.md
index b2c0ec48..ab02b006 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -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:
diff --git a/test/fixers/test_gofumpt_fixer.vader b/test/fixers/test_gofumpt_fixer.vader
new file mode 100644
index 00000000..63e04de8
--- /dev/null
+++ b/test/fixers/test_gofumpt_fixer.vader
@@ -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'
+ \}