diff options
author | Dan George <dgeorge83616@yahoo.com> | 2021-11-17 20:27:23 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-18 13:27:23 +0900 |
commit | aee0cc45bea7f190c27f0fc06f98a465ecff56fa (patch) | |
tree | 2d58fed6b5e945611c59385b7309709ae2570e66 /autoload | |
parent | 3ca66e44bdedca31a5f9de2fa304d2cfc8c2aae3 (diff) | |
download | ale-aee0cc45bea7f190c27f0fc06f98a465ecff56fa.zip |
Cppcheck buffered file only (#3983)
* Add cppcheck handler match on misra msg
* Use --file-filter cppcheck option
Cppcheck recently added --file-filter so that cppcheck only checks the
filtered files, even when using --project option, which checks all files
in the project, by default. The --ccpcheck-build-dir option didn't help
enough (at all?).
* Added C test cases
Also fixed and assumed typo: foo.c, instead of foo.cpp
* Replace hard-coded full path filenames
Attempt to fix the windows platform test execution.
* Fix typo - foo.c, instead of foo.cpp
* Reset buffer var between tests
* Handle header files in cppcheck
Cppcheck isn't designed to check header files, stand-alone. Daniel
Marjamäki suggested using --suppress options to avoid FPs.
* Fix Vint complaint in cppcheck handler.
* Fix file path in cppcheck handler
Co-authored-by: Dan George <dgeorge@anduril.com>
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/handlers/cppcheck.vim | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/autoload/ale/handlers/cppcheck.vim b/autoload/ale/handlers/cppcheck.vim index bb8c8602..cf69df26 100644 --- a/autoload/ale/handlers/cppcheck.vim +++ b/autoload/ale/handlers/cppcheck.vim @@ -19,6 +19,18 @@ function! ale#handlers#cppcheck#GetBufferPathIncludeOptions(buffer) abort endfunction function! ale#handlers#cppcheck#GetCompileCommandsOptions(buffer) abort + " The compile_commands.json doesn't apply to headers and cppheck will + " bail out if it cannot find a file matching the filter, below. Skip out + " now, for headers. Also, suppress FPs; cppcheck is not meant to + " process lone header files. + let b:buffer_name = bufname(a:buffer) + let b:file_extension = fnamemodify(b:buffer_name, ':e') + + if b:file_extension is# 'h' || b:file_extension is# 'hpp' + return ale#handlers#cppcheck#GetBufferPathIncludeOptions(a:buffer) + \ . ' --suppress=unusedStructMember' + endif + " If the current buffer is modified, using compile_commands.json does no " good, so include the file's directory instead. It's not quite as good as " using --project, but is at least equivalent to running cppcheck on this @@ -34,9 +46,13 @@ function! ale#handlers#cppcheck#GetCompileCommandsOptions(buffer) abort " If we find it, we'll `cd` to where the compile_commands.json file is, " then use the file to set up import paths, etc. let [l:dir, l:json_path] = ale#c#FindCompileCommands(a:buffer) + let b:root_index = len(l:dir) + 1 + let b:buffer_file= bufname(a:buffer) + " By default, cppcheck processes every config in compile_commands.json. + " Use --file-filter to limit to just the buffer file. return !empty(l:json_path) - \ ? '--project=' . ale#Escape(l:json_path[len(l:dir) + 1: ]) + \ ? '--project=' . ale#Escape(l:json_path[b:root_index: ]) . ' --file-filter=' . ale#Escape(b:buffer_file[b:root_index:]) \ : '' endfunction |