diff options
author | pigfrown <pigfrown@protonmail.com> | 2021-08-09 02:13:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-09 10:13:43 +0900 |
commit | 836125391a75094e4c7e157664bb00ffb86a8b37 (patch) | |
tree | fd0f7e13ffcfd8710a12fe0e498b97a1f24d6ad9 | |
parent | d6f5fb69ad49ad8377fafb2fdfe80819d39f5f01 (diff) | |
download | ale-836125391a75094e4c7e157664bb00ffb86a8b37.zip |
Adds fixer for golines (#3862)
* Adds fixer for golines
* Repositions golines docs to be in alphabetical order
* Fixes golines doc tag
* Fixes formatting for golines docs
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/golines.vim | 21 | ||||
-rw-r--r-- | doc/ale-go.txt | 17 | ||||
-rw-r--r-- | doc/ale-supported-languages-and-tools.txt | 1 | ||||
-rw-r--r-- | doc/ale.txt | 3 | ||||
-rw-r--r-- | supported-tools.md | 1 | ||||
-rw-r--r-- | test/fixers/test_golines_fixer_callback.vader | 54 |
7 files changed, 101 insertions, 1 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 597dfe6c..15a6632d 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 imports with goimports.', \ }, +\ 'golines': { +\ 'function': 'ale#fixers#golines#Fix', +\ 'suggested_filetypes': ['go'], +\ 'description': 'Fix Go file long lines with golines', +\ }, \ 'gomod': { \ 'function': 'ale#fixers#gomod#Fix', \ 'suggested_filetypes': ['gomod'], diff --git a/autoload/ale/fixers/golines.vim b/autoload/ale/fixers/golines.vim new file mode 100644 index 00000000..9326f482 --- /dev/null +++ b/autoload/ale/fixers/golines.vim @@ -0,0 +1,21 @@ +" Author Pig Frown <pigfrown@protonmail.com> +" Description: Fix Go files long lines with golines" + +call ale#Set('go_golines_executable', 'golines') + +call ale#Set('go_golines_options', '') + +function! ale#fixers#golines#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'go_golines_executable') + let l:options = ale#Var(a:buffer, 'go_golines_options') + let l:env = ale#go#EnvString(a:buffer) + + if !executable(l:executable) + return 0 + endif + + return { + \ 'command': l:env . ale#Escape(l:executable) + \ . (empty(l:options) ? '' : ' ' . l:options) + \} +endfunction diff --git a/doc/ale-go.txt b/doc/ale-go.txt index 7813c7b3..2f1e4c1c 100644 --- a/doc/ale-go.txt +++ b/doc/ale-go.txt @@ -133,6 +133,23 @@ g:ale_go_langserver_options *g:ale_go_langserver_options* `-gocodecompletion` option is ignored because it is handled automatically by the |g:ale_completion_enabled| variable. +=============================================================================== +golines *ale-go-golines* + +g:ale_go_golines_executable *g:ale_go_lines_executable* + *b:ale_go_lines_executable* + Type: |String| + Default: `'golines'` + + Location of the golines binary file + +g:ale_go_golines_options *g:ale_go_golines_options* + *b:ale_go_golines_options* + Type: |String| + Default: '' + + Additional options passed to the golines command. By default golines has + --max-length=100 (lines above 100 characters will be wrapped) =============================================================================== golint *ale-go-golint* diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index fa089bbb..0247a743 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -183,6 +183,7 @@ Notes: * `goimports` * `golangci-lint`!! * `golangserver` + * `golines` * `golint` * `gometalinter`!! * `gopls` diff --git a/doc/ale.txt b/doc/ale.txt index e871f1ff..85646dd9 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1,4 +1,4 @@ -*ale.txt* Plugin to lint and fix files asynchronously +*ale.txt* Plugin to lint and fix files asynchronously *ale* ALE - Asynchronous Lint Engine @@ -2750,6 +2750,7 @@ documented in additional help files. gofmt.................................|ale-go-gofmt| golangci-lint.........................|ale-go-golangci-lint| golangserver..........................|ale-go-golangserver| + golines...............................|ale-go-golines| golint................................|ale-go-golint| gometalinter..........................|ale-go-gometalinter| gopls.................................|ale-go-gopls| diff --git a/supported-tools.md b/supported-tools.md index 863e7a6a..ff75c5ad 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -192,6 +192,7 @@ formatting. * [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: + * [golines](https://github.com/segmentio/golines) * [golint](https://godoc.org/github.com/golang/lint) * [gometalinter](https://github.com/alecthomas/gometalinter) :warning: :floppy_disk: * [gopls](https://github.com/golang/go/wiki/gopls) diff --git a/test/fixers/test_golines_fixer_callback.vader b/test/fixers/test_golines_fixer_callback.vader new file mode 100644 index 00000000..87e53c88 --- /dev/null +++ b/test/fixers/test_golines_fixer_callback.vader @@ -0,0 +1,54 @@ +Before: + Save g:ale_go_golines_executable + Save g:ale_go_golines_options + Save g:ale_go_go111module + + " Use an invalid global executable, so we don't match it. + let g:ale_go_golines_executable = 'xxxinvalid' + let g:ale_go_golines_options = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + unlet! b:ale_go_go111module + + call ale#test#RestoreDirectory() + +Execute(The golines callback should return 0 when the executable isn't executable): + AssertEqual + \ 0, + \ ale#fixers#golines#Fix(bufnr('')) + + +Execute(The golines callback should return the correct default values): + let g:ale_go_golines_executable = has('win32') ? 'cmd' : 'echo' + + AssertEqual + \ { + \ 'command': ale#Escape(g:ale_go_golines_executable), + \ }, + \ ale#fixers#golines#Fix(bufnr('')) + +Execute(The golines callback should include custom golines options): + let g:ale_go_golines_executable = has('win32') ? 'cmd' : 'echo' + let g:ale_go_golines_options = "--max-len --shorten-comments" + + AssertEqual + \ { + \ 'command': ale#Escape(g:ale_go_golines_executable) + \ . ' ' . g:ale_go_golines_options, + \ }, + \ ale#fixers#golines#Fix(bufnr('')) + +Execute(The golines callback should support Go environment variables): + let g:ale_go_golines_executable = has('win32') ? 'cmd' : 'echo' + let g:ale_go_go111module = 'off' + + AssertEqual + \ { + \ 'command': ale#Env('GO111MODULE', 'off') + \ . ale#Escape(g:ale_go_golines_executable) + \ }, + \ ale#fixers#golines#Fix(bufnr('')) |