c 的编码风格检查器(变量名称,而不是缩进)
这个问题询问编码风格检查器,但重点似乎是缩进和支架放置。 GNU indent 处理缩进(这在这个代码库中不是问题,令人惊讶的是)。
我正在使用一堆充满各种命名方案的代码:camelCase
、everythingruntogetherinlowercase
、underscores_as_separators
、SomeStructsEndWithT
code> 等。
我希望能够选择一个约定,并至少自动检查新的更改是否符合约定。
有没有一个好的工具可以检查 C 中的命名?像Python的pep8检查器工具之类的东西,我不需要美化器。
谢谢。
This question asks about a coding style checker, but the focus seems to be on indentation and brace placement. GNU indent deals with indentation (which isn't a problem in this code base, amazingly enough).
I'm working with a pile of code that is full of various naming schemes: camelCase
, everythingruntogetherinlowercase
, underscores_as_separators
, SomeStructsEndWithT
, etc.
I'd like to be able to pick a convention and at least have an automatic check that new changes are in line with the convention.
Is there a good tool for checking naming in C? Something like Python's pep8 checker tool, I don't want a beautifier.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来 Google 的 cpplint(C++ 风格检查器)可能会被黑客入侵像我想要的那样提交检查 C。
(我仍然有兴趣知道是否有更好的检查器。)
It looks like Google's cpplint (a C++ style checker) can be hacked into submission for checking C like I want.
(I'm still interested in knowing if there are any better checkers out there.)
这是一个非正统的选择,但如果您愿意投入半天的时间,我会选择
cxref
。它是一个交叉引用器,附带源代码,它有一个干净的解析器,并且不构建解析树。然而,只需几行代码,您就可以转储所有变量来检查它们,或者将它们重写为您喜欢的样式(或者如果您像我一样懒惰,而不是重写,您可以为 emacs/sed 生成替换命令)。我只设法为 Mac 构建它。It is an unorthodox choice, but I'd go with
cxref
, if you are willing to put in half a days work. It is a cross referencer, comes with the source code, it has a clean parser and doesn't build a parse tree. Yet, with a few lines of code you can dump all the variables to examine them, or rewrite them to your favoured style (or if you are as lazy as I am instead of rewriting you could generate replace commands for emacs/sed). I only managed to build it for Mac.C 的编码风格检查器 中已经有很多答案
这个线程 Vera++ 可能是最有前途的,因为大多数其他建议都是格式化程序而不是验证程序。有一个关于运行 vera++ 的网页:
https://bitbucket.org/verateam/vera/wiki/Running。
可从 https://bitbucket.org/verateam/ 下载维拉/下载/vera++-1.1.1.tar.gz
编译会出现一些问题:
sudo apt-get install libboost-dev tcl-dev
tcl/tcl.h< 的
tcl.h
/code>make BOOST_DIR=/home/fluffy/tmp/boost_1_53_0
~/.vera++/profiles/
但不会自动创建默认值(可以从发行版中复制,但是)最后,在 C++ 文件上运行它会产生如下输出(为简洁起见,省略重复错误):
This one has a number of answers already in this thread Coding style checker for C
from which Vera++ might be the most promising, since most of the other suggestions are formatters not validators. There's a webpage about running vera++ at
https://bitbucket.org/verateam/vera/wiki/Running.
There's a download from https://bitbucket.org/verateam/vera/downloads/vera++-1.1.1.tar.gz
Compiling presents a few issues:
sudo apt-get install libboost-dev tcl-dev
tcl.h
that should have beentcl/tcl.h
make BOOST_DIR=/home/fluffy/tmp/boost_1_53_0
~/.vera++/profiles/
but doesn't autocreate a default (it can be copied from the one in the distribution, however)Finally, running it on a C++ file produced output like (with duplicate errors omitted for brevity):