update makeprg builder and update some checkers to use it

update makeprg builder:
* it now accepts `fname`, `tail`, and `post_args` params.
* add some doc above syntastic#makeprg#build
* update a bunch of checkers to use the new params

Still have quite a few checkers that arent using makeprg#build.
Including all c* and a few other c-like checkers. And PHP.

Not to worried about c* as these checkers are complicated and probably
justify having their own logic to build makeprgs.
This commit is contained in:
Martin Grenfell 2013-01-20 12:27:19 +00:00
parent 6a184f0e37
commit 5b31495af2
16 changed files with 125 additions and 57 deletions

View File

@ -3,60 +3,101 @@ if exists("g:loaded_syntastic_makeprg_autoload")
endif
let g:loaded_syntastic_makeprg_autoload = 1
"Returns a makeprg of the form
"
"[exe] [args] [filename] [post_args] [tail]
"
"A (made up) example:
" ruby -a -b -c test_file.rb --more --args > /tmp/output
"
"To generate this you would call:
"
" let makeprg = syntastic#makeprg#build({
" \ 'exe': 'ruby',
" \ 'args': '-a -b -c',
" \ 'post_args': '--more --args',
" \ 'tail': '> /tmp/output',
" \ 'subchecker': 'mri' })
"
"Note that the current filename is added by default - but can be overridden by
"passing in an 'fname' arg.
"
"All options can be overriden by the user with global variables - even when
"not specified by the checker in syntastic#makeprg#build().
"
"E.g. They could override the checker exe with
"
" let g:syntastic_ruby_mri_exe="another_ruby_checker_exe.rb"
"
"The general form of the override option is:
" syntastic_[filetype]_[subchecker]_[option-name]
"
function! syntastic#makeprg#build(opts)
let opts = copy(a:opts)
let builder = s:MakeprgBuilder.New(
\ get(a:opts, 'exe', ''),
\ get(a:opts, 'args', ''),
\ get(a:opts, 'fname', ''),
\ get(a:opts, 'post_args', ''),
\ get(a:opts, 'tail', ''),
\ get(a:opts, 'subchecker', '') )
if !has_key(opts, 'args')
let opts['args'] = ''
endif
if !has_key(opts, 'subchecker')
let opts['subchecker'] = ''
endif
let builder = s:MakeprgBuilder.New(opts['exe'], opts['args'], opts['subchecker'])
return builder.makeprg()
endfunction
let s:MakeprgBuilder = {}
function! s:MakeprgBuilder.New(exe, args, subchecker)
function! s:MakeprgBuilder.New(exe, args, fname, post_args, tail, subchecker)
let newObj = copy(self)
let newObj._exe = a:exe
let newObj._args = a:args
let newObj._fname = a:fname
let newObj._post_args = a:post_args
let newObj._tail = a:tail
let newObj._subchecker = a:subchecker
return newObj
endfunction
function! s:MakeprgBuilder.makeprg()
return join([self.exe(), self.args(), self.fname()])
return join([self.exe(), self.args(), self.fname(), self.post_args(), self.tail()])
endfunction
function! s:MakeprgBuilder.exe()
if self.optExists('exe')
return {self.optName('exe')}
endif
return self._exe
return self._getOpt('exe')
endfunction
function! s:MakeprgBuilder.args()
if exists('g:syntastic_' . &ft . '_args')
return g:syntastic_{&ft}_args
endif
return self._args
return self._getOpt('args')
endfunction
function! s:MakeprgBuilder.fname()
return shellescape(expand("%"))
if empty(self._fname)
return shellescape(expand("%"))
else
return self._fname
endif
endfunction
function! s:MakeprgBuilder.optExists(name)
return exists(self.optName(a:name))
function! s:MakeprgBuilder.post_args()
return self._getOpt('post_args')
endfunction
function! s:MakeprgBuilder.optName(name)
function! s:MakeprgBuilder.tail()
return self._getOpt('tail')
endfunction
function s:MakeprgBuilder._getOpt(name)
if self._optExists(a:name)
return {self._optName(a:name)}
endif
return self['_' . a:name]
endfunction
function! s:MakeprgBuilder._optExists(name)
return exists(self._optName(a:name))
endfunction
function! s:MakeprgBuilder._optName(name)
let setting = "g:syntastic_" . &ft
if !empty(self._subchecker)
let setting .= '_' . self._subchecker

View File

@ -16,8 +16,8 @@ function! SyntaxCheckers_dart_GetLocList()
let args = !empty(g:syntastic_dart_analyzer_conf) ? ' ' . g:syntastic_dart_analyzer_conf : ''
let makeprg = syntastic#makeprg#build({
\ 'exe': 'dart_analyzer',
\ 'post_args': args,
\ 'subchecker': 'dart_analyser' })
let makeprg .= ' ' . args
let errorformat = '%Efile:%f:%l:%c: %m'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })

