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
|
|
|
|
2017-04-16 00:24:08 +00:00
|
|
|
function! ale_linters#python#mypy#GetCommand(buffer) abort
|
2017-04-17 22:29:02 +00:00
|
|
|
let l:automatic_stubs_dir = ale#path#FindNearestDirectory(a:buffer, 'stubs')
|
2017-01-20 17:30:23 +00: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 19:40:57 +00:00
|
|
|
return 'mypy --show-column-numbers '
|
2017-04-16 00:24:08 +00:00
|
|
|
\ . ale#Var(a:buffer, 'python_mypy_options')
|
2017-02-11 19:40:57 +00:00
|
|
|
\ . ' %t'
|
2016-12-31 00:06:49 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-04-16 00:24:08 +00:00
|
|
|
function! ale_linters#python#mypy#Handle(buffer, lines) abort
|
2017-01-20 17:30:23 +00: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 16:33:18 +00:00
|
|
|
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):?(\d+)?: ([^:]+): (.+)$'
|
2017-01-20 17:30:23 +00:00
|
|
|
let l:output = []
|
|
|
|
|
2017-04-17 23:35:53 +00:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-01-20 17:30:23 +00: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 12:35:54 +00:00
|
|
|
call ale#linter#Define('python', {
|
2016-12-31 00:06:49 +00:00
|
|
|
\ '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
|
|
|
\})
|