cppcheck.vim 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. " vim compiler file
  2. " Compiler: cppcheck (C++ static checker)
  3. " Maintainer: Vincent B. (twinside@free.fr)
  4. " Last Change: 2024 Nov 19 by @Konfekt
  5. if exists("current_compiler") | finish | endif
  6. let current_compiler = "cppcheck"
  7. let s:cpo_save = &cpo
  8. set cpo&vim
  9. let s:slash = has('win32')? '\' : '/'
  10. if !exists('g:c_cppcheck_params')
  11. let g:c_cppcheck_params = '--verbose --force --inline-suppr'
  12. \ ..' '..'--enable=warning,style,performance,portability,information,missingInclude'
  13. \ ..' '..(executable('getconf') ? '-j' .. systemlist('getconf _NPROCESSORS_ONLN')[0] : '')
  14. let s:undo_compiler = 'unlet! g:c_cppcheck_params'
  15. endif
  16. let &l:makeprg = 'cppcheck --quiet'
  17. \ ..' --template="{file}:{line}:{column}: {severity}: [{id}] {message} {callstack}"'
  18. \ ..' '..get(b:, 'c_cppcheck_params', get(g:, 'c_cppcheck_params', (&filetype ==# 'cpp' ? ' --language=c++' : '')))
  19. \ ..' '..get(b:, 'c_cppcheck_includes', get(g:, 'c_cppcheck_includes',
  20. \ (filereadable('compile_commands.json') ? '--project=compile_commands.json' :
  21. \ (!empty(glob('*'..s:slash..'compile_commands.json', 1, 1)) ? '--project='..glob('*'..s:slash..'compile_commands.json', 1, 1)[0] :
  22. \ (empty(&path) ? '' : '-I')..join(map(filter(split(&path, ','), 'isdirectory(v:val)'),'shellescape(v:val)'), ' -I')))))
  23. exe 'CompilerSet makeprg='..escape(&l:makeprg, ' \|"')
  24. CompilerSet errorformat=
  25. \%f:%l:%c:\ %tarning:\ %m,
  26. \%f:%l:%c:\ %trror:\ %m,
  27. \%f:%l:%c:\ %tnformation:\ %m,
  28. \%f:%l:%c:\ %m,
  29. \%.%#\ :\ [%f:%l]\ %m
  30. exe get(s:, 'undo_compiler', '')
  31. let &cpo = s:cpo_save
  32. unlet s:cpo_save