]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/fixers/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] / autoload / ale / fixers / clangtidy.vim
1 scriptencoding utf-8
2 " Author: ObserverOfTime <chronobserver@disroot.org>
3 " Description: Fixing C/C++ files with clang-tidy.
4
5 function! s:set_variables() abort
6     let l:use_global = get(g:, 'ale_use_global_executables', 0)
7
8     for l:ft in ['c', 'cpp']
9         call ale#Set(l:ft . '_clangtidy_executable', 'clang-tidy')
10         call ale#Set(l:ft . '_clangtidy_use_global', l:use_global)
11         call ale#Set(l:ft . '_clangtidy_checks', [])
12         call ale#Set(l:ft . '_clangtidy_options', '')
13         call ale#Set(l:ft . '_clangtidy_extra_options', '')
14         call ale#Set(l:ft . '_clangtidy_fix_errors', 1)
15     endfor
16
17     call ale#Set('c_build_dir', '')
18 endfunction
19
20 call s:set_variables()
21
22 function! ale#fixers#clangtidy#Var(buffer, name) abort
23     let l:ft = getbufvar(str2nr(a:buffer), '&filetype')
24     let l:ft = l:ft =~# 'cpp' ? 'cpp' : 'c'
25
26     return ale#Var(a:buffer, l:ft . '_clangtidy_' . a:name)
27 endfunction
28
29 function! ale#fixers#clangtidy#GetCommand(buffer) abort
30     let l:checks = join(ale#fixers#clangtidy#Var(a:buffer, 'checks'), ',')
31     let l:extra_options = ale#fixers#clangtidy#Var(a:buffer, 'extra_options')
32     let l:build_dir = ale#c#GetBuildDirectory(a:buffer)
33     let l:options = empty(l:build_dir)
34     \   ? ale#fixers#clangtidy#Var(a:buffer, 'options') : ''
35     let l:fix_errors = ale#fixers#clangtidy#Var(a:buffer, 'fix_errors')
36
37     return ' -fix' . (l:fix_errors ? ' -fix-errors' : '')
38     \   . (empty(l:checks) ? '' : ' -checks=' . ale#Escape(l:checks))
39     \   . (empty(l:extra_options) ? '' : ' ' . l:extra_options)
40     \   . (empty(l:build_dir) ? '' : ' -p ' . ale#Escape(l:build_dir))
41     \   . ' %t' . (empty(l:options) ? '' : ' -- ' . l:options)
42 endfunction
43
44 function! ale#fixers#clangtidy#Fix(buffer) abort
45     let l:executable = ale#fixers#clangtidy#Var(a:buffer, 'executable')
46     let l:command = ale#fixers#clangtidy#GetCommand(a:buffer)
47
48     return {
49     \   'command': ale#Escape(l:executable) . l:command,
50     \   'read_temporary_file': 1,
51     \}
52 endfunction