From 3dc0b6dc2414aba9dd3bac1e17295fd2318f7dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Thu, 7 Mar 2013 21:20:55 -0500 Subject: [PATCH 1/2] Made SyntacticIsVersionAtLeast more robust It now handles more cases, which will cause Syntastic to degrade better when commands return weird versions (e.g. the command crashes). --- plugin/syntastic.vim | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 69a8f7e4..54674448 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -509,17 +509,34 @@ function! s:uname() return s:uname endfunction -"the args must be arrays of the form [major, minor, macro] +" Verify that the 'installed' version is at the 'required' version, if not +" better. +" +" 'installed' and 'required' must be arrays. Only the +" first three elements (major, minor, patch) are looked at. +" +" Either array may be less than three elements. The "missing" elements +" will be assumed to be '0' for the purposes of checking. +" +" See http://semver.org for info about version numbers. function SyntasticIsVersionAtLeast(installed, required) - if a:installed[0] != a:required[0] - return a:installed[0] > a:required[0] - endif - - if a:installed[1] != a:required[1] - return a:installed[1] > a:required[1] - endif - - return a:installed[2] >= a:required[2] + for index in [0,1,2] + if len(a:installed) <= index + let installed_element = 0 + else + let installed_element = a:installed[index] + endif + if len(a:required) <= index + let required_element = 0 + else + let required_element = a:required[index] + endif + if installed_element != required_element + return installed_element > required_element + endif + endfor + " Everything matched, so it is at least the required version. + return 1 endfunction "return a string representing the state of buffer according to From 2f4fc380530822c075e060fce9b71e7d18a5b7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Fri, 8 Mar 2013 11:58:49 -0500 Subject: [PATCH 2/2] Renamed version check function Moved the `SyntasticIsVersionAtLeast()` into `util.vim` as `syntastic#util#versionIsAtLeast()` as per @scrooloose's suggestion. --- autoload/syntastic/util.vim | 31 +++++++++++++++++++++++++++ plugin/syntastic.vim | 30 -------------------------- syntax_checkers/puppet/puppetlint.vim | 6 +++--- syntax_checkers/slim/slimrb.vim | 2 +- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/autoload/syntastic/util.vim b/autoload/syntastic/util.vim index e570484c..2969a525 100644 --- a/autoload/syntastic/util.vim +++ b/autoload/syntastic/util.vim @@ -37,6 +37,37 @@ function! syntastic#util#ParseShebang() return {'exe': '', 'args': []} endfunction +" Verify that the 'installed' version is at the 'required' version, if not +" better. +" +" 'installed' and 'required' must be arrays. Only the +" first three elements (major, minor, patch) are looked at. +" +" Either array may be less than three elements. The "missing" elements +" will be assumed to be '0' for the purposes of checking. +" +" See http://semver.org for info about version numbers. +function syntastic#util#versionIsAtLeast(installed, required) + for index in [0,1,2] + if len(a:installed) <= index + let installed_element = 0 + else + let installed_element = a:installed[index] + endif + if len(a:required) <= index + let required_element = 0 + else + let required_element = a:required[index] + endif + if installed_element != required_element + return installed_element > required_element + endif + endfor + " Everything matched, so it is at least the required version. + return 1 +endfunction + + let &cpo = s:save_cpo unlet s:save_cpo " vim: set et sts=4 sw=4: diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 54674448..a7eee8a1 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -509,36 +509,6 @@ function! s:uname() return s:uname endfunction -" Verify that the 'installed' version is at the 'required' version, if not -" better. -" -" 'installed' and 'required' must be arrays. Only the -" first three elements (major, minor, patch) are looked at. -" -" Either array may be less than three elements. The "missing" elements -" will be assumed to be '0' for the purposes of checking. -" -" See http://semver.org for info about version numbers. -function SyntasticIsVersionAtLeast(installed, required) - for index in [0,1,2] - if len(a:installed) <= index - let installed_element = 0 - else - let installed_element = a:installed[index] - endif - if len(a:required) <= index - let required_element = 0 - else - let required_element = a:required[index] - endif - if installed_element != required_element - return installed_element > required_element - endif - endfor - " Everything matched, so it is at least the required version. - return 1 -endfunction - "return a string representing the state of buffer according to "g:syntastic_stl_format " diff --git a/syntax_checkers/puppet/puppetlint.vim b/syntax_checkers/puppet/puppetlint.vim index 1729f362..72173859 100644 --- a/syntax_checkers/puppet/puppetlint.vim +++ b/syntax_checkers/puppet/puppetlint.vim @@ -51,7 +51,7 @@ function! s:PuppetLintVersion() endfunction if !g:syntastic_puppet_lint_disable - if !SyntasticIsVersionAtLeast(s:PuppetLintVersion(), [0,1,10]) + if !syntastic#util#versionIsAtLeast(s:PuppetLintVersion(), [0,1,10]) let g:syntastic_puppet_lint_disable = 1 endif end @@ -68,7 +68,7 @@ endfunction function! s:getPuppetMakeprg() "If puppet is >= version 2.7 then use the new executable - if SyntasticIsVersionAtLeast(s:PuppetVersion(), [2,7,0]) + if syntastic#util#versionIsAtLeast(s:PuppetVersion(), [2,7,0]) let makeprg = 'puppet parser validate ' . \ shellescape(expand('%')) . \ ' --color=false' @@ -86,7 +86,7 @@ function! s:getPuppetEfm() "Puppet 3.0.0 changes this from "err:" to "Error:" "reset errorformat in that case - if SyntasticIsVersionAtLeast(s:PuppetVersion(), [3,0,0]) + if syntastic#util#versionIsAtLeast(s:PuppetVersion(), [3,0,0]) let errorformat = '%-GError: Try ''puppet help parser validate'' for usage,' let errorformat .= 'Error: Could not parse for environment %*[a-z]: %m at %f:%l' endif diff --git a/syntax_checkers/slim/slimrb.vim b/syntax_checkers/slim/slimrb.vim index 92011075..ca159e0b 100644 --- a/syntax_checkers/slim/slimrb.vim +++ b/syntax_checkers/slim/slimrb.vim @@ -33,7 +33,7 @@ function! SyntaxCheckers_slim_slimrb_GetLocList() let makeprg = syntastic#makeprg#build({ \ 'exe': 'slimrb', \ 'args': '-c' }) - if SyntasticIsVersionAtLeast(s:SlimrbVersion(), [1,3,1]) + if syntastic#util#versionIsAtLeast(s:SlimrbVersion(), [1,3,1]) let errorformat = '%C\ %#%f\, Line %l\, Column %c,%-G\ %.%#,%ESlim::Parser::SyntaxError: %m,%+C%.%#' else let errorformat = '%C\ %#%f\, Line %l,%-G\ %.%#,%ESlim::Parser::SyntaxError: %m,%+C%.%#'