1 " Asynchronous pylint utility call
2 " Maintainer: Sergey Matveev <stargrave@stargrave.org>
3 " License: GNU General Public License version 3 of the License or later
5 " This plugin allows you to asynchronously call pylint.
7 " * Add %{LintStatus()} to your statusline to see if pylint is running
8 " * Press <F6> to start pylint on current file
9 " * Press <S-F6> to open quickfix window with messages from pylint
10 " * All lines with corresponding pylint existing warning will be highlighted
11 " * If no warning and errors occurred, "pylint is clean" message will be shown
12 " * If existing quickfix window is found, then it won't be overwritten.
13 " Start pylint manually (<F6>) to force its filling
14 " * After Python file is saved, pylint is automatically started
16 if exists('g:loaded_pylint') | finish | endif
17 let g:loaded_pylint = 1
19 function! LintStatus()
20 if exists("b:lint_job") && job_status(b:lint_job) == "run" | return "LN" | endif
24 function! s:qffill(ch)
26 while ch_status(a:ch) == 'buffered'
27 let msgs = add(msgs, ch_read(a:ch))
32 sign define LN text=LN texthl=Error
34 function! PylintFinish(ch)
35 let l:errorformat_bak = &errorformat
36 set errorformat=%f:%l:\ [%t]%m,%f:%l:%m
38 let &errorformat=l:errorformat_bak
41 for item in getqflist()
42 if item.lnum == 0 | continue | endif
43 execute(':sign place '.l:id.' name=LN line='.l:item.lnum.' buffer='.l:item.bufnr)
48 echohl MoreMsg | echomsg "pylint is clean" | echohl None
53 function! PylintStart()
54 if exists("g:pylint_disable") || (exists("b:lint_job") && job_status(b:lint_job) == "run")
61 \"too-few-public-methods",
63 \"too-many-instance-attributes",
65 \"too-many-arguments",
67 \"too-many-public-methods",
68 \"no-value-for-parameter",
70 if !exists("g:pylint_linter") | let g:pylint_linter = "pylint" | endif
71 if g:pylint_linter == "flake8"
75 \"--format=%(path)s:%(row)d: [%(code)s] %(text)s",
76 \"--max-line-length=90",
79 elseif g:pylint_linter == "pylint"
84 \"--msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg}",
85 \"--disable=" . join(ignores, ","),
91 echohl WarningMsg | echomsg "Unknown linter specified" | echohl None
94 let b:lint_job = job_start(cmdline, {"in_mode": "nl", "err_io": "null", "close_cb": "PylintFinish"})
97 map <F6> :unlet! g:pylint_disable<CR>:call PylintStart()<CR>
98 map
\e[32~ :redraw!<CR>:copen<CR>
99 autocmd BufWritePost *.py call PylintStart()