View File

@ -16,8 +16,8 @@ function! SyntaxCheckers_go_GetLocList()
let makeprg = syntastic#makeprg#build({
\ 'exe': 'gofmt',
\ 'args': '-l',
\ 'tail': '1>' . syntastic#util#DevNull(),
\ 'subchecker': 'gofmt' })
let makeprg .= ' 1>/dev/null'
let errorformat = '%f:%l:%c: %m,%-G%.%#'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'type': 'e'} })
endfunction

View File

@ -61,8 +61,8 @@ function! SyntaxCheckers_html_GetLocList()
let makeprg = syntastic#makeprg#build({
\ 'exe': 'tidy',
\ 'args': s:Args(),
\ 'tail': '2>&1',
\ 'subchecker': 'tidy' })
let makeprg .= " 2>&1"
let errorformat='%Wline %l column %c - Warning: %m,%Eline %l column %c - Error: %m,%-G%.%#,%-G%.%#'
let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })

View File

@ -17,13 +17,13 @@ endif
if !exists("g:syntastic_java_checkstyle_conf_file")
let g:syntastic_java_checkstyle_conf_file = 'sun_checks.xml'
endif
function! SyntaxCheckers_java_GetLocList()
let makeprg = 'java -cp ' . g:syntastic_java_checkstyle_classpath . ' com.puppycrawl.tools.checkstyle.Main -c '
\. g:syntastic_java_checkstyle_conf_file . ' '
\. expand ( '%:p:h' ) . '/' . expand ( '%:t' )
\. ' 2>&1 '
let makeprg = syntastic#makeprg#build({
\ 'exe': 'java',
\ 'args': '-cp ' . g:syntastic_java_checkstyle_classpath . ' com.puppycrawl.tools.checkstyle.Main -c ' . g:syntastic_java_checkstyle_conf_file,
\ 'fname': expand ( '%:p:h' ) . '/' . expand ( '%:t' ),
\ 'tail': '2>&1',
\ 'subchecker': 'checkstyle' })
" check style format
let errorformat = '%f:%l:%c:\ %m,%f:%l:\ %m'

View File

@ -208,9 +208,12 @@ function! SyntaxCheckers_java_GetLocList()
let sep = '/'
endif
let makeprg = g:syntastic_java_javac_executable . ' '. javac_opts . ' '
\. fnameescape(expand ( '%:p:h' ) . sep . expand ( '%:t' ))
\. ' 2>&1 '
let makeprg = syntastic#makeprg#build({
\ 'exe': g:syntastic_java_javac_executable,
\ 'args': javac_opts,
\ 'fname': fnameescape(expand ( '%:p:h' ) . sep . expand ( '%:t' )),
\ 'tail': '2>&1',
\ 'subchecker': 'javac' })
" unashamedly stolen from *errorformat-javac* (quickfix.txt) and modified to include error types
let errorformat = '%E%f:%l:\ error:\ %m,%W%f:%l:\ warning:\ %m,%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#'

View File

@ -37,7 +37,12 @@ function! SyntaxCheckers_javascript_GetLocList()
let file_list = shellescape(expand('%'))
endif
let makeprg = 'java -jar ' . g:syntastic_javascript_closure_compiler_path . ' ' . g:syntastic_javascript_closure_compiler_options . ' --js ' . file_list
let makeprg = syntastic#makeprg#build({
\ 'exe': 'java -jar ' . g:syntastic_javascript_closure_compiler_path,
\ 'args': g:syntastic_javascript_closure_compiler_options . ' --js' ,
\ 'fname': file_list,
\ 'subchecker': 'closurecompiler' })
let errorformat = '%-GOK,%E%f:%l: ERROR - %m,%Z%p^,%W%f:%l: WARNING - %m,%Z%p^'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
endfunction

View File

@ -13,9 +13,16 @@ if !exists("g:syntastic_javascript_jshint_conf")
endif
function! SyntaxCheckers_javascript_GetLocList()
" node-jshint uses .jshintrc as config unless --config arg is present
let args = !empty(g:syntastic_javascript_jshint_conf) ? ' --config ' . g:syntastic_javascript_jshint_conf : ''
let makeprg = 'jshint ' . shellescape(expand("%")) . args
let makeprg = syntastic#makeprg#build({
\ 'exe': 'jshint',
\ 'post_args': s:Args(),
\ 'subchecker': 'jshint' })
let errorformat = '%ELine %l:%c,%Z\\s%#Reason: %m,%C%.%#,%f: line %l\, col %c\, %m,%-G%.%#'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr('')} })
endfunction
function s:Args()
" node-jshint uses .jshintrc as config unless --config arg is present
return !empty(g:syntastic_javascript_jshint_conf) ? ' --config ' . g:syntastic_javascript_jshint_conf : ''
endfunction

