2017-06-24 07:38:16 -04:00
|
|
|
" Author: vdeurzen <tim@kompiler.org>, w0rp <devw0rp@gmail.com>,
|
|
|
|
" gagbo <gagbobada@gmail.com>
|
2017-02-11 18:32:56 -05:00
|
|
|
" Description: clang-tidy linter for cpp files
|
|
|
|
|
2017-07-16 19:07:18 -04:00
|
|
|
call ale#Set('cpp_clangtidy_executable', 'clang-tidy')
|
2017-05-02 17:44:08 -04:00
|
|
|
" Set this option to check the checks clang-tidy will apply.
|
2017-07-16 19:07:18 -04:00
|
|
|
call ale#Set('cpp_clangtidy_checks', ['*'])
|
2017-05-02 17:44:08 -04:00
|
|
|
" Set this option to manually set some options for clang-tidy.
|
|
|
|
" This will disable compile_commands.json detection.
|
2017-07-16 19:07:18 -04:00
|
|
|
call ale#Set('cpp_clangtidy_options', '')
|
|
|
|
call ale#Set('c_build_dir', '')
|
2017-06-24 07:38:16 -04:00
|
|
|
|
2017-07-16 19:07:18 -04:00
|
|
|
function! ale_linters#cpp#clangtidy#GetExecutable(buffer) abort
|
|
|
|
return ale#Var(a:buffer, 'cpp_clangtidy_executable')
|
|
|
|
endfunction
|
2017-06-24 07:38:16 -04:00
|
|
|
|
2017-07-20 09:52:24 -04:00
|
|
|
function! s:GetBuildDirectory(buffer) abort
|
|
|
|
" Don't include build directory for header files, as compile_commands.json
|
|
|
|
" files don't consider headers to be translation units, and provide no
|
|
|
|
" commands for compiling header files.
|
|
|
|
if expand('#' . a:buffer) =~# '\v\.(h|hpp)$'
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
2017-07-16 19:07:18 -04:00
|
|
|
let l:build_dir = ale#Var(a:buffer, 'c_build_dir')
|
2017-06-24 07:38:16 -04:00
|
|
|
|
|
|
|
" c_build_dir has the priority if defined
|
2017-07-20 09:52:24 -04:00
|
|
|
if !empty(l:build_dir)
|
|
|
|
return l:build_dir
|
2017-06-24 07:38:16 -04:00
|
|
|
endif
|
|
|
|
|
2017-07-20 09:52:24 -04:00
|
|
|
return ale#c#FindCompileCommands(a:buffer)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
|
|
|
|
let l:checks = join(ale#Var(a:buffer, 'cpp_clangtidy_checks'), ',')
|
|
|
|
let l:build_dir = s:GetBuildDirectory(a:buffer)
|
|
|
|
|
2017-07-16 19:07:18 -04:00
|
|
|
" Get the extra options if we couldn't find a build directory.
|
|
|
|
let l:options = empty(l:build_dir)
|
|
|
|
\ ? ale#Var(a:buffer, 'cpp_clangtidy_options')
|
|
|
|
\ : ''
|
2017-05-02 17:44:08 -04:00
|
|
|
|
2017-07-16 19:07:18 -04:00
|
|
|
return ale#Escape(ale_linters#cpp#clangtidy#GetExecutable(a:buffer))
|
|
|
|
\ . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '')
|
|
|
|
\ . ' %s'
|
|
|
|
\ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
|
|
|
|
\ . (!empty(l:options) ? ' -- ' . l:options : '')
|
2017-02-11 18:45:06 -05:00
|
|
|
endfunction
|
2017-02-11 18:32:56 -05:00
|
|
|
|
|
|
|
call ale#linter#Define('cpp', {
|
|
|
|
\ 'name': 'clangtidy',
|
|
|
|
\ 'output_stream': 'stdout',
|
2017-07-16 19:07:18 -04:00
|
|
|
\ 'executable_callback': 'ale_linters#cpp#clangtidy#GetExecutable',
|
2017-02-11 18:45:06 -05:00
|
|
|
\ 'command_callback': 'ale_linters#cpp#clangtidy#GetCommand',
|
2017-04-11 15:32:57 -04:00
|
|
|
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
2017-05-02 17:44:08 -04:00
|
|
|
\ 'lint_file': 1,
|
2017-02-11 18:32:56 -05:00
|
|
|
\})
|