vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

cppcheck.vim (1737B)


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