2016-10-20 11:30:45 +00:00
|
|
|
" Author: Bart Libert <bart.libert@gmail.com>
|
|
|
|
" Description: cppcheck linter for c files
|
|
|
|
|
2017-07-16 21:11:43 +00:00
|
|
|
call ale#Set('c_cppcheck_executable', 'cppcheck')
|
|
|
|
call ale#Set('c_cppcheck_options', '--enable=style')
|
|
|
|
|
2017-04-15 12:35:54 +00:00
|
|
|
function! ale_linters#c#cppcheck#GetCommand(buffer) abort
|
2017-05-02 20:18:17 +00:00
|
|
|
" Search upwards from the file for compile_commands.json.
|
|
|
|
"
|
|
|
|
" If we find it, we'll `cd` to where the compile_commands.json file is,
|
|
|
|
" then use the file to set up import paths, etc.
|
|
|
|
let l:compile_commmands_path = ale#path#FindNearestFile(a:buffer, 'compile_commands.json')
|
|
|
|
|
|
|
|
let l:cd_command = !empty(l:compile_commmands_path)
|
|
|
|
\ ? ale#path#CdString(fnamemodify(l:compile_commmands_path, ':h'))
|
|
|
|
\ : ''
|
|
|
|
let l:compile_commands_option = !empty(l:compile_commmands_path)
|
|
|
|
\ ? '--project=compile_commands.json '
|
|
|
|
\ : ''
|
|
|
|
|
|
|
|
return l:cd_command
|
2018-08-02 22:44:12 +00:00
|
|
|
\ . '%e -q --language=c '
|
2017-05-02 20:18:17 +00:00
|
|
|
\ . l:compile_commands_option
|
2017-04-16 00:24:08 +00:00
|
|
|
\ . ale#Var(a:buffer, 'c_cppcheck_options')
|
2017-04-15 12:35:54 +00:00
|
|
|
\ . ' %t'
|
|
|
|
endfunction
|
|
|
|
|
2016-10-20 11:30:45 +00:00
|
|
|
call ale#linter#Define('c', {
|
|
|
|
\ 'name': 'cppcheck',
|
|
|
|
\ 'output_stream': 'both',
|
2018-08-02 22:44:12 +00:00
|
|
|
\ 'executable_callback': ale#VarFunc('c_cppcheck_executable'),
|
2017-04-15 12:35:54 +00:00
|
|
|
\ 'command_callback': 'ale_linters#c#cppcheck#GetCommand',
|
2017-04-24 21:27:18 +00:00
|
|
|
\ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat',
|
2016-10-20 11:30:45 +00:00
|
|
|
\})
|