2017-06-24 11:10:04 -04:00
|
|
|
" Author: gagbo <gagbobada@gmail.com>
|
|
|
|
" Description: clang-check linter for cpp files
|
|
|
|
|
2017-07-16 18:35:10 -04:00
|
|
|
call ale#Set('cpp_clangcheck_executable', 'clang-check')
|
|
|
|
call ale#Set('cpp_clangcheck_options', '')
|
|
|
|
call ale#Set('c_build_dir', '')
|
2017-06-24 11:10:04 -04:00
|
|
|
|
|
|
|
function! ale_linters#cpp#clangcheck#GetCommand(buffer) abort
|
|
|
|
let l:user_options = ale#Var(a:buffer, 'cpp_clangcheck_options')
|
|
|
|
|
|
|
|
" Try to find compilation database to link automatically
|
2017-07-16 18:35:10 -04:00
|
|
|
let l:build_dir = ale#Var(a:buffer, 'c_build_dir')
|
|
|
|
|
|
|
|
if empty(l:build_dir)
|
2018-07-29 14:24:19 -04:00
|
|
|
let l:build_dir = ale#path#Dirname(ale#c#FindCompileCommands(a:buffer))
|
2017-06-24 11:10:04 -04:00
|
|
|
endif
|
|
|
|
|
2017-07-17 05:19:08 -04:00
|
|
|
" The extra arguments in the command are used to prevent .plist files from
|
|
|
|
" being generated. These are only added if no build directory can be
|
|
|
|
" detected.
|
2018-08-02 18:44:12 -04:00
|
|
|
return '%e -analyze %s'
|
2018-01-01 06:02:32 -05:00
|
|
|
\ . (empty(l:build_dir) ? ' -extra-arg -Xclang -extra-arg -analyzer-output=text' : '')
|
2018-08-02 18:44:12 -04:00
|
|
|
\ . ale#Pad(l:user_options)
|
2017-07-16 18:35:10 -04:00
|
|
|
\ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
|
2017-06-24 11:10:04 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('cpp', {
|
|
|
|
\ 'name': 'clangcheck',
|
|
|
|
\ 'output_stream': 'stderr',
|
2019-02-22 13:05:04 -05:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'cpp_clangcheck_executable')},
|
|
|
|
\ 'command': function('ale_linters#cpp#clangcheck#GetCommand'),
|
2017-06-24 11:10:04 -04:00
|
|
|
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
|
|
|
\ 'lint_file': 1,
|
|
|
|
\})
|