diff --git a/ale_linters/python/mypy.vim b/ale_linters/python/mypy.vim index 6884a9a..c1c9174 100644 --- a/ale_linters/python/mypy.vim +++ b/ale_linters/python/mypy.vim @@ -1,10 +1,10 @@ " Author: Keith Smiley , w0rp " Description: mypy support for optional python typechecking -let g:ale_python_mypy_executable = -\ get(g:, 'ale_python_mypy_executable', 'mypy') -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) +call ale#Set('python_mypy_executable', 'mypy') +call ale#Set('python_mypy_ignore_invalid_syntax', 0) +call ale#Set('python_mypy_options', '') +call ale#Set('python_mypy_use_global', 0) function! ale_linters#python#mypy#GetExecutable(buffer) abort return ale#python#FindExecutable(a:buffer, 'python_mypy', ['mypy']) @@ -45,6 +45,12 @@ function! ale_linters#python#mypy#Handle(buffer, lines) abort let l:output = [] for l:match in ale#util#GetMatches(a:lines, l:pattern) + " Skip invalid syntax errors if the option is on. + if l:match[5] is# 'invalid syntax' + \&& ale#Var(a:buffer, 'python_mypy_ignore_invalid_syntax') + continue + endif + call add(l:output, { \ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]), \ 'lnum': l:match[2] + 0, diff --git a/doc/ale-python.txt b/doc/ale-python.txt index 742a854..4d55e75 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -104,6 +104,16 @@ g:ale_python_mypy_executable *g:ale_python_mypy_executable* See |ale-integrations-local-executables| +g:ale_python_mypy_ignore_invalid_syntax + *g:ale_python_mypy_ignore_invalid_syntax* + *b:ale_python_mypy_ignore_invalid_syntax* + Type: |Number| + Default: `0` + + When set to `1`, syntax error messages for mypy will be ignored. This option + can be used when running other Python linters which check for syntax errors, + as mypy can take a while to finish executing. + g:ale_python_mypy_options *g:ale_python_mypy_options* *b:ale_python_mypy_options* @@ -125,16 +135,16 @@ g:ale_python_mypy_use_global *g:ale_python_mypy_use_global* =============================================================================== prospector *ale-python-prospector* -g:ale_python_prospector_executable *g:ale_python_prospector_executable* - *b:ale_python_prospector_executable* +g:ale_python_prospector_executable *g:ale_python_prospector_executable* + *b:ale_python_prospector_executable* Type: |String| Default: `'prospector'` See |ale-integrations-local-executables| -g:ale_python_prospector_options *g:ale_python_prospector_options* - *b:ale_python_prospector_options* +g:ale_python_prospector_options *g:ale_python_prospector_options* + *b:ale_python_prospector_options* Type: |String| Default: `''` @@ -154,8 +164,8 @@ g:ale_python_prospector_options *g:ale_python_prospector_option `python3 -m pip install --user prospector`). -g:ale_python_prospector_use_global *g:ale_python_prospector_use_global* - *b:ale_python_prospector_use_global* +g:ale_python_prospector_use_global *g:ale_python_prospector_use_global* + *b:ale_python_prospector_use_global* Type: |Number| Default: `0` diff --git a/test/handler/test_mypy_handler.vader b/test/handler/test_mypy_handler.vader index abb8504..f3d4cbf 100644 --- a/test/handler/test_mypy_handler.vader +++ b/test/handler/test_mypy_handler.vader @@ -1,9 +1,15 @@ Before: + Save g:ale_python_mypy_ignore_invalid_syntax + + unlet! g:ale_python_mypy_ignore_invalid_syntax + runtime ale_linters/python/mypy.vim call ale#test#SetDirectory('/testplugin/test/handler') After: + Restore + call ale#test#RestoreDirectory() call ale#linter#Reset() @@ -80,3 +86,27 @@ Execute(The mypy handler should handle Windows names with spaces): \ ale_linters#python#mypy#Handle(bufnr(''), [ \ 'C:\something\with spaces.py:4: error: No library stub file for module ''django.db''', \ ]) + +Execute(The mypy syntax errors shouldn't be ignored by default): + AssertEqual + \ [ + \ { + \ 'lnum': 4, + \ 'col': 0, + \ 'filename': ale#path#Simplify(g:dir . '/foo.py'), + \ 'type': 'E', + \ 'text': 'invalid syntax', + \ }, + \ ], + \ ale_linters#python#mypy#Handle(bufnr(''), [ + \ 'foo.py:4: error: invalid syntax', + \ ]) + +Execute(The mypy syntax errors should be ignored when the option is on): + let g:ale_python_mypy_ignore_invalid_syntax = 1 + + AssertEqual + \ [], + \ ale_linters#python#mypy#Handle(bufnr(''), [ + \ 'foo.py:4: error: invalid syntax', + \ ])