Fix #410 - Use compile_commands.json files for clang-tidy, and check files on disk instead
This commit is contained in:
parent
eb8bd26776
commit
3573975934
@ -1,12 +1,24 @@
|
||||
" Author: vdeurzen <tim@kompiler.org>, w0rp <devw0rp@gmail.com>
|
||||
" Description: clang-tidy linter for cpp files
|
||||
|
||||
" Set this option to change the clang-tidy options for warnings for C.
|
||||
let g:ale_cpp_clangtidy_options =
|
||||
\ get(g:, 'ale_cpp_clangtidy_options', '-std=c++14 -Wall')
|
||||
" 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', '')
|
||||
|
||||
function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
|
||||
return 'clang-tidy %t -- ' . ale#Var(a:buffer, 'cpp_clangtidy_options')
|
||||
let l:check_list = ale#Var(a:buffer, 'cpp_clangtidy_checks')
|
||||
let l:check_option = !empty(l:check_list)
|
||||
\ ? '-checks=' . shellescape(join(l:check_list, ',')) . ' '
|
||||
\ : ''
|
||||
let l:user_options = ale#Var(a:buffer, 'cpp_clangtidy_options')
|
||||
let l:extra_options = !empty(l:user_options)
|
||||
\ ? ' -- ' . l:user_options
|
||||
\ : ''
|
||||
|
||||
return 'clang-tidy ' . l:check_option . '%s' . l:extra_options
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('cpp', {
|
||||
@ -15,4 +27,5 @@ call ale#linter#Define('cpp', {
|
||||
\ 'executable': 'clang-tidy',
|
||||
\ 'command_callback': 'ale_linters#cpp#clangtidy#GetCommand',
|
||||
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat',
|
||||
\ 'lint_file': 1,
|
||||
\})
|
||||
|
@ -16,12 +16,35 @@ g:ale_cpp_clang_options *g:ale_cpp_clang_options*
|
||||
-------------------------------------------------------------------------------
|
||||
clangtidy *ale-cpp-clangtidy*
|
||||
|
||||
`clang-tidy` will be run only when files are saved to disk, so that
|
||||
`compile_commands.json` files can be used. It is recommended to use this
|
||||
linter in combination with `compile_commands.json` files.
|
||||
|
||||
|
||||
g:ale_cpp_clangtidy_checks *g:ale_cpp_clangtidy_checks*
|
||||
*b:ale_cpp_clangtidy_checks*
|
||||
Type: |List|
|
||||
Default: `['*']`
|
||||
|
||||
The checks to enable for clang-tidy with the `-checks` argument.
|
||||
|
||||
All options will be joined with commas, and escaped appropriately for
|
||||
the shell. The `-checks` flag can be removed entirely by setting this
|
||||
option to an empty List.
|
||||
|
||||
|
||||
g:ale_cpp_clangtidy_options *g:ale_cpp_clangtidy_options*
|
||||
*b:ale_cpp_clangtidy_options*
|
||||
Type: |String|
|
||||
Default: `'-std=c++14 -Wall'`
|
||||
Default: `''`
|
||||
|
||||
This variable can be changed to modify flags given to clangtidy.
|
||||
This variable can be changed to modify flags given to clang-tidy.
|
||||
|
||||
Setting this variable to a non-empty string will cause the `--` argument
|
||||
to be passed to `clang-tidy`, which will mean that detection of
|
||||
`compile_commands.json` files for compile command databases will be
|
||||
disabled. Only set this option if you want to control compiler flags
|
||||
entirely manually.
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
31
test/command_callback/test_clang_tidy_command_callback.vader
Normal file
31
test/command_callback/test_clang_tidy_command_callback.vader
Normal file
@ -0,0 +1,31 @@
|
||||
Before:
|
||||
Save g:ale_cpp_clangtidy_checks
|
||||
Save g:ale_cpp_clangtidy_options
|
||||
runtime ale_linters/cpp/clangtidy.vim
|
||||
|
||||
After:
|
||||
Restore
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The clangtidy command default should be correct):
|
||||
AssertEqual
|
||||
\ 'clang-tidy -checks=''*'' %s',
|
||||
\ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
|
||||
|
||||
Execute(You should be able to remove the -checks option for clang-tidy):
|
||||
let g:ale_cpp_clangtidy_checks = []
|
||||
AssertEqual
|
||||
\ 'clang-tidy %s',
|
||||
\ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
|
||||
|
||||
Execute(You should be able to set other checks for clang-tidy):
|
||||
let g:ale_cpp_clangtidy_checks = ['-*', 'clang-analyzer-*']
|
||||
AssertEqual
|
||||
\ 'clang-tidy -checks=''-*,clang-analyzer-*'' %s',
|
||||
\ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
|
||||
|
||||
Execute(You should be able to manually set compiler flags for clang-tidy):
|
||||
let g:ale_cpp_clangtidy_options = '-Wall'
|
||||
AssertEqual
|
||||
\ 'clang-tidy -checks=''*'' %s -- -Wall',
|
||||
\ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
|
Loading…
Reference in New Issue
Block a user