当前位置: 动力学知识库 > 问答 > 编程问答 >

how to add rule for cppcheck in VIM

问题描述:

I have one issue with cppcheck during enable it in VIM, for normal code it works fine but normally I have typedef and some functions which may not known by cppcheck. For individual check, I have no problem because I can write library and rules for cppcheck, for example mycppcheck.cfg file:

<?xml version="1.0"?>

<def>

<!-- 2015-Oct-23 requested by Chen How -->

<function name="Printf"><noreturn>false</noreturn></function>

</def>

<def>

<podtype name="Int8" sign="s" size="1"/>

<podtype name="UInt8" sign="u" size="1"/>

<podtype name="Int16" sign="s" size="2"/>

<podtype name="UInt16" sign="u" size="2"/>

<podtype name="Int32" sign="s" size="4"/>

<podtype name="UInt32" sign="u" size="4"/>

</def>

<def>

<memory>

<alloc>my_malloc</alloc>

<dealloc>my_free</dealloc>

</memory>

</def>

When I use cppcheck, I do following command:

$ cppcheck --library=mycppcheck.cfg

My question is: when I use cppcheck in VIM, how can I tell cppcheck, for current file, which library it should use? without library, cppcheck can't identify correct risk.

I use syntastic as the plug-in for VIM, or any other way to enbale cppcheck facility without this plug-in?

I also checked the topic Vim & CppCheck, which errorformat to use:, I think it can work for me but I did not find the library define in this. Regarding above topic, my first guess is changing:

set makeprg=cppcheck\ --enable=all\ %

to

set makeprg=cppcheck\ --library=mycppcheck.cfg --enable=all\ %

More findings @ syntastic

4.8. Q. How can I pass additional arguments to a checker?

A. Almost all syntax checkers use the makeprgBuild() function. Those checkers that do can be configured using global variables. The general form of the global args variables is syntastic___args.

So, If you wanted to pass --my --args --here to the ruby mri checker you would add this line to your vimrc:

let g:syntastic_ruby_mri_args = "--my --args --here"

See :help syntastic-checker-options for more information.

分享给朋友:
您可能感兴趣的文章:
随机阅读: