validator.vim 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "============================================================================
  2. "File: validator.vim
  3. "Description: Syntax checking plugin for syntastic
  4. "Maintainer: LCD 47 <lcd047 at gmail dot com>
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. "============================================================================
  12. if exists('g:loaded_syntastic_html_validator_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_html_validator_checker=1
  16. let s:save_cpo = &cpo
  17. set cpo&vim
  18. " Constants {{{1
  19. let s:DEFAULTS = {
  20. \ 'api': 'https://validator.nu/',
  21. \ 'nsfilter': '',
  22. \ 'parser': '',
  23. \ 'schema': '' }
  24. let s:CONTENT_TYPE = {
  25. \ 'html': 'text/html',
  26. \ 'svg': 'image/svg+xml',
  27. \ 'xhtm': 'application/xhtml+xml' }
  28. " }}}1
  29. " @vimlint(EVL101, 1, l:api)
  30. " @vimlint(EVL101, 1, l:nsfilter)
  31. " @vimlint(EVL101, 1, l:parser)
  32. " @vimlint(EVL101, 1, l:schema)
  33. function! SyntaxCheckers_html_validator_GetLocList() dict " {{{1
  34. let buf = bufnr('')
  35. let type = self.getFiletype()
  36. let fname = syntastic#util#shescape(fnamemodify(bufname(buf), ':p'))
  37. for key in keys(s:DEFAULTS)
  38. let l:{key} = syntastic#util#var(type . '_validator_' . key, get(s:DEFAULTS, key))
  39. endfor
  40. let ctype = get(s:CONTENT_TYPE, type, '')
  41. " vint: -ProhibitUsingUndeclaredVariable
  42. let makeprg = self.getExecEscaped() . ' -q -L -s --compressed -F out=gnu -F asciiquotes=yes' .
  43. \ (nsfilter !=# '' ? ' -F nsfilter=' . syntastic#util#shescape(nsfilter) : '') .
  44. \ (parser !=# '' ? ' -F parser=' . parser : '') .
  45. \ (schema !=# '' ? ' -F schema=' . syntastic#util#shescape(schema) : '') .
  46. \ ' -F doc=@' . fname .
  47. \ (ctype !=# '' ? '\;type=' . ctype : '') .
  48. \ '\;filename=' . fname .
  49. \ ' ' . api
  50. " vint: ProhibitUsingUndeclaredVariable
  51. let errorformat =
  52. \ '%E"%f":%l: %trror: %m,' .
  53. \ '%E"%f":%l-%\d%\+: %trror: %m,' .
  54. \ '%E"%f":%l%\%.%c: %trror: %m,' .
  55. \ '%E"%f":%l%\%.%c-%\d%\+%\%.%\d%\+: %trror: %m,' .
  56. \ '%E"%f":%l: %trror fatal: %m,' .
  57. \ '%E"%f":%l-%\d%\+: %trror fatal: %m,' .
  58. \ '%E"%f":%l%\%.%c: %trror fatal: %m,' .
  59. \ '%E"%f":%l%\%.%c-%\d%\+%\%.%\d%\+: %trror fatal: %m,' .
  60. \ '%W"%f":%l: info %tarning: %m,' .
  61. \ '%W"%f":%l-%\d%\+: info %tarning: %m,' .
  62. \ '%W"%f":%l%\%.%c: info %tarning: %m,' .
  63. \ '%W"%f":%l%\%.%c-%\d%\+%\%.%\d%\+: info %tarning: %m'
  64. return SyntasticMake({
  65. \ 'makeprg': makeprg,
  66. \ 'errorformat': errorformat,
  67. \ 'preprocess': 'validator',
  68. \ 'returns': [0] })
  69. endfunction " }}}1
  70. " @vimlint(EVL101, 0, l:schema)
  71. " @vimlint(EVL101, 0, l:parser)
  72. " @vimlint(EVL101, 0, l:nsfilter)
  73. " @vimlint(EVL101, 0, l:api)
  74. call g:SyntasticRegistry.CreateAndRegisterChecker({
  75. \ 'filetype': 'html',
  76. \ 'name': 'validator',
  77. \ 'exec': 'curl' })
  78. let &cpo = s:save_cpo
  79. unlet s:save_cpo
  80. " vim: set sw=4 sts=4 et fdm=marker: