]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/syntax_checkers/python.vim
a20539b852307429799f836c67f434a3e93838e1
[rbdr/dotfiles] / vim / syntax_checkers / python.vim
1 "============================================================================
2 "File: python.vim
3 "Description: Syntax checking plugin for syntastic.vim
4 "
5 "Authors: Martin Grenfell <martin.grenfell@gmail.com>
6 " kstep <me@kstep.me>
7 " Parantapa Bhattacharya <parantapa@gmail.com>
8 "
9 "============================================================================
10 "
11 " For forcing the use of flake8, pyflakes, or pylint set
12 "
13 " let g:syntastic_python_checker = 'pyflakes'
14 "
15 " in your .vimrc. Default is flake8.
16
17 if exists("loaded_python_syntax_checker")
18 finish
19 endif
20 let loaded_python_syntax_checker = 1
21
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'
30 else
31 finish
32 endif
33 endif
34 if !exists('g:syntastic_python_checker_args')
35 let g:syntastic_python_checker_args = ''
36 endif
37
38 function! SyntaxCheckers_python_Term(i)
39 if a:i['type'] ==# 'E'
40 let a:i['text'] = "Syntax error"
41 endif
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
50
51 let term = split(a:i['text'], "'", 1)[1]
52 return '\V\<'.term.'\>'
53 endif
54 return ''
55 endfunction
56
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 })
65
66 return errors
67 endfunction
68 else
69 function! SyntaxCheckers_python_GetLocList()
70 let makeprg = g:syntastic_python_checker.' '.g:syntastic_python_checker_args.' '.shellescape(expand('%'))
71 let errorformat =
72 \ '%E%f:%l: could not compile,%-Z%p^,%W%f:%l:%c: %m,%W%f:%l: %m,%-G%.%#'
73
74 let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
75
76 call SyntasticHighlightErrors(errors, function('SyntaxCheckers_python_Term'))
77
78 return errors
79 endfunction
80 endif