2017-08-05 13:21:02 +00:00
|
|
|
" Author: vdeurzen <tim@kompiler.org>, w0rp <devw0rp@gmail.com>,
|
|
|
|
" gagbo <gagbobada@gmail.com>, Andrej Radovic <r.andrej@gmail.com>
|
|
|
|
" Description: clang-tidy linter for c files
|
|
|
|
|
|
|
|
call ale#Set('c_clangtidy_executable', 'clang-tidy')
|
|
|
|
" Set this option to check the checks clang-tidy will apply.
|
|
|
|
" The number of checks that can be applied to C files is limited in contrast to
|
|
|
|
" C++
|
|
|
|
"
|
2017-08-06 11:14:09 +00:00
|
|
|
" Consult the check list in clang-tidy's documentation:
|
|
|
|
" http://clang.llvm.org/extra/clang-tidy/checks/list.html
|
2017-08-05 13:21:02 +00:00
|
|
|
|
2018-10-29 22:48:05 +00:00
|
|
|
call ale#Set('c_clangtidy_checks', [])
|
2019-06-08 19:12:43 +00:00
|
|
|
" Set this option to manually set some options for clang-tidy to use as compile
|
|
|
|
" flags.
|
2017-08-05 13:21:02 +00:00
|
|
|
" This will disable compile_commands.json detection.
|
|
|
|
call ale#Set('c_clangtidy_options', '')
|
2019-06-08 19:12:43 +00:00
|
|
|
" Set this option to manually set options for clang-tidy directly.
|
|
|
|
call ale#Set('c_clangtidy_extra_options', '')
|
2017-08-05 13:21:02 +00:00
|
|
|
call ale#Set('c_build_dir', '')
|
|
|
|
|
2019-10-06 16:29:17 +00:00
|
|
|
function! ale_linters#c#clangtidy#GetCommand(buffer, output) abort
|
2017-08-05 13:21:02 +00:00
|
|
|
let l:checks = join(ale#Var(a:buffer, 'c_clangtidy_checks'), ',')
|
2018-08-24 09:52:33 +00:00
|
|
|
let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
|
2019-10-06 16:29:17 +00:00
|
|
|
let l:options = ''
|
|
|
|
|
2019-10-06 16:29:23 +00:00
|
|
|
" Get the extra options if we couldn't find a build directory.
|
2019-10-06 16:29:17 +00:00
|
|
|
if empty(l:build_dir)
|
|
|
|
let l:options = ale#Var(a:buffer, 'c_clangtidy_options')
|
|
|
|
let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
|
|
|
|
let l:options .= !empty(l:options) ? ale#Pad(l:cflags) : l:cflags
|
|
|
|
endif
|
2017-08-05 13:21:02 +00:00
|
|
|
|
2019-06-08 19:12:43 +00:00
|
|
|
" Get the options to pass directly to clang-tidy
|
|
|
|
let l:extra_options = ale#Var(a:buffer, 'c_clangtidy_extra_options')
|
|
|
|
|
2018-08-02 22:44:12 +00:00
|
|
|
return '%e'
|
2017-08-05 13:21:02 +00:00
|
|
|
\ . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '')
|
2019-06-08 19:12:43 +00:00
|
|
|
\ . (!empty(l:extra_options) ? ' ' . ale#Escape(l:extra_options) : '')
|
2017-08-05 13:21:02 +00:00
|
|
|
\ . ' %s'
|
|
|
|
\ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
|
|
|
|
\ . (!empty(l:options) ? ' -- ' . l:options : '')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('c', {
|
|
|
|
\ 'name': 'clangtidy',
|
|
|
|
\ 'output_stream': 'stdout',
|
2019-02-22 18:05:04 +00:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'c_clangtidy_executable')},
|
2019-10-06 16:29:17 +00:00
|
|
|
\ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#clangtidy#GetCommand'))},
|
2017-08-05 13:21:02 +00:00
|
|
|
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
|
|
|
\ 'lint_file': 1,
|
|
|
|
\})
|