#782 - Do not set the build directory for clang-tidy for header files, which does not work
This commit is contained in:
parent
7d1fde292d
commit
87616c5e91
@ -14,15 +14,28 @@ function! ale_linters#cpp#clangtidy#GetExecutable(buffer) abort
|
|||||||
return ale#Var(a:buffer, 'cpp_clangtidy_executable')
|
return ale#Var(a:buffer, 'cpp_clangtidy_executable')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
|
function! s:GetBuildDirectory(buffer) abort
|
||||||
let l:checks = join(ale#Var(a:buffer, 'cpp_clangtidy_checks'), ',')
|
" 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
|
||||||
|
|
||||||
let l:build_dir = ale#Var(a:buffer, 'c_build_dir')
|
let l:build_dir = ale#Var(a:buffer, 'c_build_dir')
|
||||||
|
|
||||||
" c_build_dir has the priority if defined
|
" c_build_dir has the priority if defined
|
||||||
if empty(l:build_dir)
|
if !empty(l:build_dir)
|
||||||
let l:build_dir = ale#c#FindCompileCommands(a:buffer)
|
return l:build_dir
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
" Get the extra options if we couldn't find a build directory.
|
" Get the extra options if we couldn't find a build directory.
|
||||||
let l:options = empty(l:build_dir)
|
let l:options = empty(l:build_dir)
|
||||||
\ ? ale#Var(a:buffer, 'cpp_clangtidy_options')
|
\ ? ale#Var(a:buffer, 'cpp_clangtidy_options')
|
||||||
|
@ -12,6 +12,8 @@ Before:
|
|||||||
|
|
||||||
runtime ale_linters/cpp/clangtidy.vim
|
runtime ale_linters/cpp/clangtidy.vim
|
||||||
|
|
||||||
|
call ale#test#SetFilename('test.cpp')
|
||||||
|
|
||||||
After:
|
After:
|
||||||
unlet! b:ale_c_build_dir
|
unlet! b:ale_c_build_dir
|
||||||
unlet! b:ale_cpp_clangtidy_checks
|
unlet! b:ale_cpp_clangtidy_checks
|
||||||
@ -68,6 +70,24 @@ Execute(The build directory setting should override the options):
|
|||||||
\ . ' -checks=''*'' %s -p ' . ale#Escape('/foo/bar'),
|
\ . ' -checks=''*'' %s -p ' . ale#Escape('/foo/bar'),
|
||||||
\ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
|
\ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The build directory should be ignored for header files):
|
||||||
|
call ale#test#SetFilename('test.h')
|
||||||
|
|
||||||
|
let b:ale_c_build_dir = '/foo/bar'
|
||||||
|
let b:ale_cpp_clangtidy_options = '-Wall'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ ale#Escape('clang-tidy')
|
||||||
|
\ . ' -checks=''*'' %s -- -Wall',
|
||||||
|
\ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
|
||||||
|
\
|
||||||
|
call ale#test#SetFilename('test.hpp')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ ale#Escape('clang-tidy')
|
||||||
|
\ . ' -checks=''*'' %s -- -Wall',
|
||||||
|
\ ale_linters#cpp#clangtidy#GetCommand(bufnr(''))
|
||||||
|
|
||||||
Execute(The executable should be configurable):
|
Execute(The executable should be configurable):
|
||||||
let b:ale_cpp_clangtidy_executable = 'foobar'
|
let b:ale_cpp_clangtidy_executable = 'foobar'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user