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-07-16 23:07:18 +00:00
|
|
|
call ale#Set('cpp_clangtidy_executable', 'clang-tidy')
|
2017-05-02 21:44:08 +00:00
|
|
|
" Set this option to check the checks clang-tidy will apply.
|
2018-10-29 22:48:05 +00:00
|
|
|
call ale#Set('cpp_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-05-02 21:44:08 +00:00
|
|
|
" This will disable compile_commands.json detection.
|
2017-07-16 23:07:18 +00:00
|
|
|
call ale#Set('cpp_clangtidy_options', '')
|
2019-06-08 19:12:43 +00:00
|
|
|
" Set this option to manually set options for clang-tidy directly.
|
|
|
|
call ale#Set('cpp_clangtidy_extra_options', '')
|
2017-07-16 23:07:18 +00:00
|
|
|
call ale#Set('c_build_dir', '')
|
2017-06-24 11:38:16 +00:00
|
|
|
|
2017-07-20 13:52:24 +00:00
|
|
|
function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
|
|
|
|
let l:checks = join(ale#Var(a:buffer, 'cpp_clangtidy_checks'), ',')
|
2018-08-24 09:52:33 +00:00
|
|
|
let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
|
2017-07-20 13:52:24 +00:00
|
|
|
|
2017-07-16 23:07:18 +00: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 21:44:08 +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, 'cpp_clangtidy_extra_options')
|
|
|
|
|
2018-08-02 22:44:12 +00:00
|
|
|
return '%e'
|
2017-07-16 23:07:18 +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-07-16 23:07:18 +00:00
|
|
|
\ . ' %s'
|
|
|
|
\ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
|
|
|
|
\ . (!empty(l:options) ? ' -- ' . l: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',
|
2019-02-22 18:05:04 +00:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'cpp_clangtidy_executable')},
|
|
|
|
\ 'command': function('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
|
|
|
\})
|