summaryrefslogtreecommitdiff
path: root/ale_linters/python
diff options
context:
space:
mode:
authorYauhen Kirylau <actionless.loveless@gmail.com>2018-07-26 09:41:27 +0200
committerw0rp <w0rp@users.noreply.github.com>2018-07-26 08:41:27 +0100
commit8517e901ffff5dbc4928cba64f30c26d08869733 (patch)
tree625bdb0d89b8d0778cf774176965c59f49fb86ce /ale_linters/python
parent79ffdde267323a206a96227904549c370f27decf (diff)
downloadale-8517e901ffff5dbc4928cba64f30c26d08869733.zip
Add support for 'vulture' for Python
Diffstat (limited to 'ale_linters/python')
-rw-r--r--ale_linters/python/vulture.vim84
1 files changed, 84 insertions, 0 deletions
diff --git a/ale_linters/python/vulture.vim b/ale_linters/python/vulture.vim
new file mode 100644
index 00000000..bff7d623
--- /dev/null
+++ b/ale_linters/python/vulture.vim
@@ -0,0 +1,84 @@
+" Author: Yauheni Kirylau <actionless.loveless@gmail.com>
+" Description: vulture linting for python files
+
+call ale#Set('python_vulture_executable', 'vulture')
+call ale#Set('python_vulture_options', '')
+call ale#Set('python_vulture_use_global', get(g:, 'ale_use_global_executables', 0))
+call ale#Set('python_vulture_change_directory', 1)
+
+
+" The directory to change to before running vulture
+function! s:GetDir(buffer) abort
+ let l:project_root = ale#python#FindProjectRoot(a:buffer)
+
+ return !empty(l:project_root)
+ \ ? l:project_root
+ \ : expand('#' . a:buffer . ':p:h')
+endfunction
+
+
+function! ale_linters#python#vulture#GetExecutable(buffer) abort
+ return ale#python#FindExecutable(a:buffer, 'python_vulture', ['vulture'])
+endfunction
+
+
+function! ale_linters#python#vulture#GetCommand(buffer) abort
+ let l:change_dir = ale#Var(a:buffer, 'python_vulture_change_directory')
+ \ ? ale#path#CdString(s:GetDir(a:buffer))
+ \ : ''
+
+ let l:executable = ale_linters#python#vulture#GetExecutable(a:buffer)
+
+ let l:exec_args = l:executable =~? 'pipenv$'
+ \ ? ' run vulture'
+ \ : ''
+
+ let l:lint_dest = ale#Var(a:buffer, 'python_vulture_change_directory')
+ \ ? ' .'
+ \ : ' %s'
+
+ return l:change_dir
+ \ . ale#Escape(l:executable) . l:exec_args
+ \ . ' '
+ \ . ale#Var(a:buffer, 'python_vulture_options')
+ \ . l:lint_dest
+endfunction
+
+
+function! ale_linters#python#vulture#Handle(buffer, lines) abort
+ for l:line in a:lines[:10]
+ if match(l:line, '^Traceback') >= 0
+ return [{
+ \ 'lnum': 1,
+ \ 'text': 'An exception was thrown. See :ALEDetail',
+ \ 'detail': join(a:lines, "\n"),
+ \}]
+ endif
+ endfor
+
+ " Matches patterns line the following:
+ let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+): (.*)$'
+ let l:output = []
+ let l:dir = s:GetDir(a:buffer)
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ let l:abspath = ale#path#GetAbsPath(l:dir, l:match[1])
+ let l:item = {
+ \ 'filename': l:abspath,
+ \ 'lnum': l:match[2] + 0,
+ \ 'text': l:match[3],
+ \ 'type': 'W',
+ \}
+ call add(l:output, l:item)
+ endfor
+
+ return l:output
+endfunction
+
+
+call ale#linter#Define('python', {
+\ 'name': 'vulture',
+\ 'executable_callback': 'ale_linters#python#vulture#GetExecutable',
+\ 'command_callback': 'ale_linters#python#vulture#GetCommand',
+\ 'callback': 'ale_linters#python#vulture#Handle',
+\})