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-04-17 18:29:02 -04:00
|
|
|
let l:automatic_stubs_dir = ale#path#FindNearestDirectory(a:buffer, 'stubs')
|
2017-01-20 12:30:23 -05:00
|
|
|
" 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-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-04-29 12:33:18 -04:00
|
|
|
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):?(\d+)?: ([^:]+): (.+)$'
|
2017-01-20 12:30:23 -05:00
|
|
|
let l:output = []
|
|
|
|
|
2017-04-17 19:35:53 -04:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-01-20 12:30:23 -05:00
|
|
|
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, {
|
|
|
|
\ '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
|
|
|
\})
|