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 an editor. I want to bring some standard code rules in our team in such a way that, if the code does not match it, some warning or error will be generated during assembly or compilation. It doesn’t necessarily build, but at least I can run some kind of plugin or tools for this code to make sure that it complies with the standard. So that before executing svn everyone needs to run the code through some kind of plugin or script and make sure that it meets the requirement, and then only he / she can commit it. Not sure if we can add some rules to vim, if any, let me know.

For example, in our code standards, all member variables and private functions must begin with _

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

Therefore, I want to throw a warning or error or some messages for this class if the variables are declared as follows.

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

Note that the warning and error are not from the compiler. Becoz is still valid. It is from a tool that I want to use so that the code switches to re-factoring, but still works fine on the executable side.

I am looking for some kind of plugin or preliminary parsers or scripts to help me achieve all of this.

We are currently using svn; just to comment on the comment.

+4
source share
3 answers

I would recommend using a commit hook, so that after commit, a script is run that will allow (or not) commit and, if possible, report what is wrong in a friendly manner.

In this regard, there are two CLang interest projects :

  • Python CLang associations allow you to view C ++ code in Python, so you can check files (obviously, only those that have been modified to minimize execution time)
  • There is a project using the CLang backend to provide automatic completion in vim via the same Python bindings

If you are interested in this, you can request the devang mailing list .

+1
source

The coding style is all your own (or team) settings, so find a tool that exactly matches your needs. It will be hard to do.

Anyway, if you already have a document or a list with your rules for the coding style, I suggest you write a script in some simple language, for example ruby ​​or python, and then edit your "commit hook" in the git repository enable the execution of this script for each CPP file and header, and finally accept or reject the commit based on the output of the script.

Sincerely.

0
source

I found a tool ( vera ++ ) that seems promising, but I haven't tried it yet. If it is scriptable and you can use the hook in a subversive game to run its tests, it will be perfect :)

my2c

0
source

Source: https://habr.com/ru/post/1339105/


All Articles