2017-01-20 17:30:23 +00:00
|
|
|
" Author: Keith Smiley <k@keith.so>, w0rp <devw0rp@gmail.com>
|
2016-12-31 00:06:49 +00:00
|
|
|
" Description: mypy support for optional python typechecking
|
|
|
|
|
2017-01-18 10:31:36 +00:00
|
|
|
let g:ale_python_mypy_options = get(g:, 'ale_python_mypy_options', '')
|
2016-12-31 00:06:49 +00:00
|
|
|
|
|
|
|
function! g:ale_linters#python#mypy#GetCommand(buffer) abort
|
2017-01-20 17:30:23 +00:00
|
|
|
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 . ' '
|
|
|
|
\ : ''
|
|
|
|
|
2017-02-11 19:40:57 +00:00
|
|
|
return 'mypy --show-column-numbers '
|
2017-01-15 13:20:23 +00:00
|
|
|
\ . g:ale_python_mypy_options
|
2017-02-11 19:40:57 +00:00
|
|
|
\ . ' %t'
|
2016-12-31 00:06:49 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-02-04 19:47:37 +00:00
|
|
|
let s:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'
|
|
|
|
|
2017-01-20 17:30:23 +00:00
|
|
|
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)
|
2017-02-04 19:47:37 +00:00
|
|
|
let l:pattern = '^' . s:path_pattern . ':\(\d\+\):\?\(\d\+\)\?: \([^:]\+\): \(.\+\)$'
|
2017-01-20 17:30:23 +00:00
|
|
|
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,
|
|
|
|
\ 'col': l:match[2] + 0,
|
|
|
|
\ 'text': l:match[4],
|
|
|
|
\ 'type': l:match[3] =~# 'error' ? 'E' : 'W',
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
2016-12-31 00:06:49 +00:00
|
|
|
call g:ale#linter#Define('python', {
|
|
|
|
\ 'name': 'mypy',
|
|
|
|
\ 'executable': 'mypy',
|
|
|
|
\ 'command_callback': 'ale_linters#python#mypy#GetCommand',
|
2017-01-20 17:30:23 +00:00
|
|
|
\ 'callback': 'ale_linters#python#mypy#Handle',
|
2016-12-31 00:06:49 +00:00
|
|
|
\})
|