]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/cpp/clangtidy.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '56df844d3c39ec494dacc69eae34272b27db185a' as '.vim/bundle/asyncomplete'
[etc/vim.git] / .vim / bundle / ale / ale_linters / cpp / clangtidy.vim
1 " Author: vdeurzen <tim@kompiler.org>, w0rp <devw0rp@gmail.com>,
2 " gagbo <gagbobada@gmail.com>
3 " Description: clang-tidy linter for cpp files
4
5 call ale#Set('cpp_clangtidy_executable', 'clang-tidy')
6 " Set this option to check the checks clang-tidy will apply.
7 call ale#Set('cpp_clangtidy_checks', [])
8 " Set this option to manually set some options for clang-tidy to use as compile
9 " flags.
10 " This will disable compile_commands.json detection.
11 call ale#Set('cpp_clangtidy_options', '')
12 " Set this option to manually set options for clang-tidy directly.
13 call ale#Set('cpp_clangtidy_extra_options', '')
14 call ale#Set('c_build_dir', '')
15
16 function! ale_linters#cpp#clangtidy#GetCommand(buffer, output) abort
17     let l:checks = join(ale#Var(a:buffer, 'cpp_clangtidy_checks'), ',')
18     let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
19     let l:options = ''
20
21     " Get the extra options if we couldn't find a build directory.
22     if empty(l:build_dir)
23         let l:options = ale#Var(a:buffer, 'cpp_clangtidy_options')
24         let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
25         let l:options .= !empty(l:options) ? ale#Pad(l:cflags) : l:cflags
26
27         " Tell clang-tidy a .h header with a C++ filetype in Vim is a C++ file
28         " only when compile-commands.json file is not there. Adding these
29         " flags makes clang-tidy completely ignore compile commands.
30         if expand('#' . a:buffer) =~# '\.h$'
31             let l:options .= !empty(l:options) ? ' -x c++' : '-x c++'
32         endif
33     endif
34
35     " Get the options to pass directly to clang-tidy
36     let l:extra_options = ale#Var(a:buffer, 'cpp_clangtidy_extra_options')
37
38     return '%e'
39     \   . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '')
40     \   . (!empty(l:extra_options) ? ' ' . ale#Escape(l:extra_options) : '')
41     \   . ' %s'
42     \   . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
43     \   . (!empty(l:options) ? ' -- ' . l:options : '')
44 endfunction
45
46 call ale#linter#Define('cpp', {
47 \   'name': 'clangtidy',
48 \   'output_stream': 'stdout',
49 \   'executable': {b -> ale#Var(b, 'cpp_clangtidy_executable')},
50 \   'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#clangtidy#GetCommand'))},
51 \   'callback': 'ale#handlers#gcc#HandleGCCFormat',
52 \   'lint_file': 1,
53 \})