summaryrefslogtreecommitdiff
path: root/ale_linters/python
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2020-09-09 21:42:27 +0100
committerw0rp <devw0rp@gmail.com>2020-09-09 21:45:15 +0100
commit4ddf74264397a0c739b1c6fd5f643505a31e1d11 (patch)
tree5745b0de17ad7380fb47c6354e9aca42d853956e /ale_linters/python
parent78fa93bd55be70c00d0342655bcdfada338e6e79 (diff)
downloadale-4ddf74264397a0c739b1c6fd5f643505a31e1d11.zip
Close #2522 - Check pylint on the fly
Newer versions of pylint will now check your code as you type. Older versions will still only check the file on disk. Co-authored-by: Oliver Wiegers <oliver.wiegers@gmail.com>
Diffstat (limited to 'ale_linters/python')
-rw-r--r--ale_linters/python/pylint.vim38
1 files changed, 30 insertions, 8 deletions
diff --git a/ale_linters/python/pylint.vim b/ale_linters/python/pylint.vim
index b16d5355..44eea246 100644
--- a/ale_linters/python/pylint.vim
+++ b/ale_linters/python/pylint.vim
@@ -17,7 +17,7 @@ function! ale_linters#python#pylint#GetExecutable(buffer) abort
return ale#python#FindExecutable(a:buffer, 'python_pylint', ['pylint'])
endfunction
-function! ale_linters#python#pylint#GetCommand(buffer) abort
+function! ale_linters#python#pylint#GetCommand(buffer, version) abort
let l:cd_string = ''
if ale#Var(a:buffer, 'python_pylint_change_directory')
@@ -38,17 +38,23 @@ function! ale_linters#python#pylint#GetCommand(buffer) abort
return l:cd_string
\ . ale#Escape(l:executable) . l:exec_args
- \ . ' ' . ale#Var(a:buffer, 'python_pylint_options')
+ \ . ale#Pad(ale#Var(a:buffer, 'python_pylint_options'))
\ . ' --output-format text --msg-template="{path}:{line}:{column}: {msg_id} ({symbol}) {msg}" --reports n'
+ \ . (ale#semver#GTE(a:version, [2, 4, 0]) ? ' --from-stdin' : '')
\ . ' %s'
endfunction
function! ale_linters#python#pylint#Handle(buffer, lines) abort
+ let l:output = ale#python#HandleTraceback(a:lines, 10)
+
+ if !empty(l:output)
+ return l:output
+ endif
+
" Matches patterns like the following:
"
" test.py:4:4: W0101 (unreachable) Unreachable code
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+): ([[:alnum:]]+) \(([^(]*)\) (.*)$'
- let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
"let l:failed = append(0, l:match)
@@ -71,13 +77,19 @@ function! ale_linters#python#pylint#Handle(buffer, lines) abort
let l:code_out = l:match[4]
endif
- call add(l:output, {
+ let l:item = {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 1,
\ 'text': l:match[5],
\ 'code': l:code_out,
- \ 'type': l:code[:0] is# 'E' ? 'E' : 'W',
- \})
+ \ 'type': 'W',
+ \}
+
+ if l:code[:0] is# 'E'
+ let l:item.type = 'E'
+ endif
+
+ call add(l:output, l:item)
endfor
return l:output
@@ -86,7 +98,17 @@ endfunction
call ale#linter#Define('python', {
\ 'name': 'pylint',
\ 'executable': function('ale_linters#python#pylint#GetExecutable'),
-\ 'command': function('ale_linters#python#pylint#GetCommand'),
+\ 'lint_file': {buffer -> ale#semver#RunWithVersionCheck(
+\ buffer,
+\ ale#Var(buffer, 'python_pylint_executable'),
+\ '%e --version',
+\ {buffer, version -> !ale#semver#GTE(version, [2, 4, 0])},
+\ )},
+\ 'command': {buffer -> ale#semver#RunWithVersionCheck(
+\ buffer,
+\ ale#Var(buffer, 'python_pylint_executable'),
+\ '%e --version',
+\ function('ale_linters#python#pylint#GetCommand'),
+\ )},
\ 'callback': 'ale_linters#python#pylint#Handle',
-\ 'lint_file': 1,
\})