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.
2 " Author: ObserverOfTime <chronobserver@disroot.org>
3 " Description: Fixing C/C++ files with clang-tidy.
5 function! s:set_variables() abort
6 let l:use_global = get(g:, 'ale_use_global_executables', 0)
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)
17 call ale#Set('c_build_dir', '')
20 call s:set_variables()
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'
26 return ale#Var(a:buffer, l:ft . '_clangtidy_' . a:name)
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')
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)
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)
49 \ 'command': ale#Escape(l:executable) . l:command,
50 \ 'read_temporary_file': 1,