A free tool to check C/C++ source code against a set of coding standards? [closed]
Asked Answered
A

12

161

It looks quite easy to find such a tool for Java (Checkstyle, JCSC), but I can't seem to find one for C/C++. I am not looking for a lint-like static code analyzer, I only would like to check against coding standards like variable naming, capitalization, spacing, identation, bracket placement, and so on.

Anemology answered 18/9, 2008 at 14:50 Comment(1)
If you don't find the answer you want here, consider this question: https://mcmap.net/q/102721/-automatic-code-style-guide-test-for-c-duplicate/120163Priddy
B
58

The only tool I know is Vera. Haven't used it, though, so can't comment how viable it is. Demo looks promising.

Bellinzona answered 18/9, 2008 at 14:54 Comment(7)
I have tested it, and it is quite simple. But it works!Bosquet
I tried it but was disappointed. It tokenised C++ code but has only a single token type for "identifiers", so it doesn't differentiate between say class names, member variables and local variables. There is therefore no way I could find to enforce different naming conventions to different types of identifier.Alexandria
Vera does not have a very comprehensive set of rules - but they are extendable (in TCL)Hazy
"Extensible" only for very simple tasks. Since Vera's understanding of C++ is shallow, any "deep style check" (consider a possible [I'm not suggesting good] rule: for every allocation, there's a corresponding deallocation in the same function) will have to encode the appropriate C++ knowledge, and that is really really hard, which means it won't happen.Priddy
Fixed link to Vera: bitbucket.org/verateam/veraGabbi
I just gave it a quick try: It gave up parsing entirely upon encountering something seemingly trivial as a one-line comment that followed the closing bracket of a namespace declaration. It said I should "fix" it or exclude file...Desperation
Vera is incredibly impossible to build from scratch, which you have to do if you're using a CI system and don't want to use TCL. I'll pass.Anatol
F
50

Google c++lint from Google code style guide.

Fineman answered 28/7, 2009 at 10:11 Comment(6)
+1. This is very nice - though it does have a very strict style. Not that easy to extend with own rules like with vera++.Hazy
Great if you're using Google's C++ style though :) +1Wolf
I assume this is now whats called cpplint It can be found at github.com/google/styleguide/tree/gh-pages/cpplint , the link above to c++lint is broken.Gangster
Just for reference, to install, you can use "pip install cpplint". Then you can just use "cpplint file.cpp" or "cpplint --recursive ." instead of "./cpplint.py" which is much preferable IMO. Easier than downloading through github at leastHelli
Why Google Style Guide for C++ is a deal-breakerKanaka
I'd really add a word about the downsides of Googles style guide for C++, maybe a link to the interesting article @LưuVĩnhPhúc mentioned. For me, the most important question is if the tool can be easily modified to conform to different stale guides?Christoper
N
8

I'm sure this could help to some degree cxx checker. Also this tool seems to be pretty good KWStyle It's from Kitware, the guys who develop Cmake.

Negotiate answered 11/2, 2009 at 16:54 Comment(2)
cxxchecker seems very dead to me now.Panocha
cxx checker is a dead link.Christoper
A
7

Not exactly what you ask for, but I've found it easier to just all agree on a coding standard astyle can generate and then automate the process.

Attaboy answered 18/9, 2008 at 17:8 Comment(1)
You better make clear that ArtisticStyle focuses solely on formatting which of course is not a bad thing :)Christoper
B
6

Try nsiqcppstyle. It's a Python based coding style checker for C/C++. It's easy to extend to add your own rules.

Baudekin answered 22/11, 2011 at 23:12 Comment(0)
O
5

There's a list. There is also a putative C++ frontend on splint.

Outmaneuver answered 18/9, 2008 at 15:3 Comment(1)
-1 because question explicitly said "not looking for static code analyzer".Jannery
C
2

I have used a tool in my work its LDRA tool suite

It is used for testing the c/c++ code but it also can check against coding standards such as MISRA etc.

Concurrence answered 18/9, 2008 at 15:2 Comment(2)
Why is this down modded? Even if LDRA is also a static analyzer - something the question is not looking for - I believe it's also capable to check the code for violations of a coding standard.Bedesman
LDRA costs about as much as your average car... not my idea of free.Rountree
M
2

Check universalindentgui on sourceforge.net.

it has many style checkers for C and you can customise the checkers.

Mantra answered 27/12, 2008 at 10:21 Comment(1)
UniversalIndentGUI It has a live preview function, can export config and export script. It's great for trying out different "indenters", such as GNU Indent, Artistic Style and Uncrustify.Gabbi
W
1

There is cppcheck which is supported also by Hudson via the plugin of the same name.

Wo answered 15/7, 2010 at 21:53 Comment(2)
cppcheck is a static analysis tool and not what the question is looking for.Bedesman
Maybe this changed since 2010: Today Cppcheck also includes warnings for stylistic issues. But, well, the OP explicitly excluded static code analyzers.Christoper
M
1

Check Metrix++ http://metrixplusplus.sourceforge.net/. It may require some extensions which are specific for your needs.

Moniliform answered 12/8, 2013 at 10:46 Comment(0)
M
0

Check out Abraxas Code Check http://www.abxsoft.com/codchk_user.html

Mascagni answered 7/8, 2012 at 14:9 Comment(1)
besides the documentation, it's not free: abxsoft.com/codchk.htm Plus, it seems to be outdated abxsoft.com/pricing.htmChristoper
H
-1

I'm currently working on a project with another project to write just such a tool. I looked at other static code analysis tools and decided that I could do better.

Unfortunately, the project is not yet ready to be used without fairly intimate knowledge of the code (read: it's buggy as all hell). However, we're moving fairly quickly, and hope to have a beta release within the next 8 weeks.

The project is open source - you can visit the project page, and if you want to get involved, we'd love some more external input.

I won't bore you with the details - you can visit the project page for that, but I will say one thing: Most static code analysis tools are aimed at checking your code for mistakes, and not very concerned with checking for coding guidelines. We have taken a more flexible approach that allows us to write plugiins to check for both "house rules" as well as possible bugs.

If you want any more information, please don't hesitate to contact me.

Cheers,

Hierophant answered 14/2, 2009 at 20:25 Comment(1)
Last commit was in June 2009. It seems to be no longer developed.Yoga

© 2022 - 2024 — McMap. All rights reserved.