" Asynchronous pylint utility call " Maintainer: Sergey Matveev " License: GNU General Public License version 3 of the License or later " " This plugin allows you to asynchronously call pylint. " " * Add %{LintStatus()} to your statusline to see if pylint is running " * Press to start pylint on current file " * Press to open quickfix window with messages from pylint " * All lines with corresponding pylint existing warning will be highlighted " * If no warning and errors occurred, "pylint is clean" message will be shown " * If existing quickfix window is found, then it won't be overwritten. " Start pylint manually () to force its filling " * After Python file is saved, pylint is automatically started if exists('g:loaded_pylint') | finish | endif let g:loaded_pylint = 1 function! LintStatus() if exists("b:lint_job") && job_status(b:lint_job) == "run" | return "LN" | endif return "" endfunction function! s:qffill(ch) let msgs = [] while ch_status(a:ch) == 'buffered' let msgs = add(msgs, ch_read(a:ch)) endwhile cgetexpr msgs endfunction sign define LN text=LN texthl=Error function! PylintFinish(ch) let l:errorformat_bak = &errorformat set errorformat=%f:%l:\ [%t]%m,%f:%l:%m call s:qffill(a:ch) let &errorformat=l:errorformat_bak sign unplace * let l:id = 2 for item in getqflist() if item.lnum == 0 | continue | endif execute(':sign place '.l:id.' name=LN line='.l:item.lnum.' buffer='.l:item.bufnr) let l:id = l:id + 2 endfor redraw! if l:id == 2 echohl MoreMsg | echomsg "pylint is clean" | echohl None cclose endif endfunction function! PylintStart() if exists("g:pylint_disable") || (exists("b:lint_job") && job_status(b:lint_job) == "run") return endif let ignores = [ \"locally-disabled", \"no-init", \"no-self-use", \"too-few-public-methods", \"missing-docstring", \"too-many-instance-attributes", \"invalid-name", \"too-many-arguments", \"too-many-locals", \"too-many-public-methods", \"no-value-for-parameter", \] if !exists("g:pylint_linter") | let g:pylint_linter = "flake8" | endif if g:pylint_linter == "flake8" let cmdline = [ \"flake8", \"--ignore=E501", \"--format=%(path)s:%(row)d: [%(code)s] %(text)s", \"--max-line-length=90", \expand("%p") \] elseif g:pylint_linter == "pylint" let cmdline = [ \"pylint", \"--jobs=4", \"--reports=n", \"--msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg}", \"--disable=" . join(ignores, ","), \"--persistent=n", \expand("%p") \] else echohl WarningMsg | echomsg "Unknown linter specified" | echohl None return endif let b:lint_job = job_start(cmdline, {"in_mode": "nl", "err_io": "null", "close_cb": "PylintFinish"}) endfunction() map :unlet! g:pylint_disable:call PylintStart() map [17;2~ :redraw!:copen autocmd BufWritePost *.py call PylintStart()