View File

@ -10,7 +10,10 @@
"============================================================================
function! SyntaxCheckers_json_GetLocList()
let makeprg = 'jsonlint ' . shellescape(expand("%")) . ' --compact'
let makeprg = syntastic#makeprg#build({
\ 'exe': 'jsonlint',
\ 'post_args': '--compact',
\ 'subchecker': 'jsonlint' })
let errorformat = '%ELine %l:%c,%Z\\s%#Reason: %m,%C%.%#,%f: line %l\, col %c\, %m,%-G%.%#'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr('')} })
endfunction

View File

@ -39,8 +39,8 @@ end
function! SyntaxCheckers_less_GetLocList()
let makeprg = syntastic#makeprg#build({
\ 'exe': s:check_file,
\ 'args': g:syntastic_less_options })
let makeprg .= syntastic#util#DevNull()
\ 'args': g:syntastic_less_options,
\ 'tail': syntastic#util#DevNull() })
let errorformat = '%m in %f:%l:%c'
return SyntasticMake({ 'makeprg': makeprg,

View File

@ -16,8 +16,10 @@ if !executable("clisp")
endif
function! SyntaxCheckers_lisp_GetLocList()
let makeprg = syntastic#makeprg#build({ 'exe': 'clisp', 'args': '-c' })
let makeprg .= ' -o /tmp/clisp-vim-compiled-file'
let makeprg = syntastic#makeprg#build({
\ 'exe': 'clisp',
\ 'args': '-c'
\ 'tail': '-o /tmp/clisp-vim-compiled-file' })
let efm = '%-G;%.%#,'
let efm .= '%W%>WARNING:%.%#line %l : %m,%C %#%m,'
let efm .= '%E%>The following functions were %m,%Z %m,'

View File

@ -8,10 +8,15 @@ function! SyntaxCheckers_python_GetLocList()
let makeprg = syntastic#makeprg#build({
\ 'exe': 'pylint',
\ 'args': g:syntastic_python_checker_args. ' -f parseable -r n -i y',
\ 'tail': s:MakeprgTail(),
\ 'subchecker': 'pylint' })
let makeprg .= ' 2>&1 \| sed ''s_: \[\([RCW]\)_: \[W] \[\1_''' .
\ ' \| sed ''s_: \[\([FE]\)_:\ \[E] \[\1_'''
let errorformat = '%f:%l: [%t] %m,%Z,%-GNo config %m'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
endfunction
function! s:MakeprgTail()
return ' 2>&1 \| sed ''s_: \[\([RCW]\)_: \[W] \[\1_''' .
\ ' \| sed ''s_: \[\([FE]\)_:\ \[E] \[\1_'''
endfunction

View File

@ -21,9 +21,8 @@ endif
function! SyntaxCheckers_rst_GetLocList()
let makeprg = syntastic#makeprg#build({
\ 'exe': 'rst2pseudoxml.py',
\ 'args': '--report=2 --exit-status=1' })
let makeprg .= syntastic#util#DevNull()
\ 'args': '--report=2 --exit-status=1',
\ 'tail': syntastic#util#DevNull() })
let errorformat = '%f:%l:\ (%tNFO/1)\ %m,
\%f:%l:\ (%tARNING/2)\ %m,

View File

@ -12,8 +12,10 @@
"
"============================================================================
function! SyntaxCheckers_tcl_GetLocList()
let makeprg = "nagelfar -H " . g:syntastic_tcl_nagelfar_conf . " " . shellescape(expand('%'))
let makeprg = syntastic#makeprg#build({
\ 'exe': 'nagelfar',
\ 'args': '-H ' . g:syntastic_tcl_nagelfar_conf,
\ 'subchecker': 'nagelfar' })
let errorformat='%I%f: %l: N %m, %f: %l: %t %m, %-GChecking file %f'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })

View File

@ -16,7 +16,7 @@ if !executable("tclsh")
endif
function! SyntaxCheckers_tclsh_GetLocList()
let makeprg = 'tclsh '.shellescape(expand('%'))
let makeprg = syntastic#makeprg#build({'exe': 'tclsh'})
let errorformat = '%f:%l:%m'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })

View File

@ -10,8 +10,9 @@ if !executable("tsc")
endif
function! SyntaxCheckers_typescript_GetLocList()
let makeprg = syntastic#makeprg#build({ 'exe': 'tsc' })
let makeprg .= ' --out ' . syntastic#util#DevNull()
let makeprg = syntastic#makeprg#build({
\ 'exe': 'tsc',
\ 'post_args': '--out ' . syntastic#util#DevNull() })
let errorformat = '%f %#(%l\,%c): %m'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
endfunction