summaryrefslogtreecommitdiff
path: root/ale_linters/python
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-01-20 17:30:23 +0000
committerw0rp <devw0rp@gmail.com>2017-01-20 17:30:34 +0000
commit9820899b9e09dba27a1fc0867fde3012769a01e7 (patch)
treece9e86e043087c765851fc0e779f934926ccc353 /ale_linters/python
parentea438be5c108aba328db790ab0d08531ea74abd1 (diff)
downloadale-9820899b9e09dba27a1fc0867fde3012769a01e7.zip
Improve mypy handling a little bit more
Diffstat (limited to 'ale_linters/python')
-rw-r--r--ale_linters/python/mypy.vim51
1 files changed, 48 insertions, 3 deletions
diff --git a/ale_linters/python/mypy.vim b/ale_linters/python/mypy.vim
index a7461443..934961b1 100644
--- a/ale_linters/python/mypy.vim
+++ b/ale_linters/python/mypy.vim
@@ -1,17 +1,62 @@
-" Author: Keith Smiley <k@keith.so>
+" Author: Keith Smiley <k@keith.so>, w0rp <devw0rp@gmail.com>
" Description: mypy support for optional python typechecking
let g:ale_python_mypy_options = get(g:, 'ale_python_mypy_options', '')
function! g:ale_linters#python#mypy#GetCommand(buffer) abort
- return g:ale#util#stdin_wrapper
+ let l:automatic_stubs_dir = ale#util#FindNearestDirectory(a:buffer, 'stubs')
+ " TODO: Add Windows support
+ let l:automatic_stubs_command = (has('unix') && !empty(l:automatic_stubs_dir))
+ \ ? 'MYPYPATH=' . l:automatic_stubs_dir . ' '
+ \ : ''
+
+ return l:automatic_stubs_command
+ \ . g:ale#util#stdin_wrapper
\ . ' .py mypy --show-column-numbers '
\ . g:ale_python_mypy_options
endfunction
+function! g:ale_linters#python#mypy#Handle(buffer, lines) abort
+ " Look for lines like the following:
+ "
+ " file.py:4: error: No library stub file for module 'django.db'
+ "
+ " Lines like these should be ignored below:
+ "
+ " file.py:4: note: (Stub files are from https://github.com/python/typeshed)
+ let l:pattern = '^.\+:\(\d\+\):\?\(\d\+\)\?: \([^:]\+\): \(.\+\)$'
+ let l:output = []
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ if l:match[4] =~# 'Stub files are from'
+ " The lines telling us where to get stub files from make it so
+ " we can't read the actual errors, so exclude them.
+ continue
+ endif
+
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:match[1] + 0,
+ \ 'vcol': 0,
+ \ 'col': l:match[2] + 0,
+ \ 'text': l:match[4],
+ \ 'type': l:match[3] =~# 'error' ? 'E' : 'W',
+ \ 'nr': -1,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
call g:ale#linter#Define('python', {
\ 'name': 'mypy',
\ 'executable': 'mypy',
\ 'command_callback': 'ale_linters#python#mypy#GetCommand',
-\ 'callback': 'ale#handlers#HandleGCCFormat',
+\ 'callback': 'ale_linters#python#mypy#Handle',
\})