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 " Description: Handle errors for cppcheck.
3 function! ale#handlers#cppcheck#GetCwd(buffer) abort
4 let [l:dir, l:json_path] = ale#c#FindCompileCommands(a:buffer)
6 return !empty(l:dir) ? l:dir : ''
9 function! ale#handlers#cppcheck#GetBufferPathIncludeOptions(buffer) abort
10 let l:buffer_path_include = ''
12 " Get path to this buffer so we can include it into cppcheck with -I
13 " This could be expanded to get more -I directives from the compile
14 " command in compile_commands.json, if it's found.
15 let l:buffer_path = fnamemodify(bufname(a:buffer), ':p:h')
16 let l:buffer_path_include = ' -I' . ale#Escape(l:buffer_path)
18 return l:buffer_path_include
21 function! ale#handlers#cppcheck#GetCompileCommandsOptions(buffer) abort
22 " The compile_commands.json doesn't apply to headers and cppheck will
23 " bail out if it cannot find a file matching the filter, below. Skip out
24 " now, for headers. Also, suppress FPs; cppcheck is not meant to
25 " process lone header files.
26 let b:buffer_name = bufname(a:buffer)
27 let b:file_extension = fnamemodify(b:buffer_name, ':e')
29 if b:file_extension is# 'h' || b:file_extension is# 'hpp'
30 return ale#handlers#cppcheck#GetBufferPathIncludeOptions(a:buffer)
31 \ . ' --suppress=unusedStructMember'
34 " If the current buffer is modified, using compile_commands.json does no
35 " good, so include the file's directory instead. It's not quite as good as
36 " using --project, but is at least equivalent to running cppcheck on this
37 " file manually from the file's directory.
38 let l:modified = getbufvar(a:buffer, '&modified')
44 " Search upwards from the file for compile_commands.json.
46 " If we find it, we'll `cd` to where the compile_commands.json file is,
47 " then use the file to set up import paths, etc.
48 let [l:dir, l:json_path] = ale#c#FindCompileCommands(a:buffer)
50 " By default, cppcheck processes every config in compile_commands.json.
51 " Use --file-filter to limit to just the buffer file.
52 return !empty(l:json_path)
53 \ ? '--project=' . ale#Escape(l:json_path[len(l:dir) + 1: ]) . ' --file-filter=' . ale#Escape(bufname(a:buffer))
57 function! ale#handlers#cppcheck#HandleCppCheckFormat(buffer, lines) abort
58 " Look for lines like the following.
60 "test.cpp:974:6: error:inconclusive Array 'n[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\
63 "" OR if cppcheck doesn't support {column} or {inconclusive:text}:
64 "test.cpp:974:{column}: error:{inconclusive:inconclusive} Array 'n[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\
68 "" OR if using the misra addon:
69 "test.c:1:16: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.7]\'
70 "void test( int parm ) {}
72 let l:pattern = '\v(\f+):(\d+):(\d+|\{column\}): (\w+):(\{inconclusive:inconclusive\})? ?(.*) \[(%(\w[-.]?)+)\]\'
75 for l:match in ale#util#GetMatches(a:lines, l:pattern)
76 if ale#path#IsBufferPath(a:buffer, l:match[1])
78 \ 'lnum': str2nr(l:match[2]),
79 \ 'col': match(l:match[3],'{column}') >= 0 ? 1 : str2nr(l:match[3]),
80 \ 'type': l:match[4] is# 'error' ? 'E' : 'W',
81 \ 'sub_type': l:match[4] is# 'style' ? 'style' : '',