2014-02-08 05:05:16 -05:00
|
|
|
"============================================================================
|
|
|
|
"File: vimlint.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.
|
|
|
|
"
|
|
|
|
"============================================================================
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
if exists('g:loaded_syntastic_vim_vimlint_checker')
|
2014-02-08 05:05:16 -05:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_syntastic_vim_vimlint_checker = 1
|
|
|
|
|
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
function! SyntaxCheckers_vim_vimlint_GetHighlightRegex(item) " {{{1
|
2014-02-08 05:05:16 -05:00
|
|
|
let term = matchstr(a:item['text'], '\m `\zs[^`]\+\ze`')
|
2015-07-13 06:22:46 -04:00
|
|
|
if term !=# ''
|
2014-02-08 05:05:16 -05:00
|
|
|
let col = get(a:item, 'col', 0)
|
|
|
|
|
|
|
|
if col && term[0:1] ==# 'l:'
|
|
|
|
if getline(a:item.lnum)[col-1:col] !=# 'l:'
|
|
|
|
let term = term[2:]
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2014-07-02 07:18:18 -04:00
|
|
|
return col ? '\%>' . (col - 1) . 'c\%<' . (col + strlen(term)) . 'c' : '\V' . escape(term, '\')
|
2014-02-08 05:05:16 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
return ''
|
2015-01-18 07:58:28 -05:00
|
|
|
endfunction " }}}1
|
2014-02-08 05:05:16 -05:00
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
function! SyntaxCheckers_vim_vimlint_IsAvailable() dict " {{{1
|
|
|
|
let vimlparser = globpath(&runtimepath, 'autoload/vimlparser.vim', 1)
|
|
|
|
let vimlint = globpath(&runtimepath, 'autoload/vimlint.vim', 1)
|
|
|
|
call self.log("globpath(&runtimepath, 'autoload/vimlparser.vim', 1) = " . string(vimlparser) . ', ' .
|
|
|
|
\ "globpath(&runtimepath, 'autoload/vimlint.vim', 1) = " . string(vimlint))
|
2015-07-13 06:22:46 -04:00
|
|
|
return vimlparser !=# '' && vimlint !=# ''
|
2015-01-18 07:58:28 -05:00
|
|
|
endfunction " }}}1
|
2014-02-08 05:05:16 -05:00
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
function! SyntaxCheckers_vim_vimlint_GetLocList() dict " {{{1
|
2014-02-08 05:05:16 -05:00
|
|
|
" EVL102: unused variable v
|
|
|
|
" EVL103: unused argument v
|
|
|
|
" EVL104: variable may not be initialized on some execution path: v
|
|
|
|
" EVL105: global variable v is defined without g:
|
|
|
|
" EVL106: local variable v is used without l:
|
|
|
|
" EVL201: unreachable code
|
|
|
|
" EVL204: constant in conditional context
|
|
|
|
" EVL205: missing scriptencoding
|
|
|
|
" value 3: the message is a warning
|
|
|
|
"
|
|
|
|
" References: :help vimlint-errorcode and :help vimlint-variables
|
2014-08-03 18:02:51 -04:00
|
|
|
let param = {
|
2014-02-08 05:05:16 -05:00
|
|
|
\ 'output': function('s:vimlintOutput'),
|
|
|
|
\ 'quiet': 1,
|
|
|
|
\ 'EVL102': 3,
|
|
|
|
\ 'EVL103': 3,
|
|
|
|
\ 'EVL104': 3,
|
|
|
|
\ 'EVL105': 3,
|
|
|
|
\ 'EVL106': 3,
|
|
|
|
\ 'EVL201': 3,
|
|
|
|
\ 'EVL204': 3,
|
2014-08-03 18:02:51 -04:00
|
|
|
\ 'EVL205': 3 }
|
|
|
|
|
2016-06-26 07:12:36 -04:00
|
|
|
if exists('g:syntastic_vimlint_options') || exists('b:syntastic_vimlint_options')
|
|
|
|
let opts = syntastic#util#var('vimlint_options')
|
|
|
|
if type(opts) == type({})
|
|
|
|
let options = filter(copy(opts), 'v:key =~# "\\m^EVL"')
|
2014-08-03 18:02:51 -04:00
|
|
|
call extend(param, options, 'force')
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2015-12-08 08:20:04 -05:00
|
|
|
call self.log('options =', param)
|
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
return vimlint#vimlint(expand('%', 1), param)
|
|
|
|
endfunction " }}}1
|
|
|
|
|
|
|
|
" Utilities {{{1
|
2014-02-08 05:05:16 -05:00
|
|
|
|
|
|
|
" @vimlint(EVL103, 1, a:filename)
|
2015-01-18 07:58:28 -05:00
|
|
|
function! s:vimlintOutput(filename, pos, ev, eid, mes, obj) " {{{2
|
2014-02-08 05:05:16 -05:00
|
|
|
call add(a:obj.error, {
|
|
|
|
\ 'bufnr': bufnr(''),
|
|
|
|
\ 'lnum': a:pos.lnum,
|
|
|
|
\ 'col': a:pos.col,
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'type': a:ev[0],
|
|
|
|
\ 'text': '[' . a:eid . '] ' . a:mes,
|
2014-02-16 12:46:49 -05:00
|
|
|
\ 'valid': a:pos.lnum > 0 })
|
2015-01-18 07:58:28 -05:00
|
|
|
endfunction " }}}2
|
2014-02-08 05:05:16 -05:00
|
|
|
" @vimlint(EVL103, 0, a:filename)
|
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
" }}}1
|
|
|
|
|
2014-02-08 05:05:16 -05:00
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
|
|
|
\ 'filetype': 'vim',
|
2016-11-09 12:22:55 -05:00
|
|
|
\ 'name': 'vimlint' })
|
2014-02-08 05:05:16 -05:00
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|