From 4b9bf4405b111935dddcdd82695a5dcd80b7dca8 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Sun, 14 Jul 2013 19:13:18 +0300 Subject: [PATCH 1/3] Pylama: new checker for Python 2. Minor refactoring. --- syntax_checkers/python/flake8.vim | 16 ++------- syntax_checkers/python/pyflakes.vim | 26 +++++++++------ syntax_checkers/python/pylama.vim | 50 +++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 22 deletions(-) create mode 100644 syntax_checkers/python/pylama.vim diff --git a/syntax_checkers/python/flake8.vim b/syntax_checkers/python/flake8.vim index 703ba9a9..796ba6bd 100644 --- a/syntax_checkers/python/flake8.vim +++ b/syntax_checkers/python/flake8.vim @@ -15,19 +15,7 @@ function! SyntaxCheckers_python_flake8_IsAvailable() endfunction function! SyntaxCheckers_python_flake8_GetHighlightRegex(i) - if match(a:i['text'], 'is assigned to but never used') > -1 - \ || match(a:i['text'], 'imported but unused') > -1 - \ || match(a:i['text'], 'undefined name') > -1 - \ || match(a:i['text'], 'redefinition of') > -1 - \ || match(a:i['text'], 'referenced before assignment') > -1 - \ || match(a:i['text'], 'duplicate argument') > -1 - \ || match(a:i['text'], 'after other statements') > -1 - \ || match(a:i['text'], 'shadowed by loop variable') > -1 - - let term = split(a:i['text'], "'", 1)[1] - return '\V\<'.term.'\>' - endif - return '' + return SyntaxCheckers_python_pyflakes_GetHighlightRegex(a:i) endfunction function! SyntaxCheckers_python_flake8_GetLocList() @@ -52,3 +40,5 @@ endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ \ 'filetype': 'python', \ 'name': 'flake8'}) + +runtime! syntax_checkers/python/pyflakes.vim diff --git a/syntax_checkers/python/pyflakes.vim b/syntax_checkers/python/pyflakes.vim index 80351367..f93047bf 100644 --- a/syntax_checkers/python/pyflakes.vim +++ b/syntax_checkers/python/pyflakes.vim @@ -17,16 +17,24 @@ endfunction function! SyntaxCheckers_python_pyflakes_GetHighlightRegex(i) if match(a:i['text'], 'is assigned to but never used') > -1 - \ || match(a:i['text'], 'imported but unused') > -1 - \ || match(a:i['text'], 'undefined name') > -1 - \ || match(a:i['text'], 'redefinition of') > -1 - \ || match(a:i['text'], 'referenced before assignment') > -1 - \ || match(a:i['text'], 'duplicate argument') > -1 - \ || match(a:i['text'], 'after other statements') > -1 - \ || match(a:i['text'], 'shadowed by loop variable') > -1 + \ || match(a:i['text'], 'imported but unused') > -1 + \ || match(a:i['text'], 'undefined name') > -1 + \ || match(a:i['text'], 'redefinition of') > -1 + \ || match(a:i['text'], 'referenced before assignment') > -1 + \ || match(a:i['text'], 'duplicate argument') > -1 + \ || match(a:i['text'], 'after other statements') > -1 + \ || match(a:i['text'], 'shadowed by loop variable') > -1 - let term = split(a:i['text'], "'", 1)[1] - return '\V\<'.term.'\>' + " 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 diff --git a/syntax_checkers/python/pylama.vim b/syntax_checkers/python/pylama.vim new file mode 100644 index 00000000..eef14ba3 --- /dev/null +++ b/syntax_checkers/python/pylama.vim @@ -0,0 +1,50 @@ +"============================================================================ +"File: pylama.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: LCD 47 +"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 + +function! SyntaxCheckers_python_pylama_IsAvailable() + return executable('pylama') +endfunction + +function! SyntaxCheckers_python_pylama_GetHighlightRegex(i) + return SyntaxCheckers_python_pyflakes_GetHighlightRegex(a:i) +endfunction + +function! SyntaxCheckers_python_pylama_GetLocList() + let makeprg = syntastic#makeprg#build({ + \ 'exe': 'pylama', + \ 'post_args': ' -f pep8', + \ 'filetype': 'python', + \ 'subchecker': 'pylama' }) + + let errorformat = '%A%f:%l:%c: %m' + + let loclist=SyntasticMake({ + \ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'postprocess': ['sort'] }) + + for n in range(len(loclist)) + let loclist[n]['type'] = match(['R', 'C', 'W'], loclist[n]['text'][0]) >= 0 ? 'W' : 'E' + endfor + + return loclist +endfunction + +call g:SyntasticRegistry.CreateAndRegisterChecker({ + \ 'filetype': 'python', + \ 'name': 'pylama' }) + +runtime! syntax_checkers/python/pyflakes.vim From ba0f349dbf514dc876e1cfc683734f35c5087e11 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Mon, 15 Jul 2013 11:24:41 +0300 Subject: [PATCH 2/3] Pylama: pep8, pep257, and mccabe are style checkers. --- syntax_checkers/python/pylama.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/syntax_checkers/python/pylama.vim b/syntax_checkers/python/pylama.vim index eef14ba3..4d7d02ad 100644 --- a/syntax_checkers/python/pylama.vim +++ b/syntax_checkers/python/pylama.vim @@ -38,6 +38,9 @@ function! SyntaxCheckers_python_pylama_GetLocList() for n in range(len(loclist)) let loclist[n]['type'] = match(['R', 'C', 'W'], loclist[n]['text'][0]) >= 0 ? 'W' : 'E' + if loclist[n]['text'] =~# '\v\[%(pep8|pep257|mccabe)\]$' + let loclist[n]['subtype'] = 'Style' + endif endfor return loclist From 60578c35d2a4babd0eab9bb2afafc6cece449e98 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Mon, 15 Jul 2013 18:37:37 +0300 Subject: [PATCH 3/3] Bug fix: g:syntastic_auto_jump should jump on checks, not on writes. --- plugin/syntastic.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index d6fa8ddc..b603149a 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -129,7 +129,8 @@ function! s:UpdateErrors(auto_invoked, ...) return endif - if !a:auto_invoked || s:modemap.allowsAutoChecking(&filetype) + let run_checks = !a:auto_invoked || s:modemap.allowsAutoChecking(&filetype) + if run_checks if a:0 >= 1 call s:CacheErrors(a:1) else @@ -141,7 +142,7 @@ function! s:UpdateErrors(auto_invoked, ...) if g:syntastic_always_populate_loc_list || g:syntastic_auto_jump call setloclist(0, loclist.filteredRaw()) - if g:syntastic_auto_jump && loclist.hasErrorsOrWarningsToDisplay() + if run_checks && g:syntastic_auto_jump && loclist.hasErrorsOrWarningsToDisplay() silent! lrewind endif endif