2017-01-20 12:30:23 -05:00
|
|
|
" Author: Keith Smiley <k@keith.so>, w0rp <devw0rp@gmail.com>
|
2016-12-30 19:06:49 -05:00
|
|
|
" Description: mypy support for optional python typechecking
|
|
|
|
|
2017-01-18 05:31:36 -05:00
|
|
|
let g:ale_python_mypy_options = get(g:, 'ale_python_mypy_options', '')
|
2016-12-30 19:06:49 -05:00
|
|
|
|
2017-04-15 20:24:08 -04:00
|
|
|
function! ale_linters#python#mypy#GetCommand(buffer) abort
|
2017-01-20 12:30:23 -05: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 14:40:57 -05:00
|
|
|
return 'mypy --show-column-numbers '
|
2017-04-15 20:24:08 -04:00
|
|
|
\ . ale#Var(a:buffer, 'python_mypy_options')
|
2017-02-11 14:40:57 -05:00
|
|
|
\ . ' %t'
|
2016-12-30 19:06:49 -05:00
|
|
|
endfunction
|
|
|
|
|
2017-02-04 14:47:37 -05:00
|
|
|
let s:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'
|
|
|
|
|
2017-04-15 20:24:08 -04:00
|
|
|
function! ale_linters#python#mypy#Handle(buffer, lines) abort
|
2017-01-20 12:30:23 -05:00
|
|
|
" 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 14:47:37 -05:00
|
|
|
let l:pattern = '^' . s:path_pattern . ':\(\d\+\):\?\(\d\+\)\?: \([^:]\+\): \(.\+\)$'
|
2017-01-20 12:30:23 -05: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
|
|
|
|
|
2017-04-15 08:35:54 -04:00
|
|
|
call ale#linter#Define('python', {
|
2016-12-30 19:06:49 -05:00
|
|
|
\ 'name': 'mypy',
|
|
|
|
\ 'executable': 'mypy',
|
|
|
|
\ 'command_callback': 'ale_linters#python#mypy#GetCommand',
|
2017-01-20 12:30:23 -05:00
|
|
|
\ 'callback': 'ale_linters#python#mypy#Handle',
|
2016-12-30 19:06:49 -05:00
|
|
|
\})
|