1
0
mirror of https://github.com/amix/vimrc synced 2025-06-24 07:44:59 +08:00

Use syntastic instead of pyflakes (supports a ton of more languages)

This commit is contained in:
amix
2014-02-08 10:05:16 +00:00
parent 8265dca5d5
commit 497b5aa4fb
193 changed files with 11942 additions and 3531 deletions

View File

@ -0,0 +1,13 @@
#!/usr/bin/env python
from __future__ import print_function
from sys import argv, exit
if len(argv) != 2:
exit(1)
try:
compile(open(argv[1]).read(), argv[1], 'exec', 0, 1)
except SyntaxError as err:
print('%s:%s:%s: %s' % (err.filename, err.lineno, err.offset, err.msg))

View File

@ -0,0 +1,69 @@
"============================================================================
"File: flake8.vim
"Description: Syntax checking plugin for syntastic.vim
"Authors: Sylvain Soliman <Sylvain dot Soliman+git at gmail dot com>
" kstep <me@kstep.me>
"
"============================================================================
if exists("g:loaded_syntastic_python_flake8_checker")
finish
endif
let g:loaded_syntastic_python_flake8_checker = 1
let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_python_flake8_GetHighlightRegex(item)
return SyntaxCheckers_python_pyflakes_GetHighlightRegex(a:item)
endfunction
function! SyntaxCheckers_python_flake8_GetLocList() dict
let makeprg = self.makeprgBuild({})
let errorformat =
\ '%E%f:%l: could not compile,%-Z%p^,' .
\ '%A%f:%l:%c: %t%n %m,' .
\ '%A%f:%l: %t%n %m,' .
\ '%-G%.%#'
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat })
for e in loclist
" E*** and W*** are pep8 errors
" F*** are PyFlakes codes
" C*** are McCabe complexity messages
" N*** are naming conventions from pep8-naming
if has_key(e, 'nr')
let e['text'] .= printf(' [%s%03d]', e['type'], e['nr'])
" E901 are syntax errors
" E902 are I/O errors
if e['type'] ==? 'E' && e['nr'] !~ '\m^9'
let e['subtype'] = 'Style'
endif
call remove(e, 'nr')
endif
if e['type'] =~? '\m^[CNW]'
let e['subtype'] = 'Style'
endif
let e['type'] = e['type'] =~? '\m^[EFC]' ? 'E' : 'W'
endfor
return loclist
endfunction
runtime! syntax_checkers/python/pyflakes.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'flake8'})
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,60 @@
"============================================================================
"File: frosted.vim
"Description: Syntax checking plugin for syntastic.vim
"Maintainer: LCD 47 <lcd047 at gmail dot com>
"License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
"============================================================================
if exists('g:loaded_syntastic_python_frosted_checker')
finish
endif
let g:loaded_syntastic_python_frosted_checker = 1
let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_python_frosted_GetLocList() dict
let makeprg = self.makeprgBuild({ 'args_after': '-vb' })
let errorformat =
\ '%f:%l:%c:%m,' .
\ '%E%f:%l: %m,' .
\ '%-Z%p^,' .
\ '%-G%.%#'
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'returns': [0, 1] })
for e in loclist
let e["col"] += 1
let parts = matchlist(e.text, '\v^([EW]\d+):([^:]*):(.+)')
if len(parts) >= 4
let e["type"] = parts[1][0]
let e["text"] = parts[3] . ' [' . parts[1] . ']'
let e["hl"] = '\V' . parts[2]
elseif e["text"] =~? '\v^I\d+:'
let e["valid"] = 0
else
let e["vcol"] = 0
endif
endfor
return loclist
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'frosted' })
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,51 @@
"============================================================================
"File: pep257.vim
"Description: Docstring style checking plugin for syntastic.vim
"============================================================================
"
" For details about pep257 see: https://github.com/GreenSteam/pep257
if exists("g:loaded_syntastic_python_pep257_checker")
finish
endif
let g:loaded_syntastic_python_pep257_checker = 1
let s:save_cpo = &cpo
set cpo&vim
" sanity: kill empty lines here rather than munging errorformat
function! SyntaxCheckers_python_pep257_Preprocess(errors)
return filter(copy(a:errors), 'v:val != ""')
endfunction
function! SyntaxCheckers_python_pep257_GetLocList() dict
let makeprg = self.makeprgBuild({})
let errorformat =
\ '%E%f:%l:%c%\%.%\%.%\d%\+:%\d%\+: %m,' .
\ '%E%f:%l:%c: %m,' .
\ '%+C %m'
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'subtype': 'Style',
\ 'preprocess': 'SyntaxCheckers_python_pep257_Preprocess',
\ 'postprocess': ['compressWhitespace'] })
" pep257 outputs byte offsets rather than column numbers
for e in loclist
let e['col'] = get(e, 'col', 0) + 1
endfor
return loclist
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'pep257'})
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,47 @@
"============================================================================
"File: pep8.vim
"Description: Syntax checking plugin for syntastic.vim
"Maintainer: LCD 47 <lcd047 at gmail dot com>
"License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
"============================================================================
"
" For details about pep8 see: https://github.com/jcrocholl/pep8
if exists("g:loaded_syntastic_python_pep8_checker")
finish
endif
let g:loaded_syntastic_python_pep8_checker = 1
let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_python_pep8_GetLocList() dict
let makeprg = self.makeprgBuild({})
let errorformat = '%f:%l:%c: %m'
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'subtype': 'Style' })
for e in loclist
let e['type'] = e['text'] =~? '^W' ? 'W' : 'E'
endfor
return loclist
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'pep8'})
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,33 @@
"============================================================================
"File: py3kwarn.vim
"Description: Syntax checking plugin for syntastic.vim
"Authors: Liam Curry <liam@curry.name>
"
"============================================================================
if exists("g:loaded_syntastic_python_py3kwarn_checker")
finish
endif
let g:loaded_syntastic_python_py3kwarn_checker = 1
let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_python_py3kwarn_GetLocList() dict
let makeprg = self.makeprgBuild({})
let errorformat = '%W%f:%l:%c: %m'
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat })
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'py3kwarn'})
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,70 @@
"============================================================================
"File: pyflakes.vim
"Description: Syntax checking plugin for syntastic.vim
"Authors: Martin Grenfell <martin.grenfell@gmail.com>
" kstep <me@kstep.me>
" Parantapa Bhattacharya <parantapa@gmail.com>
"
"============================================================================
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
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 '...'
let terms = split(a:i['text'], '"', 1)
if len(terms) > 2
return terms[1]
endif
let terms = split(a:i['text'], "'", 1)
if len(terms) > 2
return terms[1]
endif
endif
return ''
endfunction
function! SyntaxCheckers_python_pyflakes_GetLocList() dict
let makeprg = self.makeprgBuild({})
let errorformat =
\ '%E%f:%l: could not compile,'.
\ '%-Z%p^,'.
\ '%E%f:%l: %m,'.
\ '%-G%.%#'
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'defaults': {'text': "Syntax error"} })
for e in loclist
let e['vcol'] = 0
endfor
return loclist
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'pyflakes'})
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,68 @@
"============================================================================
"File: pylama.vim
"Description: Syntax checking plugin for syntastic.vim
"Maintainer: LCD 47 <lcd047 at gmail dot com>
"License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
"============================================================================
if exists('g:loaded_syntastic_python_pylama_checker')
finish
endif
let g:loaded_syntastic_python_pylama_checker = 1
let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_python_pylama_GetHighlightRegex(item)
return SyntaxCheckers_python_pyflakes_GetHighlightRegex(a:item)
endfunction
function! SyntaxCheckers_python_pylama_GetLocList() dict
let makeprg = self.makeprgBuild({ 'args_after': '-f pep8' })
" TODO: "WARNING:pylama:..." messages are probably a logging bug
let errorformat =
\ '%-GWARNING:pylama:%.%#,' .
\ '%A%f:%l:%c: %m'
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'postprocess': ['sort'] })
" adjust for weirdness in each checker
for e in loclist
let e['type'] = e['text'] =~? '\m^[RCW]' ? 'W' : 'E'
if e['text'] =~# '\v\[%(mccabe|pep257|pylint)\]$'
if has_key(e, 'col')
let e['col'] += 1
endif
endif
if e['text'] =~# '\v\[pylint\]$'
if has_key(e, 'vcol')
let e['vcol'] = 0
endif
endif
if e['text'] =~# '\v\[%(mccabe|pep257|pep8)\]$'
let e['subtype'] = 'Style'
endif
endfor
return loclist
endfunction
runtime! syntax_checkers/python/pyflakes.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'pylama' })
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,83 @@
"============================================================================
"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
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
return s:pylint_new >= 0
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') })
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,
\ 'postprocess': ['sort'],
\ 'returns': range(32) })
for e in loclist
if !s:pylint_new
let e['type'] = e['text'][1]
endif
if e['type'] =~? '\m^[EF]'
let e['type'] = 'E'
elseif e['type'] =~? '\m^[CRW]'
let e['type'] = 'W'
else
let e['valid'] = 0
endif
let e['col'] += 1
let e['vcol'] = 0
endfor
return loclist
endfunction
function! s:PylintNew(exe)
let exe = syntastic#util#shescape(a:exe)
try
" On Windows the version is shown as "pylint-script.py 1.0.0".
" On Gentoo Linux it's "pylint-python2.7 0.28.0". Oh, joy. :)
let pylint_version = filter(split(system(exe . ' --version'), '\m, \=\|\n'), 'v:val =~# ''\m^pylint\>''')[0]
let pylint_version = substitute(pylint_version, '\v^\S+\s+', '', '')
let ret = syntastic#util#versionIsAtLeast(syntastic#util#parseVersion(pylint_version), [1])
catch /^Vim\%((\a\+)\)\=:E684/
call syntastic#log#error("checker python/pylint: can't parse version string (abnormal termination?)")
let ret = -1
endtry
return ret
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'pylint' })
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,46 @@
"============================================================================
"File: python.vim
"Description: Syntax checking plugin for syntastic.vim
"Maintainer: LCD 47 <lcd047 at gmail dot com>
"License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
"============================================================================
if exists("g:loaded_syntastic_python_python_checker")
finish
endif
let g:loaded_syntastic_python_python_checker = 1
let s:save_cpo = &cpo
set cpo&vim
let s:compiler = expand('<sfile>:p:h') . syntastic#util#Slash() . 'compile.py'
function! SyntaxCheckers_python_python_IsAvailable() dict
return executable(self.getExec()) &&
\ syntastic#util#versionIsAtLeast(syntastic#util#getVersion(self.getExecEscaped() . ' --version'), [2, 6])
endfunction
function! SyntaxCheckers_python_python_GetLocList() dict
let makeprg = self.makeprgBuild({ 'exe': [self.getExec(), s:compiler] })
let errorformat = '%E%f:%l:%c: %m'
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'returns': [0] })
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'python',
\ 'name': 'python'})
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4: