]> git.madduck.net Git - etc/vim.git/blob - ale_linters/c/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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / c / clangtidy.vim
1 " Author: vdeurzen <tim@kompiler.org>, w0rp <devw0rp@gmail.com>,
2 " gagbo <gagbobada@gmail.com>, Andrej Radovic <r.andrej@gmail.com>
3 " Description: clang-tidy linter for c files
4
5 call ale#Set('c_clangtidy_executable', 'clang-tidy')
6 " Set this option to check the checks clang-tidy will apply.
7 " The number of checks that can be applied to C files is limited in contrast to
8 " C++
9 "
10 " Consult the check list in clang-tidy's documentation:
11 " http://clang.llvm.org/extra/clang-tidy/checks/list.html
12
13 call ale#Set('c_clangtidy_checks', [])
14 " Set this option to manually set some options for clang-tidy to use as compile
15 " flags.
16 " This will disable compile_commands.json detection.
17 call ale#Set('c_clangtidy_options', '')
18 " Set this option to manually set options for clang-tidy directly.
19 call ale#Set('c_clangtidy_extra_options', '')
20 call ale#Set('c_build_dir', '')
21
22 function! ale_linters#c#clangtidy#GetCommand(buffer, output) abort
23     let l:checks = join(ale#Var(a:buffer, 'c_clangtidy_checks'), ',')
24     let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
25     let l:options = ''
26
27     " Get the extra options if we couldn't find a build directory.
28     if empty(l:build_dir)
29         let l:options = ale#Var(a:buffer, 'c_clangtidy_options')
30         let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
31         let l:options .= !empty(l:options) ? ale#Pad(l:cflags) : l:cflags
32     endif
33
34     " Get the options to pass directly to clang-tidy
35     let l:extra_options = ale#Var(a:buffer, 'c_clangtidy_extra_options')
36
37     return '%e'
38     \   . (!empty(l:checks) ? ' -checks=' . ale#Escape(l:checks) : '')
39     \   . (!empty(l:extra_options) ? ' ' . ale#Escape(l:extra_options) : '')
40     \   . ' %s'
41     \   . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '')
42     \   . (!empty(l:options) ? ' -- ' . l:options : '')
43 endfunction
44
45 call ale#linter#Define('c', {
46 \   'name': 'clangtidy',
47 \   'output_stream': 'stdout',
48 \   'executable': {b -> ale#Var(b, 'c_clangtidy_executable')},
49 \   'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#clangtidy#GetCommand'))},
50 \   'callback': 'ale#handlers#gcc#HandleGCCFormat',
51 \   'lint_file': 1,
52 \})