2018-03-31 10:55:20 -04:00
|
|
|
" Author: vdeurzen <tim@kompiler.org>, w0rp <devw0rp@gmail.com>,
|
|
|
|
" gagbo <gagbobada@gmail.com>
|
|
|
|
" Description: clang-tidy linter for cpp files
|
|
|
|
|
|
|
|
call ale#Set('cpp_clangtidy_executable', 'clang-tidy')
|
|
|
|
" Set this option to check the checks clang-tidy will apply.
|
2018-11-01 06:03:42 -04:00
|
|
|
call ale#Set('cpp_clangtidy_checks', [])
|
2019-07-08 12:44:45 -04:00
|
|
|
" Set this option to manually set some options for clang-tidy to use as compile
|
|
|
|
" flags.
|
2018-03-31 10:55:20 -04:00
|
|
|
" This will disable compile_commands.json detection.
|
|
|
|
call ale#Set('cpp_clangtidy_options', '')
|
2019-07-08 12:44:45 -04:00
|
|
|
" Set this option to manually set options for clang-tidy directly.
|
|
|
|
call ale#Set('cpp_clangtidy_extra_options', '')
|
2018-03-31 10:55:20 -04:00
|
|
|
call ale#Set('c_build_dir', '')
|
|
|
|
|
2019-11-16 10:28:42 -05:00
|
|
|
function! ale_linters#cpp#clangtidy#GetCommand(buffer, output) abort
|
2018-03-31 10:55:20 -04:00
|
|
|
let l:checks = join(ale#Var(a:buffer, 'cpp_clangtidy_checks'), ',')
|
2018-08-25 12:13:42 -04:00
|
|
|
let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
|
2019-11-16 10:28:42 -05:00
|
|
|
let l:options = ''
|
2018-03-31 10:55:20 -04:00
|
|
|
|
|
|
|
" Get the extra options if we couldn't find a build directory.
|
2019-11-16 10:28:42 -05:00
|
|
|
if empty(l:build_dir)
|
|
|
|
let l:options = ale#Var(a:buffer, 'cpp_clangtidy_options')
|
|
|
|
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
|
|
|
|
let l:options .= !empty(l:options) ? ale#Pad(l:cflags) : l:cflags
|
2018-03-31 10:55:20 -04:00
|
|
|
|
2021-06-30 13:00:07 -04:00
|
|
|
" Tell clang-tidy a .h header with a C++ filetype in Vim is a C++ file
|
|
|
|
" only when compile-commands.json file is not there. Adding these
|
|
|
|
" flags makes clang-tidy completely ignore compile commmands.
|
|
|
|
if expand('#' . a:buffer) =~# '\.h$'
|
|
|
|
let l:options .= !empty(l:options) ? ' -x c++' : '-x c++'
|
|
|
|
endif
|
2020-12-04 16:15:32 -05:00
|
|
|
endif
|
|
|
|
|
2019-08-22 11:36:17 -04:00
|
|
|
" Get the options to pass directly to clang-tidy
|
|
|
|
let l:extra_options = ale#Var(a:buffer, 'cpp_clangtidy_extra_options')
|
2018-03-31 10:55:20 -04:00
|
|
|
|
2018-08-25 12:13:42 -04:00
|
|
|
return '%e'
|
2018-03-31 10:55:20 -04:00
|
|
|
\ . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '')
|
2019-07-08 12:44:45 -04:00
|
|
|
\ . (!empty(l:extra_options) ? ' ' . ale#Escape(l:extra_options) : '')
|
2018-03-31 10:55:20 -04:00
|
|
|
\ . ' %s'
|
|
|
|
\ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
|
|
|
|
\ . (!empty(l:options) ? ' -- ' . l:options : '')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('cpp', {
|
|
|
|
\ 'name': 'clangtidy',
|
|
|
|
\ 'output_stream': 'stdout',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'cpp_clangtidy_executable')},
|
2019-11-16 10:28:42 -05:00
|
|
|
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#clangtidy#GetCommand'))},
|
2018-03-31 10:55:20 -04:00
|
|
|
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
|
|
|
\ 'lint_file': 1,
|
|
|
|
\})
|