1 "============================================================================
3 "Description: Syntax checking plugin for syntastic.vim
5 "Authors: Martin Grenfell <martin.grenfell@gmail.com>
7 " Parantapa Bhattacharya <parantapa@gmail.com>
9 "============================================================================
11 " For forcing the use of flake8, pyflakes, or pylint set
13 " let g:syntastic_python_checker = 'pyflakes'
15 " in your .vimrc. Default is flake8.
17 if exists("loaded_python_syntax_checker")
20 let loaded_python_syntax_checker = 1
22 "bail if the user doesnt have his favorite checker or flake8 or pyflakes installed
23 if !exists('g:syntastic_python_checker') || !executable(g:syntastic_python_checker)
24 if executable("flake8")
25 let g:syntastic_python_checker = 'flake8'
26 elseif executable("pyflakes")
27 let g:syntastic_python_checker = 'pyflakes'
28 elseif executable("pylint")
29 let g:syntastic_python_checker = 'pylint'
34 if !exists('g:syntastic_python_checker_args')
35 let g:syntastic_python_checker_args = ''
38 function! SyntaxCheckers_python_Term(i)
39 if a:i['type'] ==# 'E'
40 let a:i['text'] = "Syntax error"
42 if match(a:i['text'], 'is assigned to but never used') > -1
43 \ || match(a:i['text'], 'imported but unused') > -1
44 \ || match(a:i['text'], 'undefined name') > -1
45 \ || match(a:i['text'], 'redefinition of') > -1
46 \ || match(a:i['text'], 'referenced before assignment') > -1
47 \ || match(a:i['text'], 'duplicate argument') > -1
48 \ || match(a:i['text'], 'after other statements') > -1
49 \ || match(a:i['text'], 'shadowed by loop variable') > -1
51 let term = split(a:i['text'], "'", 1)[1]
52 return '\V\<'.term.'\>'
57 if g:syntastic_python_checker == 'pylint'
58 function! SyntaxCheckers_python_GetLocList()
59 let makeprg = 'pylint -f parseable -r n -i y ' .
60 \ shellescape(expand('%')) .
61 \ ' \| sed ''s_: \[[RC]_: \[W_''' .
62 \ ' \| sed ''s_: \[[F]_:\ \[E_'''
63 let errorformat = '%f:%l: [%t%n] %m,%-GNo config%m'
64 let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
69 function! SyntaxCheckers_python_GetLocList()
70 let makeprg = g:syntastic_python_checker.' '.g:syntastic_python_checker_args.' '.shellescape(expand('%'))
72 \ '%E%f:%l: could not compile,%-Z%p^,%W%f:%l:%c: %m,%W%f:%l: %m,%-G%.%#'
74 let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
76 call SyntasticHighlightErrors(errors, function('SyntaxCheckers_python_Term'))