Fix #680 - Use --shadow-file to check for problems with mypy while you type

This commit is contained in:
w0rp 2017-06-27 10:06:03 +01:00
parent 499bf63dc3
commit 16ba9bd680
7 changed files with 23 additions and 31 deletions

View File

@ -7,19 +7,7 @@ let g:ale_python_mypy_options = get(g:, 'ale_python_mypy_options', '')
let g:ale_python_mypy_use_global = get(g:, 'ale_python_mypy_use_global', 0)
function! ale_linters#python#mypy#GetExecutable(buffer) abort
if !ale#Var(a:buffer, 'python_mypy_use_global')
let l:virtualenv = ale#python#FindVirtualenv(a:buffer)
if !empty(l:virtualenv)
let l:ve_mypy = l:virtualenv . '/bin/mypy'
if executable(l:ve_mypy)
return l:ve_mypy
endif
endif
endif
return ale#Var(a:buffer, 'python_mypy_executable')
return ale#python#FindExecutable(a:buffer, 'python_mypy', ['/bin/mypy'])
endfunction
function! ale_linters#python#mypy#GetCommand(buffer) abort
@ -33,7 +21,7 @@ function! ale_linters#python#mypy#GetCommand(buffer) abort
\ . ale#Escape(l:executable)
\ . ' --show-column-numbers '
\ . ale#Var(a:buffer, 'python_mypy_options')
\ . ' %s'
\ . ' --shadow-file %s %t %s'
endfunction
function! ale_linters#python#mypy#Handle(buffer, lines) abort
@ -69,5 +57,4 @@ call ale#linter#Define('python', {
\ 'executable_callback': 'ale_linters#python#mypy#GetExecutable',
\ 'command_callback': 'ale_linters#python#mypy#GetCommand',
\ 'callback': 'ale_linters#python#mypy#Handle',
\ 'lint_file': 1,
\})

View File

@ -12,7 +12,7 @@ function! ale#fixers#autopep8#Fix(buffer) abort
\ ['/bin/autopep8'],
\)
if empty(l:executable)
if !executable(l:executable)
return 0
endif

View File

@ -11,7 +11,7 @@ function! ale#fixers#isort#Fix(buffer) abort
\ ['/bin/isort'],
\)
if empty(l:executable)
if !executable(l:executable)
return 0
endif

View File

@ -11,7 +11,7 @@ function! ale#fixers#yapf#Fix(buffer) abort
\ ['/bin/yapf'],
\)
if empty(l:executable)
if !executable(l:executable)
return 0
endif

View File

@ -58,11 +58,5 @@ function! ale#python#FindExecutable(buffer, base_var_name, path_list) abort
endfor
endif
let l:global_executable = ale#Var(a:buffer, a:base_var_name . '_executable')
if executable(l:global_executable)
return l:global_executable
endif
return ''
return ale#Var(a:buffer, a:base_var_name . '_executable')
endfunction

View File

@ -107,6 +107,11 @@ g:ale_python_isort_use_global *g:ale_python_isort_use_global*
-------------------------------------------------------------------------------
mypy *ale-python-mypy*
The minimum supported version of mypy that ALE supports is v0.4.4. This is
the first version containing the `--shadow-file` option ALE needs to be able
to check for errors while you type.
g:ale_python_mypy_executable *g:ale_python_mypy_executable*
*b:ale_python_mypy_executable*
Type: |String|

View File

@ -20,7 +20,8 @@ Execute(The mypy callbacks should return the correct default values):
\ 'mypy',
\ ale_linters#python#mypy#GetExecutable(bufnr(''))
AssertEqual
\ 'cd ''' . g:dir . ''' && ''mypy'' --show-column-numbers %s',
\ 'cd ''' . g:dir . ''' && ''mypy'' --show-column-numbers '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr(''))
Execute(The mypy executable should be configurable, and escaped properly):
@ -30,14 +31,16 @@ Execute(The mypy executable should be configurable, and escaped properly):
\ 'executable with spaces',
\ ale_linters#python#mypy#GetExecutable(bufnr(''))
AssertEqual
\ 'cd ''' . g:dir . ''' && ''executable with spaces'' --show-column-numbers %s',
\ 'cd ''' . g:dir . ''' && ''executable with spaces'' --show-column-numbers '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr(''))
Execute(The mypy command callback should let you set options):
let g:ale_python_mypy_options = '--some-option'
AssertEqual
\ 'cd ''' . g:dir . ''' && ''mypy'' --show-column-numbers --some-option %s',
\ 'cd ''' . g:dir . ''' && ''mypy'' --show-column-numbers --some-option '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr(''))
Execute(The mypy command should switch directories to the detected project root):
@ -47,7 +50,8 @@ Execute(The mypy command should switch directories to the detected project root)
\ 'mypy',
\ ale_linters#python#mypy#GetExecutable(bufnr(''))
AssertEqual
\ 'cd ''' . g:dir . '/python_paths/no_virtualenv/subdir'' && ''mypy'' --show-column-numbers %s',
\ 'cd ''' . g:dir . '/python_paths/no_virtualenv/subdir'' && ''mypy'' --show-column-numbers '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr(''))
Execute(The mypy callbacks should detect virtualenv directories and switch to the project root):
@ -58,7 +62,8 @@ Execute(The mypy callbacks should detect virtualenv directories and switch to th
\ ale_linters#python#mypy#GetExecutable(bufnr(''))
AssertEqual
\ 'cd ''' . g:dir . '/python_paths/with_virtualenv/subdir'' && '''
\ . g:dir . '/python_paths/with_virtualenv/env/bin/mypy'' --show-column-numbers %s',
\ . g:dir . '/python_paths/with_virtualenv/env/bin/mypy'' --show-column-numbers '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr(''))
Execute(You should able able to use the global mypy instead):
@ -69,5 +74,6 @@ Execute(You should able able to use the global mypy instead):
\ 'mypy',
\ ale_linters#python#mypy#GetExecutable(bufnr(''))
AssertEqual
\ 'cd ''' . g:dir . '/python_paths/with_virtualenv/subdir'' && ''mypy'' --show-column-numbers %s',
\ 'cd ''' . g:dir . '/python_paths/with_virtualenv/subdir'' && ''mypy'' --show-column-numbers '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr(''))