2017-06-24 11:38:16 +00:00
|
|
|
" Author: vdeurzen <tim@kompiler.org>, w0rp <devw0rp@gmail.com>,
|
|
|
|
" gagbo <gagbobada@gmail.com>
|
2017-02-11 23:32:56 +00:00
|
|
|
" Description: clang-tidy linter for cpp files
|
|
|
|
|
2017-05-02 21:44:08 +00:00
|
|
|
" Set this option to check the checks clang-tidy will apply.
|
|
|
|
let g:ale_cpp_clangtidy_checks = get(g:, 'ale_cpp_clangtidy_checks', ['*'])
|
|
|
|
|
|
|
|
" Set this option to manually set some options for clang-tidy.
|
|
|
|
" This will disable compile_commands.json detection.
|
|
|
|
let g:ale_cpp_clangtidy_options = get(g:, 'ale_cpp_clangtidy_options', '')
|
2017-02-11 23:45:06 +00:00
|
|
|
|
2017-06-24 11:38:16 +00:00
|
|
|
" Set this option to manually point to the build directory for clang-tidy.
|
|
|
|
" This will disable all the other clangtidy_options, since compilation
|
|
|
|
" flags are contained in the json
|
|
|
|
let g:ale_c_build_dir = get(g:, 'ale_c_build_dir', '')
|
|
|
|
|
|
|
|
|
2017-02-11 23:45:06 +00:00
|
|
|
function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
|
2017-05-02 21:44:08 +00:00
|
|
|
let l:check_list = ale#Var(a:buffer, 'cpp_clangtidy_checks')
|
|
|
|
let l:check_option = !empty(l:check_list)
|
2017-05-12 08:20:16 +00:00
|
|
|
\ ? '-checks=' . ale#Escape(join(l:check_list, ',')) . ' '
|
2017-05-02 21:44:08 +00:00
|
|
|
\ : ''
|
|
|
|
let l:user_options = ale#Var(a:buffer, 'cpp_clangtidy_options')
|
2017-06-24 11:38:16 +00:00
|
|
|
let l:user_build_dir = ale#Var(a:buffer, 'c_build_dir')
|
|
|
|
|
|
|
|
" c_build_dir has the priority if defined
|
|
|
|
if empty(l:user_build_dir)
|
|
|
|
let l:user_build_dir = ale#c#FindCompileCommands(a:buffer)
|
|
|
|
endif
|
|
|
|
|
|
|
|
" We check again if user_builddir stayed empty after the
|
|
|
|
" c_build_dir_names check
|
|
|
|
" If we found the compilation database we override the value of
|
|
|
|
" l:extra_options
|
|
|
|
if empty(l:user_build_dir)
|
|
|
|
let l:extra_options = !empty(l:user_options)
|
|
|
|
\ ? ' -- ' . l:user_options
|
|
|
|
\ : ''
|
|
|
|
else
|
|
|
|
let l:extra_options = ' -p ' . ale#Escape(l:user_build_dir)
|
|
|
|
endif
|
2017-05-02 21:44:08 +00:00
|
|
|
|
|
|
|
return 'clang-tidy ' . l:check_option . '%s' . l:extra_options
|
2017-02-11 23:45:06 +00:00
|
|
|
endfunction
|
2017-02-11 23:32:56 +00:00
|
|
|
|
|
|
|
call ale#linter#Define('cpp', {
|
|
|
|
\ 'name': 'clangtidy',
|
|
|
|
\ 'output_stream': 'stdout',
|
|
|
|
\ 'executable': 'clang-tidy',
|
2017-02-11 23:45:06 +00:00
|
|
|
\ 'command_callback': 'ale_linters#cpp#clangtidy#GetCommand',
|
2017-04-11 19:32:57 +00:00
|
|
|
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
2017-05-02 21:44:08 +00:00
|
|
|
\ 'lint_file': 1,
|
2017-02-11 23:32:56 +00:00
|
|
|
\})
|