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.
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: A C++ compiler linter for C++ files with gcc/clang, etc.
4 call ale#Set('cpp_cc_executable', '<auto>')
5 call ale#Set('cpp_cc_options', '-std=c++14 -Wall')
6 call ale#Set('cpp_cc_use_header_lang_flag', -1)
7 call ale#Set('cpp_cc_header_exts', ['h', 'hpp'])
9 function! ale_linters#cpp#cc#GetExecutable(buffer) abort
10 let l:executable = ale#Var(a:buffer, 'cpp_cc_executable')
12 " Default to either clang++ or gcc.
13 if l:executable is# '<auto>'
14 if ale#engine#IsExecutable(a:buffer, 'clang++')
15 let l:executable = 'clang++'
17 let l:executable = 'gcc'
24 function! ale_linters#cpp#cc#GetCommand(buffer, output) abort
25 let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
26 let l:ale_flags = ale#Var(a:buffer, 'cpp_cc_options')
28 if l:cflags =~# '-std='
29 let l:ale_flags = substitute(
31 \ '-std=\(c\|gnu\)++[0-9]\{2\}',
36 " Select the correct language flag depending on the executable, options
38 let l:executable = ale_linters#cpp#cc#GetExecutable(a:buffer)
39 let l:use_header_lang_flag = ale#Var(a:buffer, 'cpp_cc_use_header_lang_flag')
40 let l:header_exts = ale#Var(a:buffer, 'cpp_cc_header_exts')
41 let l:lang_flag = ale#c#GetLanguageFlag(
44 \ l:use_header_lang_flag,
48 " -iquote with the directory the file is in makes #include work for
49 " headers in the same directory.
51 " `-o /dev/null` or `-o null` is needed to catch all errors,
52 " -fsyntax-only doesn't catch everything.
53 return '%e -S -x ' . l:lang_flag
54 \ . ' -o ' . g:ale#util#nul_file
57 \ . ale#Pad(l:ale_flags) . ' -'
60 call ale#linter#Define('cpp', {
62 \ 'aliases': ['gcc', 'clang', 'g++', 'clang++'],
63 \ 'output_stream': 'stderr',
64 \ 'executable': function('ale_linters#cpp#cc#GetExecutable'),
65 \ 'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#cpp#cc#GetCommand'))},
66 \ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',