mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-22 03:51:26 +08:00
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
This commit is contained in:
@@ -246,6 +246,11 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['go'],
|
\ 'suggested_filetypes': ['go'],
|
||||||
\ 'description': 'Fix Go files imports with goimports.',
|
\ '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': {
|
\ 'gomod': {
|
||||||
\ 'function': 'ale#fixers#gomod#Fix',
|
\ 'function': 'ale#fixers#gomod#Fix',
|
||||||
\ 'suggested_filetypes': ['gomod'],
|
\ 'suggested_filetypes': ['gomod'],
|
||||||
|
|||||||
21
autoload/ale/fixers/golines.vim
Normal file
21
autoload/ale/fixers/golines.vim
Normal file
@@ -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
|
||||||
@@ -133,6 +133,23 @@ g:ale_go_langserver_options *g:ale_go_langserver_options*
|
|||||||
`-gocodecompletion` option is ignored because it is handled automatically
|
`-gocodecompletion` option is ignored because it is handled automatically
|
||||||
by the |g:ale_completion_enabled| variable.
|
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*
|
golint *ale-go-golint*
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ Notes:
|
|||||||
* `goimports`
|
* `goimports`
|
||||||
* `golangci-lint`!!
|
* `golangci-lint`!!
|
||||||
* `golangserver`
|
* `golangserver`
|
||||||
|
* `golines`
|
||||||
* `golint`
|
* `golint`
|
||||||
* `gometalinter`!!
|
* `gometalinter`!!
|
||||||
* `gopls`
|
* `gopls`
|
||||||
|
|||||||
@@ -2750,6 +2750,7 @@ documented in additional help files.
|
|||||||
gofmt.................................|ale-go-gofmt|
|
gofmt.................................|ale-go-gofmt|
|
||||||
golangci-lint.........................|ale-go-golangci-lint|
|
golangci-lint.........................|ale-go-golangci-lint|
|
||||||
golangserver..........................|ale-go-golangserver|
|
golangserver..........................|ale-go-golangserver|
|
||||||
|
golines...............................|ale-go-golines|
|
||||||
golint................................|ale-go-golint|
|
golint................................|ale-go-golint|
|
||||||
gometalinter..........................|ale-go-gometalinter|
|
gometalinter..........................|ale-go-gometalinter|
|
||||||
gopls.................................|ale-go-gopls|
|
gopls.................................|ale-go-gopls|
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ formatting.
|
|||||||
* [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:
|
||||||
|
* [golines](https://github.com/segmentio/golines)
|
||||||
* [golint](https://godoc.org/github.com/golang/lint)
|
* [golint](https://godoc.org/github.com/golang/lint)
|
||||||
* [gometalinter](https://github.com/alecthomas/gometalinter) :warning: :floppy_disk:
|
* [gometalinter](https://github.com/alecthomas/gometalinter) :warning: :floppy_disk:
|
||||||
* [gopls](https://github.com/golang/go/wiki/gopls)
|
* [gopls](https://github.com/golang/go/wiki/gopls)
|
||||||
|
|||||||
54
test/fixers/test_golines_fixer_callback.vader
Normal file
54
test/fixers/test_golines_fixer_callback.vader
Normal file
@@ -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(''))
|
||||||
Reference in New Issue
Block a user