syntastic/syntax_checkers/python/pylint.vim

86 lines
2.6 KiB
VimL
Raw Normal View History

"============================================================================
"File: pylint.vim
"Description: Syntax checking plugin for syntastic.vim
"Author: Parantapa Bhattacharya <parantapa at gmail dot com>
"
"============================================================================
if exists("g:loaded_syntastic_python_pylint_checker")
finish
endif
2013-09-20 00:49:19 -04:00
let g:loaded_syntastic_python_pylint_checker = 1
let s:pylint_new = -1
let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_python_pylint_IsAvailable() dict
let exe = self.getExec()
let s:pylint_new = executable(exe) ? s:PylintNew(exe) : -1
2013-09-20 00:49:19 -04:00
return s:pylint_new >= 0
refactor how we represent and store checkers using python as a demo Add 2 classes: SyntasticChecker and SyntasticRegistry. SyntasticChecker represents a checker. It holds funcrefs to the checker func, the highlight regex func and a new `isAvailable()` func (that essentially just checks if the checker exe is installed) SyntasticRegistry is responsible for: * loading checkers * storing checkers * fetching the checkers to use according to availability and the users settings Motivation/benefits: * in the current system only one checker can be loaded per filetype * syntax checkers cant be "chained" together * the system is hard to add features to since fundamental concepts like syntax checkers and location lists arent represented explicitly Things left to do: * add a call to g:SyntasticRegistry.CreateAndRegisterChecker() to all checkers * add an `isAvailable` function to all checkers * move all checkers into `syntax_checkers/filetype/checkername.vim` - g:SyntasticRegistry assumes this layout, and its a good idea anyway for consistency and it makes it easier for users to add their own checkers Things to do after all of the above: * add a LocationList class and move all the filtering functions onto it * possibly add an Error class that wraps up each item in a loc list Random notes: * with the new system you can select the checkers to use with e.g. `let g:syntastic_python_checkers=['flake8', 'pylint']` This will try flake8 first, and if no errors are detected it will move onto pylint.
2013-01-23 19:01:30 -05:00
endfunction
function! SyntaxCheckers_python_pylint_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'args_after': (s:pylint_new ? '-f text --msg-template="{path}:{line}:{column}:{C}: [{symbol}] {msg}" -r n' : '-f parseable -r n -i y') })
2013-04-10 04:48:17 -04:00
let errorformat =
\ '%A%f:%l:%c:%t: %m,' .
\ '%A%f:%l: %m,' .
\ '%A%f:(%l): %m,' .
\ '%-Z%p^%.%#,' .
\ '%-G%.%#'
let loclist=SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
2013-12-11 03:43:10 -05:00
\ 'postprocess': ['sort'],
\ 'returns': range(32) })
2013-11-08 03:45:15 -05:00
for e in loclist
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'
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
let e['col'] += 1
2013-11-04 16:00:51 -05:00
let e['vcol'] = 0
endfor
return loclist
endfunction
refactor how we represent and store checkers using python as a demo Add 2 classes: SyntasticChecker and SyntasticRegistry. SyntasticChecker represents a checker. It holds funcrefs to the checker func, the highlight regex func and a new `isAvailable()` func (that essentially just checks if the checker exe is installed) SyntasticRegistry is responsible for: * loading checkers * storing checkers * fetching the checkers to use according to availability and the users settings Motivation/benefits: * in the current system only one checker can be loaded per filetype * syntax checkers cant be "chained" together * the system is hard to add features to since fundamental concepts like syntax checkers and location lists arent represented explicitly Things left to do: * add a call to g:SyntasticRegistry.CreateAndRegisterChecker() to all checkers * add an `isAvailable` function to all checkers * move all checkers into `syntax_checkers/filetype/checkername.vim` - g:SyntasticRegistry assumes this layout, and its a good idea anyway for consistency and it makes it easier for users to add their own checkers Things to do after all of the above: * add a LocationList class and move all the filtering functions onto it * possibly add an Error class that wraps up each item in a loc list Random notes: * with the new system you can select the checkers to use with e.g. `let g:syntastic_python_checkers=['flake8', 'pylint']` This will try flake8 first, and if no errors are detected it will move onto pylint.
2013-01-23 19:01:30 -05:00
function! s:PylintNew(exe)
let exe = syntastic#util#shescape(a:exe)
2013-09-19 18:16:36 -04:00
try
" On Windows the version is shown as "pylint-script.py 1.0.0".
2014-02-17 04:49:02 -05:00
" On Gentoo Linux it's "pylint-python2.7 0.28.0".
" On NixOS, that would be ".pylint-wrapped 0.26.0", that would be.
" Have you guys considered switching to creative writing yet? ;)
let pylint_version = filter(split(system(exe . ' --version'), '\m, \=\|\n'), 'v:val =~# ''\m^\.\=pylint\>''')[0]
let pylint_version = substitute(pylint_version, '\v^\S+\s+', '', '')
2013-09-24 01:39:07 -04:00
let ret = syntastic#util#versionIsAtLeast(syntastic#util#parseVersion(pylint_version), [1])
catch /\m^Vim\%((\a\+)\)\=:E684/
call syntastic#log#error("checker python/pylint: can't parse version string (abnormal termination?)")
2013-09-20 00:49:19 -04:00
let ret = -1
2013-09-19 18:16:36 -04:00
endtry
2013-09-20 00:49:19 -04:00
return ret
endfunction
refactor how we represent and store checkers using python as a demo Add 2 classes: SyntasticChecker and SyntasticRegistry. SyntasticChecker represents a checker. It holds funcrefs to the checker func, the highlight regex func and a new `isAvailable()` func (that essentially just checks if the checker exe is installed) SyntasticRegistry is responsible for: * loading checkers * storing checkers * fetching the checkers to use according to availability and the users settings Motivation/benefits: * in the current system only one checker can be loaded per filetype * syntax checkers cant be "chained" together * the system is hard to add features to since fundamental concepts like syntax checkers and location lists arent represented explicitly Things left to do: * add a call to g:SyntasticRegistry.CreateAndRegisterChecker() to all checkers * add an `isAvailable` function to all checkers * move all checkers into `syntax_checkers/filetype/checkername.vim` - g:SyntasticRegistry assumes this layout, and its a good idea anyway for consistency and it makes it easier for users to add their own checkers Things to do after all of the above: * add a LocationList class and move all the filtering functions onto it * possibly add an Error class that wraps up each item in a loc list Random notes: * with the new system you can select the checkers to use with e.g. `let g:syntastic_python_checkers=['flake8', 'pylint']` This will try flake8 first, and if no errors are detected it will move onto pylint.
2013-01-23 19:01:30 -05:00
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'pylint' })
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4: