summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-07-20 14:52:24 +0100
committerw0rp <devw0rp@gmail.com>2017-07-20 14:52:24 +0100
commit87616c5e91746181182a1f7eb0c09487d6ade3e7 (patch)
tree2846d6830c30b17eb67798cf26117394f36f5b7e /ale_linters
parent7d1fde292d1735c119791c96094d8b9ed374b3fc (diff)
downloadale-87616c5e91746181182a1f7eb0c09487d6ade3e7.zip
#782 - Do not set the build directory for clang-tidy for header files, which does not work
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/cpp/clangtidy.vim21
1 files changed, 17 insertions, 4 deletions
diff --git a/ale_linters/cpp/clangtidy.vim b/ale_linters/cpp/clangtidy.vim
index 5ff345fd..1d5fb77a 100644
--- a/ale_linters/cpp/clangtidy.vim
+++ b/ale_linters/cpp/clangtidy.vim
@@ -14,15 +14,28 @@ function! ale_linters#cpp#clangtidy#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'cpp_clangtidy_executable')
endfunction
-function! ale_linters#cpp#clangtidy#GetCommand(buffer) abort
- let l:checks = join(ale#Var(a:buffer, 'cpp_clangtidy_checks'), ',')
+function! s:GetBuildDirectory(buffer) abort
+ " 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')
" c_build_dir has the priority if defined
- if empty(l:build_dir)
- let l:build_dir = ale#c#FindCompileCommands(a:buffer)
+ if !empty(l:build_dir)
+ return l:build_dir
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.
let l:options = empty(l:build_dir)
\ ? ale#Var(a:buffer, 'cpp_clangtidy_options')