开发者

Looking for something to add some standard rules for my c++ project

My team is developing a C++ project on linux. We use vim as editor. I want to enforce some code standard rules in our team in such a way that if the code is not in accordance with it, some sort of warning or error will be thrown when it builds or compiles. Not necessarily it builds but at least I can run some plugin or tools on that code to make sure it meets the standard. So that before committing to svn everyone need to run the code through some sort of plugin or script and make sure it meets the requirement and then only he/she can commit. Not sure if we can add some rules to vim, if there are any let me know about it.

For eg. In our code standards all the member variables and private functions should start with _

class A{
private:
    int _count;
    float _amount;
    void _increment_count(){ ++_count; }
}

So I want to throw some warning or error or some sort of messages for this class if the variables are declared as follows.

class A{
private:
    int count;
    float amount;
    void increment_count(){ ++_count; }
}

Please note that warning and error are not from compiler becoz program is still valid. Its from the tool I want to use so that code goes to re-factoring but still works fine on the executable side.

开发者_运维百科

I am looking for some sort of plugin or pre parsers or scripts which will help me in achieving all this.

Currently we use svn; just to anser the comment.


I would recommend using a commit hook, so that upon commit, a script is ran that will authorize (or not) the commit, and if possible report what's wrong in a friendly manner.

There are two projects of interests in CLang in this regard:

  • CLang Python bindings allow you to browse C++ code in Python, so you could check the files (obviously, only those which changed, to minimize the run-time)
  • There is a project to use a CLang backend to provide auto-completion in vim through those same Python bindings

If you are interested in either, you can ask on the CLang dev mailing list.


Coding Style is all about your own (or team) preferences, so find a tool that fit exactly your needs it's gonna be kinda hard to do.

Anyway, if you already have a Document or list with your rules for Coding Style, I suggest you to write a script in some easy-to-mantain language, like ruby or python and then edit your "commit hook" within the git repository to include the execution of this script against every CPP and Header file, and finally accept or reject the commit based on the output of the script.

Regards.


I've found a tool (vera++) that seems promising, but I've not tried it yet. If it is scriptable and you can use a hook in subversion to trigger its tests, it will be perfect :)

my2c

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