-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
580bd36
commit 7b62a15
Showing
6 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
" Author: Sascha Grunert <mail@saschagrunert.de> | ||
" Description: Adds support of golangci-lint | ||
|
||
call ale#Set('go_golangci_lint_options', '--enable-all') | ||
call ale#Set('go_golangci_lint_executable', 'golangci-lint') | ||
call ale#Set('go_golangci_lint_package', 0) | ||
|
||
function! ale_linters#go#golangci_lint#GetCommand(buffer) abort | ||
let l:filename = expand('#' . a:buffer . ':t') | ||
let l:options = ale#Var(a:buffer, 'go_golangci_lint_options') | ||
let l:lint_package = ale#Var(a:buffer, 'go_golangci_lint_package') | ||
|
||
if l:lint_package | ||
return ale#path#BufferCdString(a:buffer) | ||
\ . '%e run ' | ||
\ . l:options | ||
endif | ||
|
||
return ale#path#BufferCdString(a:buffer) | ||
\ . '%e run ' | ||
\ . ale#util#EscapePCRE(l:filename) | ||
\ . ' ' . l:options | ||
endfunction | ||
|
||
function! ale_linters#go#golangci_lint#GetMatches(lines) abort | ||
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?:?:?:?\s\*?(.+)$' | ||
|
||
return ale#util#GetMatches(a:lines, l:pattern) | ||
endfunction | ||
|
||
function! ale_linters#go#golangci_lint#Handler(buffer, lines) abort | ||
let l:dir = expand('#' . a:buffer . ':p:h') | ||
let l:output = [] | ||
|
||
for l:match in ale_linters#go#golangci_lint#GetMatches(a:lines) | ||
" l:match[1] will already be an absolute path, output from | ||
" golangci_lint | ||
call add(l:output, { | ||
\ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]), | ||
\ 'lnum': l:match[2] + 0, | ||
\ 'col': l:match[3] + 0, | ||
\ 'type': 'E', | ||
\ 'text': l:match[4], | ||
\}) | ||
endfor | ||
|
||
return l:output | ||
endfunction | ||
|
||
call ale#linter#Define('go', { | ||
\ 'name': 'golangci-lint', | ||
\ 'executable_callback': ale#VarFunc('go_golangci_lint_executable'), | ||
\ 'command_callback': 'ale_linters#go#golangci_lint#GetCommand', | ||
\ 'callback': 'ale_linters#go#golangci_lint#Handler', | ||
\ 'lint_file': 1, | ||
\}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
test/command_callback/test_golangci_lint_command_callback.vader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Before: | ||
call ale#assert#SetUpLinterTest('go', 'golangci_lint') | ||
call ale#test#SetFilename('test.go') | ||
|
||
After: | ||
call ale#assert#TearDownLinterTest() | ||
|
||
Execute(The golangci-lint defaults should be correct): | ||
AssertLinter 'golangci-lint', | ||
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' | ||
\ . ale#Escape('golangci-lint') | ||
\ . ' run ' . ale#util#EscapePCRE(expand('%' . ':t')) | ||
\ . ' --enable-all' | ||
|
||
Execute(The golangci-lint callback should use a configured executable): | ||
let b:ale_go_golangci_lint_executable = 'something else' | ||
|
||
AssertLinter 'something else', | ||
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' | ||
\ . ale#Escape('something else') | ||
\ . ' run ' . ale#util#EscapePCRE(expand('%' . ':t')) | ||
\ . ' --enable-all' | ||
|
||
Execute(The golangci-lint callback should use configured options): | ||
let b:ale_go_golangci_lint_options = '--foobar' | ||
|
||
AssertLinter 'golangci-lint', | ||
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' | ||
\ . ale#Escape('golangci-lint') | ||
\ . ' run ' . ale#util#EscapePCRE(expand('%' . ':t')) | ||
\ . ' --foobar' | ||
|
||
Execute(The golangci-lint `lint_package` option should use the correct command): | ||
let b:ale_go_golangci_lint_package = 1 | ||
|
||
AssertLinter 'golangci-lint', | ||
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' | ||
\ . ale#Escape('golangci-lint') . ' run --enable-all' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Before: | ||
runtime ale_linters/go/golangci_lint.vim | ||
|
||
After: | ||
call ale#linter#Reset() | ||
|
||
Execute (The golangci-lint handler should handle names with spaces): | ||
" We can't test Windows paths with the path resovling on Linux, but we can | ||
" test the regex. | ||
AssertEqual | ||
\ [ | ||
\ [ | ||
\ 'C:\something\file with spaces.go', | ||
\ '12', | ||
\ '3', | ||
\ 'expected ''package'', found ''IDENT'' gibberish (staticcheck)', | ||
\ ], | ||
\ [ | ||
\ 'C:\something\file with spaces.go', | ||
\ '37', | ||
\ '5', | ||
\ 'expected ''package'', found ''IDENT'' gibberish (golint)', | ||
\ ], | ||
\ ], | ||
\ map(ale_linters#go#golangci_lint#GetMatches([ | ||
\ 'C:\something\file with spaces.go:12:3: expected ''package'', found ''IDENT'' gibberish (staticcheck)', | ||
\ 'C:\something\file with spaces.go:37:5: expected ''package'', found ''IDENT'' gibberish (golint)', | ||
\ ]), 'v:val[1:4]') | ||
|
||
Execute (The golangci-lint handler should handle paths correctly): | ||
call ale#test#SetFilename('app/test.go') | ||
|
||
let file = ale#path#GetAbsPath(expand('%:p:h'), 'test.go') | ||
|
||
AssertEqual | ||
\ [ | ||
\ { | ||
\ 'lnum': 12, | ||
\ 'col': 3, | ||
\ 'text': 'expected ''package'', found ''IDENT'' gibberish (staticcheck)', | ||
\ 'type': 'E', | ||
\ 'filename': ale#path#Simplify(expand('%:p:h') . '/test.go'), | ||
\ }, | ||
\ { | ||
\ 'lnum': 37, | ||
\ 'col': 5, | ||
\ 'text': 'expected ''package'', found ''IDENT'' gibberish (golint)', | ||
\ 'type': 'E', | ||
\ 'filename': ale#path#Simplify(expand('%:p:h') . '/test.go'), | ||
\ }, | ||
\ ], | ||
\ ale_linters#go#golangci_lint#Handler(bufnr(''), [ | ||
\ file . ':12:3: expected ''package'', found ''IDENT'' gibberish (staticcheck)', | ||
\ file . ':37:5: expected ''package'', found ''IDENT'' gibberish (golint)', | ||
\ ]) |