syntastic/syntax_checkers/python/pyflakes.vim

75 lines
2.3 KiB
VimL
Raw Normal View History

"============================================================================
"File: pyflakes.vim
2017-09-15 14:04:16 -04:00
"Description: Syntax checking plugin for syntastic
"Authors: Martin Grenfell <martin.grenfell@gmail.com>
" kstep <me@kstep.me>
" Parantapa Bhattacharya <parantapa@gmail.com>
"
"============================================================================
2015-03-25 12:44:34 -04:00
if exists('g:loaded_syntastic_python_pyflakes_checker')
finish
endif
let g:loaded_syntastic_python_pyflakes_checker = 1
let s:save_cpo = &cpo
set cpo&vim
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! SyntaxCheckers_python_pyflakes_GetHighlightRegex(i)
if stridx(a:i['text'], 'is assigned to but never used') >= 0
\ || stridx(a:i['text'], 'imported but unused') >= 0
\ || stridx(a:i['text'], 'undefined name') >= 0
\ || stridx(a:i['text'], 'redefinition of') >= 0
\ || stridx(a:i['text'], 'referenced before assignment') >= 0
\ || stridx(a:i['text'], 'duplicate argument') >= 0
\ || stridx(a:i['text'], 'after other statements') >= 0
\ || stridx(a:i['text'], 'shadowed by loop variable') >= 0
" fun with Python's %r: try "..." first, then '...'
2014-06-30 07:45:30 -04:00
let term = matchstr(a:i['text'], '\m^.\{-}"\zs.\{-1,}\ze"')
2015-03-25 12:44:34 -04:00
if term !=# ''
2014-06-30 07:45:30 -04:00
return '\V\<' . escape(term, '\') . '\>'
endif
2014-06-30 07:45:30 -04:00
let term = matchstr(a:i['text'], '\m^.\{-}''\zs.\{-1,}\ze''')
2015-03-25 12:44:34 -04:00
if term !=# ''
2014-06-30 07:45:30 -04:00
return '\V\<' . escape(term, '\') . '\>'
endif
endif
return ''
endfunction
function! SyntaxCheckers_python_pyflakes_GetLocList() dict
let makeprg = self.makeprgBuild({})
let errorformat =
\ '%E%f:%l: could not compile,'.
\ '%-Z%p^,'.
2014-02-27 11:10:47 -05:00
\ '%E%f:%l:%c: %m,'.
\ '%E%f:%l: %m,'.
\ '%-G%.%#'
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
2014-01-04 12:26:56 -05:00
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'env': env,
2015-03-25 12:44:34 -04:00
\ 'defaults': {'text': 'Syntax error'} })
2014-01-04 12:26:56 -05:00
for e in loclist
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
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'pyflakes'})
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: