Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Google-Style: Automatic correction

Tags:

c++

checkstyle

I have a research project with several files (~100). The code has been written over the years without any specific style. Each developer (mostly master students that come, code and leave) used their own "style", if any.

Now, I'm trying to maintain the code in a way to make new people that join us follow certain rules. I found that Google published some style-guide. Luckily enough they published also a python script, that is easy to use.

The problem is, the script gives me for each file a tone of silly errors like

Missing space after ,  [whitespace/comma] [3]

or

Missing space before {  [whitespace/braces] [5]

My question is: Is it somehow possible to automatize the correction of such "errors"? That mean running a script over a file that eliminates automatically all those errors.

like image 518
Tengis Avatar asked May 01 '14 13:05

Tengis


People also ask

Is Google C++ style guide good?

It was vetted for being useful at the time when it was introduced. Many parts of C++ are very old and what was considered useful at the time might be a bad idea nowadays, either because better alternatives exist, or because it turned out that the feature has flaws.

What is probably too long for functions according to the Google style guide?

A decent rule of thumb is to not inline a function if it is more than 10 lines long. Beware of destructors, which are often longer than they appear because of implicit member- and base-destructor calls!

How do I use CPP lint?

Starting in Visual Studio 2022, the C++ Linter is enabled by default. To use it, just open a source file in the editor. The linter shows any problems it finds by annotations in the editor window and in the Error List window. In Visual Studio 2019, the C++ linter is available as an option.

What are the C++ coding conventions?

Common guidelines for C and C++ codeDo not use leading underscores, as all such names are reserved according to the C/C++ standard. Name include guards like GMX_DIRNAME_HEADERNAME_H . Boolean variables are always named with a b prefix, followed by a CamelCase name. Enum values are named with an e prefix.


1 Answers

clang-format might be useful, as it can be run with an option to use Google style rules:

clang-format -style=Google ...

See e.g. http://clang.llvm.org/docs/ClangFormatStyleOptions.html

like image 72
Nate Kohl Avatar answered Sep 21 '22 16:09

Nate Kohl