2012-02-20 05:20:48 -05:00
|
|
|
"============================================================================
|
|
|
|
"File: pylint.vim
|
2017-09-15 14:04:16 -04:00
|
|
|
"Description: Syntax checking plugin for syntastic
|
2015-07-10 13:14:23 -04:00
|
|
|
"Maintainer: Parantapa Bhattacharya <parantapa at gmail dot com>
|
2012-02-20 05:20:48 -05:00
|
|
|
"
|
|
|
|
"============================================================================
|
2014-01-03 04:29:08 -05:00
|
|
|
|
2015-03-25 12:44:34 -04:00
|
|
|
if exists('g:loaded_syntastic_python_pylint_checker')
|
2013-02-21 10:50:41 -05:00
|
|
|
finish
|
|
|
|
endif
|
2013-09-20 00:49:19 -04:00
|
|
|
let g:loaded_syntastic_python_pylint_checker = 1
|
|
|
|
|
2014-10-24 08:55:47 -04:00
|
|
|
if !exists('g:syntastic_python_pylint_sort')
|
|
|
|
let g:syntastic_python_pylint_sort = 1
|
|
|
|
endif
|
2013-02-21 10:50:41 -05:00
|
|
|
|
2014-01-03 04:29:08 -05:00
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2014-10-24 08:55:47 -04:00
|
|
|
let s:pylint_new = -1
|
|
|
|
|
2016-04-25 02:15:49 -04:00
|
|
|
function! SyntaxCheckers_python_pylint_IsAvailable() dict " {{{1
|
2014-10-06 15:15:44 -04:00
|
|
|
if !executable(self.getExec())
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
try
|
|
|
|
" On Windows the version is shown as "pylint-script.py 1.0.0".
|
|
|
|
" On Gentoo Linux it's "pylint-python2.7 0.28.0".
|
|
|
|
" On NixOS, that would be ".pylint-wrapped 0.26.0".
|
|
|
|
" On Arch Linux it's "pylint2 1.1.0".
|
|
|
|
" On new-ish Fedora it's "python3-pylint 1.2.0".
|
|
|
|
" Have you guys considered switching to creative writing yet? ;)
|
|
|
|
|
2015-07-10 13:14:23 -04:00
|
|
|
let version_output = syntastic#util#system(self.getExecEscaped() . ' --version')
|
|
|
|
let pylint_version = filter( split(version_output, '\m, \=\|\n'), 'v:val =~# ''\m^\(python[-0-9]*-\|\.\)\=pylint[-0-9]*\>''' )[0]
|
|
|
|
let parsed_ver = syntastic#util#parseVersion(substitute(pylint_version, '\v^\S+\s+', '', ''))
|
|
|
|
call self.setVersion(parsed_ver)
|
2014-10-06 15:15:44 -04:00
|
|
|
|
2015-07-10 13:14:23 -04:00
|
|
|
let s:pylint_new = syntastic#util#versionIsAtLeast(parsed_ver, [1])
|
2014-10-06 15:15:44 -04:00
|
|
|
catch /\m^Vim\%((\a\+)\)\=:E684/
|
2015-07-10 13:14:23 -04:00
|
|
|
call syntastic#log#ndebug(g:_SYNTASTIC_DEBUG_LOCLIST, 'checker output:', split(version_output, "\n", 1))
|
2014-10-06 15:15:44 -04:00
|
|
|
call syntastic#log#error("checker python/pylint: can't parse version string (abnormal termination?)")
|
|
|
|
let s:pylint_new = -1
|
|
|
|
endtry
|
|
|
|
|
2013-09-20 00:49:19 -04:00
|
|
|
return s:pylint_new >= 0
|
2016-04-25 02:15:49 -04:00
|
|
|
endfunction " }}}1
|
2013-01-23 19:01:30 -05:00
|
|
|
|
2016-04-25 02:15:49 -04:00
|
|
|
function! SyntaxCheckers_python_pylint_GetLocList() dict " {{{1
|
2013-11-01 05:51:47 -04:00
|
|
|
let makeprg = self.makeprgBuild({
|
2014-10-06 15:15:44 -04:00
|
|
|
\ 'args_after': (s:pylint_new ?
|
|
|
|
\ '-f text --msg-template="{path}:{line}:{column}:{C}: [{symbol}] {msg}" -r n' :
|
|
|
|
\ '-f parseable -r n -i y') })
|
2013-05-31 14:05:45 -04:00
|
|
|
|
2013-04-10 04:48:17 -04:00
|
|
|
let errorformat =
|
2014-01-23 15:20:00 -05:00
|
|
|
\ '%A%f:%l:%c:%t: %m,' .
|
2013-08-07 05:01:45 -04:00
|
|
|
\ '%A%f:%l: %m,' .
|
|
|
|
\ '%A%f:(%l): %m,' .
|
2013-05-10 07:11:07 -04:00
|
|
|
\ '%-Z%p^%.%#,' .
|
|
|
|
\ '%-G%.%#'
|
2013-01-20 06:07:05 -05:00
|
|
|
|
2014-07-07 12:04:22 -04:00
|
|
|
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
|
|
|
|
|
2014-04-16 15:16:40 -04:00
|
|
|
let loclist = SyntasticMake({
|
2013-05-10 07:11:07 -04:00
|
|
|
\ 'makeprg': makeprg,
|
|
|
|
\ 'errorformat': errorformat,
|
2014-07-07 12:04:22 -04:00
|
|
|
\ 'env': env,
|
2013-12-11 03:43:10 -05:00
|
|
|
\ 'returns': range(32) })
|
2013-02-06 08:29:56 -05:00
|
|
|
|
2013-11-08 03:45:15 -05:00
|
|
|
for e in loclist
|
2014-01-23 15:20:00 -05:00
|
|
|
if !s:pylint_new
|
|
|
|
let e['type'] = e['text'][1]
|
|
|
|
endif
|
|
|
|
|
|
|
|
if e['type'] =~? '\m^[EF]'
|
2013-11-04 16:00:51 -05:00
|
|
|
let e['type'] = 'E'
|
2014-01-23 15:20:00 -05:00
|
|
|
elseif e['type'] =~? '\m^[CRW]'
|
2013-11-04 16:00:51 -05:00
|
|
|
let e['type'] = 'W'
|
2013-08-12 04:22:12 -04:00
|
|
|
else
|
2013-11-04 16:00:51 -05:00
|
|
|
let e['valid'] = 0
|
2013-08-12 04:22:12 -04:00
|
|
|
endif
|
2014-02-04 04:53:26 -05:00
|
|
|
|
|
|
|
let e['col'] += 1
|
2013-11-04 16:00:51 -05:00
|
|
|
let e['vcol'] = 0
|
2013-04-15 04:21:52 -04:00
|
|
|
endfor
|
2013-01-20 07:27:19 -05:00
|
|
|
|
2013-05-10 07:11:07 -04:00
|
|
|
return loclist
|
2016-04-25 02:15:49 -04:00
|
|
|
endfunction " }}}1
|
2013-01-23 19:01:30 -05:00
|
|
|
|
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
|
|
|
\ 'filetype': 'python',
|
2013-01-27 15:08:30 -05:00
|
|
|
\ 'name': 'pylint' })
|
2014-01-03 04:29:08 -05:00
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|