forked from github-mirrors/ale
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:
parent
d6f5fb69ad
commit
836125391a
|
@ -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'],
|
||||
|
|
|
@ -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
|
||||
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*
|
||||
|
|
|
@ -183,6 +183,7 @@ Notes:
|
|||
* `goimports`
|
||||
* `golangci-lint`!!
|
||||
* `golangserver`
|
||||
* `golines`
|
||||
* `golint`
|
||||
* `gometalinter`!!
|
||||
* `gopls`
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(''))
|
Loading…
Reference in New Issue