2018-03-31 10:55:20 -04:00
|
|
|
" Author: Bart Libert <bart.libert@gmail.com>
|
|
|
|
" Description: cppcheck linter for c files
|
|
|
|
|
|
|
|
call ale#Set('c_cppcheck_executable', 'cppcheck')
|
|
|
|
call ale#Set('c_cppcheck_options', '--enable=style')
|
|
|
|
|
|
|
|
function! ale_linters#c#cppcheck#GetCommand(buffer) abort
|
|
|
|
" 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-25 12:13:42 -04:00
|
|
|
\ . '%e -q --language=c '
|
2018-03-31 10:55:20 -04:00
|
|
|
\ . l:compile_commands_option
|
|
|
|
\ . ale#Var(a:buffer, 'c_cppcheck_options')
|
|
|
|
\ . ' %t'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('c', {
|
|
|
|
\ 'name': 'cppcheck',
|
|
|
|
\ 'output_stream': 'both',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'c_cppcheck_executable')},
|
|
|
|
\ 'command': function('ale_linters#c#cppcheck#GetCommand'),
|
2018-03-31 10:55:20 -04:00
|
|
|
\ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat',
|
|
|
|
\})
|