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