-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add golangci-lint #1890
Merged
Merged
Add golangci-lint #1890
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]> | ||
" 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
EscapePCRE
correct here?l:filename
doesn't seem to be a regular expression, but just a regular filename. The documentation isn't clear, but this tool also doesn't seem to accept regular expressions here:I think it should be
ale#util#EscapeVim
orale#Escape()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change it to
ale#Escape
if that works instead.