diff options
Diffstat (limited to 'ale_linters')
-rw-r--r-- | ale_linters/c/clang.vim | 2 | ||||
-rw-r--r-- | ale_linters/c/gcc.vim | 2 | ||||
-rw-r--r-- | ale_linters/coffee/coffee.vim | 2 | ||||
-rw-r--r-- | ale_linters/cpp/clang.vim | 2 | ||||
-rw-r--r-- | ale_linters/cpp/clangtidy.vim | 2 | ||||
-rw-r--r-- | ale_linters/cpp/gcc.vim | 2 | ||||
-rw-r--r-- | ale_linters/go/gobuild.vim | 226 | ||||
-rw-r--r-- | ale_linters/php/php.vim | 4 | ||||
-rw-r--r-- | ale_linters/puppet/puppetlint.vim | 28 | ||||
-rw-r--r-- | ale_linters/sh/shellcheck.vim | 2 | ||||
-rw-r--r-- | ale_linters/swift/swiftlint.vim | 2 | ||||
-rw-r--r-- | ale_linters/vim/vint.vim | 2 |
12 files changed, 74 insertions, 202 deletions
diff --git a/ale_linters/c/clang.vim b/ale_linters/c/clang.vim index 603e2b75..489245da 100644 --- a/ale_linters/c/clang.vim +++ b/ale_linters/c/clang.vim @@ -22,5 +22,5 @@ call ale#linter#Define('c', { \ 'output_stream': 'stderr', \ 'executable': 'clang', \ 'command_callback': 'ale_linters#c#clang#GetCommand', -\ 'callback': 'ale#handlers#HandleGCCFormat', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/c/gcc.vim b/ale_linters/c/gcc.vim index a487909c..c89fae72 100644 --- a/ale_linters/c/gcc.vim +++ b/ale_linters/c/gcc.vim @@ -22,5 +22,5 @@ call ale#linter#Define('c', { \ 'output_stream': 'stderr', \ 'executable': 'gcc', \ 'command_callback': 'ale_linters#c#gcc#GetCommand', -\ 'callback': 'ale#handlers#HandleGCCFormat', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/coffee/coffee.vim b/ale_linters/coffee/coffee.vim index ac9ef79e..f263a163 100644 --- a/ale_linters/coffee/coffee.vim +++ b/ale_linters/coffee/coffee.vim @@ -19,5 +19,5 @@ call ale#linter#Define('coffee', { \ 'executable_callback': 'ale_linters#coffee#coffee#GetExecutable', \ 'command_callback': 'ale_linters#coffee#coffee#GetCommand', \ 'output_stream': 'stderr', -\ 'callback': 'ale#handlers#HandleGCCFormat', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/cpp/clang.vim b/ale_linters/cpp/clang.vim index 9915ac3a..e8af6dc2 100644 --- a/ale_linters/cpp/clang.vim +++ b/ale_linters/cpp/clang.vim @@ -19,5 +19,5 @@ call ale#linter#Define('cpp', { \ 'output_stream': 'stderr', \ 'executable': 'clang++', \ 'command_callback': 'ale_linters#cpp#clang#GetCommand', -\ 'callback': 'ale#handlers#HandleGCCFormat', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/cpp/clangtidy.vim b/ale_linters/cpp/clangtidy.vim index 11088c43..6b72e1f5 100644 --- a/ale_linters/cpp/clangtidy.vim +++ b/ale_linters/cpp/clangtidy.vim @@ -14,5 +14,5 @@ call ale#linter#Define('cpp', { \ 'output_stream': 'stdout', \ 'executable': 'clang-tidy', \ 'command_callback': 'ale_linters#cpp#clangtidy#GetCommand', -\ 'callback': 'ale#handlers#HandleGCCFormat', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/cpp/gcc.vim b/ale_linters/cpp/gcc.vim index ad1b93b7..f2261c4f 100644 --- a/ale_linters/cpp/gcc.vim +++ b/ale_linters/cpp/gcc.vim @@ -28,5 +28,5 @@ call ale#linter#Define('cpp', { \ 'output_stream': 'stderr', \ 'executable': 'g++', \ 'command_callback': 'ale_linters#cpp#gcc#GetCommand', -\ 'callback': 'ale#handlers#HandleGCCFormat', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/go/gobuild.vim b/ale_linters/go/gobuild.vim index 0bac9f26..a40565d6 100644 --- a/ale_linters/go/gobuild.vim +++ b/ale_linters/go/gobuild.vim @@ -1,4 +1,4 @@ -" Author: Joshua Rubin <joshua@rubixconsulting.com> +" Author: Joshua Rubin <joshua@rubixconsulting.com>, Ben Reedy <https://github.com/breed808> " Description: go build for Go files " inspired by work from dzhou121 <dzhou121@gmail.com> @@ -11,198 +11,55 @@ function! ale_linters#go#gobuild#GoEnv(buffer) abort return 'go env GOPATH GOROOT' endfunction -let s:SplitChar = has('unix') ? ':' : ':' - -" get a list of all source directories from $GOPATH and $GOROOT -function! s:SrcDirs() abort - let l:paths = split(s:go_env.GOPATH, s:SplitChar) - call add(l:paths, s:go_env.GOROOT) - - return l:paths -endfunction - -" figure out from a directory like `/home/user/go/src/some/package` that the -" import for that path is simply `some/package` -function! s:PackageImportPath(buffer) abort - let l:bufname = resolve(bufname(a:buffer)) - let l:pkgdir = fnamemodify(l:bufname, ':p:h') - - for l:path in s:SrcDirs() - let l:path = l:path . '/src/' - - if stridx(l:pkgdir, l:path) == 0 - return l:pkgdir[strlen(l:path):] - endif - endfor - - return '' -endfunction - -" get the package info data structure using `go list` -function! ale_linters#go#gobuild#GoList(buffer, goenv_output) abort - if !empty(a:goenv_output) +function! ale_linters#go#gobuild#GetCommand(buffer, goenv_output) abort + if !exists('s:go_env') let s:go_env = { \ 'GOPATH': a:goenv_output[0], \ 'GOROOT': a:goenv_output[1], \} endif - return 'go list -json ' . shellescape(s:PackageImportPath(a:buffer)) -endfunction - -let s:filekeys = [ -\ 'GoFiles', -\ 'CgoFiles', -\ 'CFiles', -\ 'CXXFiles', -\ 'MFiles', -\ 'HFiles', -\ 'FFiles', -\ 'SFiles', -\ 'SwigFiles', -\ 'SwigCXXFiles', -\ 'SysoFiles', -\ 'TestGoFiles', -\ 'XTestGoFiles', -\] - -" get the go and test go files from the package -" will return empty list if the package has any cgo or other invalid files -function! s:PkgFiles(pkginfo) abort - let l:files = [] - - for l:key in s:filekeys - if has_key(a:pkginfo, l:key) - call extend(l:files, a:pkginfo[l:key]) - endif - endfor - - " resolve the path of the file relative to the window directory - return map(l:files, 'shellescape(fnamemodify(resolve(a:pkginfo.Dir . ''/'' . v:val), '':p''))') -endfunction - -function! ale_linters#go#gobuild#CopyFiles(buffer, golist_output) abort - let l:tempdir = tempname() - let l:temppkgdir = l:tempdir . '/src/' . s:PackageImportPath(a:buffer) - call mkdir(l:temppkgdir, 'p', 0700) - - if empty(a:golist_output) - return 'echo ' . shellescape(l:tempdir) - endif - - " parse the output - let l:pkginfo = json_decode(join(a:golist_output, "\n")) - - " get all files for the package - let l:files = s:PkgFiles(l:pkginfo) - - " copy the files to a temp directory with $GOPATH structure - return 'cp ' . join(l:files, ' ') . ' ' . shellescape(l:temppkgdir) . ' && echo ' . shellescape(l:tempdir) -endfunction - -function! ale_linters#go#gobuild#GetCommand(buffer, copy_output) abort - " If for some reason we don't get any output from the last command, stop - " here. - if empty(a:copy_output) - return '' - endif - - let l:tempdir = a:copy_output[0] - let l:importpath = s:PackageImportPath(a:buffer) - - " write the a:buffer and any modified buffers from the package to the tempdir - for l:bufnum in range(1, bufnr('$')) - " ignore unloaded buffers (can't be a:buffer or a modified buffer) - if !bufloaded(l:bufnum) - continue - endif - - " ignore non-Go buffers - if getbufvar(l:bufnum, '&ft') !=# 'go' - continue - endif - - " only consider buffers other than a:buffer if they have the same import - " path as a:buffer and are modified - if l:bufnum != a:buffer - if s:PackageImportPath(l:bufnum) !=# l:importpath - continue - endif - - if !getbufvar(l:bufnum, '&mod') - continue - endif - endif - - call writefile(getbufline(l:bufnum, 1, '$'), l:tempdir . '/src/' . s:PkgFile(l:bufnum)) - endfor - - let l:gopaths = [ l:tempdir ] - call extend(l:gopaths, split(s:go_env.GOPATH, s:SplitChar)) - - return 'GOPATH=' . shellescape(join(l:gopaths, s:SplitChar)) . ' go test -c -o /dev/null ' . shellescape(l:importpath) -endfunction - -function! s:PkgFile(buffer) abort - let l:bufname = resolve(bufname(a:buffer)) - let l:importpath = s:PackageImportPath(a:buffer) - let l:fname = fnamemodify(l:bufname, ':t') - - return l:importpath . '/' . l:fname + return 'GOPATH=' . s:go_env.GOPATH . ' go test -c -o /dev/null %s' endfunction -function! s:FindBuffer(file) abort - for l:buffer in range(1, bufnr('$')) - if !buflisted(l:buffer) - continue - endif - - let l:pkgfile = s:PkgFile(l:buffer) - - if a:file =~ '/' . l:pkgfile . '$' - return l:buffer - endif - endfor - - return -1 -endfunction - -let s:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+' -let s:handler_pattern = '^\(' . s:path_pattern . '\):\(\d\+\):\?\(\d\+\)\?: \(.\+\)$' - -let s:multibuffer = 0 - function! ale_linters#go#gobuild#Handler(buffer, lines) abort - let l:output = [] - - for l:line in a:lines - let l:match = matchlist(l:line, s:handler_pattern) - - if len(l:match) == 0 - continue - endif - - let l:buffer = s:FindBuffer(l:match[1]) - - if l:buffer == -1 - continue - endif - - if !s:multibuffer && l:buffer != a:buffer - " strip lines from other buffers - continue - endif - - call add(l:output, { - \ 'bufnr': l:buffer, - \ 'lnum': l:match[2] + 0, - \ 'col': l:match[3] + 0, - \ 'text': l:match[4], - \ 'type': 'E', - \}) - endfor + return ale_linters#go#gobuild#HandleGoBuildErrors(a:buffer, bufname(a:buffer), a:lines) +endfunction - return l:output +function! ale_linters#go#gobuild#HandleGoBuildErrors(buffer, full_filename, lines) abort + " Matches patterns line the following: + " + " file.go:27: missing argument for Printf("%s"): format reads arg 2, have only 1 args + " file.go:53:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) + " file.go:5:2: expected declaration, found 'STRING' "log" + + " go test returns relative paths so use tail of filename as part of pattern matcher + let l:filename = fnamemodify(a:full_filename, ':t') + let l:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+' + let l:pattern = '^' . l:path_pattern . ':\(\d\+\):\?\(\d\+\)\?:\? \(.\+\)$' + let l:output = [] + + for l:line in a:lines + let l:match = matchlist(l:line, l:pattern) + + " Omit errors from imported go packages + if len(l:match) == 0 || l:line !~ l:filename + continue + endif + + " vcol is Needed to indicate that the column is a character. + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': l:match[1] + 0, + \ 'vcol': 0, + \ 'col': l:match[2] + 0, + \ 'text': l:match[3], + \ 'type': 'E', + \ 'nr': -1, + \}) + endfor + + return l:output endfunction call ale#linter#Define('go', { @@ -210,9 +67,8 @@ call ale#linter#Define('go', { \ 'executable': 'go', \ 'command_chain': [ \ {'callback': 'ale_linters#go#gobuild#GoEnv', 'output_stream': 'stdout'}, -\ {'callback': 'ale_linters#go#gobuild#GoList', 'output_stream': 'stdout'}, -\ {'callback': 'ale_linters#go#gobuild#CopyFiles', 'output_stream': 'stdout'}, \ {'callback': 'ale_linters#go#gobuild#GetCommand', 'output_stream': 'stderr'}, \ ], \ 'callback': 'ale_linters#go#gobuild#Handler', +\ 'lint_file': 1, \}) diff --git a/ale_linters/php/php.vim b/ale_linters/php/php.vim index ebc21ea3..3f354de5 100644 --- a/ale_linters/php/php.vim +++ b/ale_linters/php/php.vim @@ -1,11 +1,11 @@ -" Author: Spencer Wood <https://github.com/scwood> +" Author: Spencer Wood <https://github.com/scwood>, Adriaan Zonnenberg <amz@adriaan.xyz> " Description: This file adds support for checking PHP with php-cli function! ale_linters#php#php#Handle(buffer, lines) abort " Matches patterns like the following: " " PHP Parse error: syntax error, unexpected ';', expecting ']' in - on line 15 - let l:pattern = '\vParse error:\s+(.+unexpected ''(.+)%(expecting.+)@<!''.*|.+) in - on line (\d+)' + let l:pattern = '\vPHP %(Fatal|Parse) error:\s+(.+unexpected ''(.+)%(expecting.+)@<!''.*|.+) in - on line (\d+)' let l:output = [] diff --git a/ale_linters/puppet/puppetlint.vim b/ale_linters/puppet/puppetlint.vim index 05745cfe..902480d8 100644 --- a/ale_linters/puppet/puppetlint.vim +++ b/ale_linters/puppet/puppetlint.vim @@ -1,10 +1,26 @@ -" Author: Alexander Olofsson <alexander.olofsson@liu.se> +" Author: Alexander Olofsson <alexander.olofsson@liu.se>, Robert Flechtner <flechtner@chemmedia.de> +" Description: puppet-lint for puppet files + +let g:ale_puppet_puppetlint_executable = +\ get(g:, 'ale_puppet_puppetlint_executable', 'puppet-lint') + +let g:ale_puppet_puppetlint_options = +\ get(g:, 'ale_puppet_puppetlint_options', '--no-autoloader_layout-check') + +function! ale_linters#puppet#puppetlint#GetExecutable(buffer) abort + return g:ale_puppet_puppetlint_executable +endfunction + +function! ale_linters#puppet#puppetlint#GetCommand(buffer) abort + return ale_linters#puppet#puppetlint#GetExecutable(a:buffer) + \ . ' ' . g:ale_puppet_puppetlint_options + \ . ' --log-format "-:%{line}:%{column}: %{kind}: [%{check}] %{message}"' + \ . ' %t' +endfunction call ale#linter#Define('puppet', { \ 'name': 'puppetlint', -\ 'executable': 'puppet-lint', -\ 'command': 'puppet-lint --no-autoloader_layout-check' -\ . ' --log-format "-:%{line}:%{column}: %{kind}: [%{check}] %{message}"' -\ . ' %t', -\ 'callback': 'ale#handlers#HandleGCCFormat', +\ 'executable_callback': 'ale_linters#puppet#puppetlint#GetExecutable', +\ 'command_callback': 'ale_linters#puppet#puppetlint#GetCommand', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/sh/shellcheck.vim b/ale_linters/sh/shellcheck.vim index bb556460..5f932b19 100644 --- a/ale_linters/sh/shellcheck.vim +++ b/ale_linters/sh/shellcheck.vim @@ -48,5 +48,5 @@ call ale#linter#Define('sh', { \ 'name': 'shellcheck', \ 'executable_callback': 'ale_linters#sh#shellcheck#GetExecutable', \ 'command_callback': 'ale_linters#sh#shellcheck#GetCommand', -\ 'callback': 'ale#handlers#HandleGCCFormat', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/swift/swiftlint.vim b/ale_linters/swift/swiftlint.vim index aaa77a9f..b7dcf935 100644 --- a/ale_linters/swift/swiftlint.vim +++ b/ale_linters/swift/swiftlint.vim @@ -5,5 +5,5 @@ call ale#linter#Define('swift', { \ 'name': 'swiftlint', \ 'executable': 'swiftlint', \ 'command': 'swiftlint lint --use-stdin', -\ 'callback': 'ale#handlers#HandleGCCFormat', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) diff --git a/ale_linters/vim/vint.vim b/ale_linters/vim/vint.vim index 4b2c5445..821a0bdc 100644 --- a/ale_linters/vim/vint.vim +++ b/ale_linters/vim/vint.vim @@ -20,5 +20,5 @@ call ale#linter#Define('vim', { \ . s:enable_neovim \ . s:format \ . ' %t', -\ 'callback': 'ale#handlers#HandleGCCFormat', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \}) |