标签: cpplint

谷歌关于输入/输出参数的样式指南作为指针

谷歌C++样式指南绘制有明显的区别(严格接着cpplint.py输入参数之间)(→常量REF,值)和输入-输出或输出参数(→非const的指针):

C/C++函数的参数既可以是函数的输入,也可以是函数的输出,或者两者兼而有之.输入参数通常是值或const引用,而输出和输入/输出参数将是非常量指针.

并进一步 :

事实上,在Google代码中,一个非常强大的约定是输出参数是值或const引用,而输出参数是指针.

但我无法弄清楚为什么不应该通过引用传递输入/输出参数(我将输出参数放在一边).在stackoverflow上有很多与这个问题相关的主题:例如,在这里,接受的答案清楚地说明了这一点

它主要是关于风格

但是如果

如果您希望能够传递null,则必须使用指针

那么,如果我想避免指针为空,总是需要一个指针是什么意思?为什么只使用输入参数的引用?

c++ parameters reference google-style-guide cpplint

10
推荐指数
2
解决办法
1万
查看次数

禁用cpplint中的特定警告

运行cpplint时,我遇到了一些我想完全禁用的警告.特别是版权信息和空白:

range.h:0:未找到版权信息.你应该有一条线:

"版权所有[年]"[法律/版权] [5]

range.h:10:代码和注释之间至少有两个空格

[空白/评论] [2]

我该如何做到这一点?理想情况下,修改CPPLINT.cfg文件,但我会采用内联注释或命令行标志.我找不到任何关于禁用规则的文档.

c++ cpplint linter

10
推荐指数
1
解决办法
5229
查看次数

c ++中if(指针)与if(指针!= NULL)之间的区别,cpplint问题

我已经检查了这篇文章我可以使用if(指针)而不是if(指针!= NULL)吗?网上还有其他一些帖子.

但它没有说两个陈述之间有任何区别.

问题:当我在cpp代码上运行cpplint.py时,我发现了检查指针为NULL的问题.我更喜欢用简单的方法来检查

if(pointer)         //statement1
Run Code Online (Sandbox Code Playgroud)

但是cpplint说你应该检查一下

if(pointer != NULL)        //statement2
Run Code Online (Sandbox Code Playgroud)

所以我只想知道,statement2statement1有什么好处吗?是否存在一些语句可能会产生问题?

工作:据我所知,这两个陈述的工作没有区别.它只是改变了编码风格.

我更喜欢使用like statement1,因为

  • 它简单易读
  • 没有张力=错误(==)在比较中错误地超过了()

但是cpplint正在提出这个问题,那么我可能会有一些好处.

注意: Java也不支持statement1.

c++ pointers coding-style cpplint

9
推荐指数
1
解决办法
376
查看次数

在整个项目上运行CPPlint

我想在整个项目上运行cpplint.py而不是单个文件来获取项目中所有C / C ++文件的报告。如何在macOS和Windows上执行此操作?

google-style-guide cpplint

5
推荐指数
1
解决办法
5589
查看次数

cpplint.py & cmake:如何指定包含文件

假设我有一个目录结构如下的项目:

myproject
??? .git [...]
??? CMakeLists.txt
??? src
    ??? CMakeLists.txt
    ??? foo.cc
    ??? foo.h
Run Code Online (Sandbox Code Playgroud)

如果在src/foo.cc我包含头文件#include "foo.h",然后在其上运行 Google 的cpplint.py,它会抱怨

src/foo.cc:8:  Include the directory when naming .h files  [build/include] [4]
Run Code Online (Sandbox Code Playgroud)

所以我把它作为#include "./foo.h". 现在我收到另一个投诉:

src/foo.cc:8:  src/foo.cc should include its header file src/foo.h  [build/include] [5]
Run Code Online (Sandbox Code Playgroud)

但是,如果我将它包含为#include "src/foo.h",编译器将找不到它,因为我当前的 CMake 设置。这是我的两个 CMakeLists.txt 文件的样子:

CMakeLists.txt:

project(myproject)
add_subdirectory(src)
Run Code Online (Sandbox Code Playgroud)

源代码/CMakeLists.txt:

set(SRCS foo.cc)
add_executable(foo ${SRCS})
Run Code Online (Sandbox Code Playgroud)

我使用 CMake 的方式在某种程度上从根本上是错误的吗?我应该src/CMakeLists.txt完全删除文件,并使用CMakeLists.txt完整路径指定基础中的所有源文件吗?

或者我应该简单地忽略 cpplint 的抱怨,因为它们并不真正适合 CMake 项目的设置方式?

c++ cmake include-path cpplint

5
推荐指数
1
解决办法
4828
查看次数

如何让vim在每次"save"命令后运行"cpplint"?

我希望每次"w"在vim中保存.h/.cpp文件时,vim会自动运行cpplint来检查我的格式,并在需要时更改文件.

如何用autocmd指定?

谢谢.

vim save autocmd cpplint

5
推荐指数
1
解决办法
1505
查看次数

如何在 cpplint 中使用 exclude_files 正则表达式?

我正在使用 cpplint 根据谷歌风格指南检查我的源代码。

Cpplint 的帮助说:

cpplint.py supports per-directory configurations specified in CPPLINT.cfg
    files. CPPLINT.cfg file can contain a number of key=value pairs.
    Currently the following options are supported:

    "exclude_files" allows to specify a regular expression to be matched against
    a file name. If the expression matches, the file is skipped and not run
    through liner.

Example file:
        filter=-build/include_order,+build/include_alpha
        exclude_files=.*\.cc

    The above example disables build/include_order warning and enables
    build/include_alpha as well as excludes all .cc from being
    processed by linter, in …
Run Code Online (Sandbox Code Playgroud)

regex google-style-guide cpplint

3
推荐指数
1
解决办法
1866
查看次数

如何使 cpplint 与 Jenkins 警告插件一起工作

我在 Jenkins 中添加了一个“执行 shell”构建步骤来运行 cpplint.py

python /var/lib/jenkins/scripts/cpplint.py --counting=detailed `find path -name *.cpp
Run Code Online (Sandbox Code Playgroud)

我还添加了“扫描编译器警告”并添加了 CppLint。

然而,即使它在控制台输出中显示一些警告,它也总是得到 0 个警告,例如

filename.cpp:18:  Missing space after ,  [whitespace/comma] [3]
Run Code Online (Sandbox Code Playgroud)

lint compiler-warnings jenkins cpplint

2
推荐指数
1
解决办法
4568
查看次数

如何在 CMake 中使用 cpplint 代码样式检查?

我找到的唯一在线资源是有关CMAKE_<LANG>_CPPLINT此处链接)和此示例(此处链接)的 CMake 文档,但我无法弄清楚如何在 CMakeLists.txt 文件中实际使用它。我尝试了提供的示例,但无法使其正常工作。仅供参考,我按照此处的说明安装了 cpplint 。

到目前为止,我可以使用以下 CMake 命令在 CMakeLists.txt 中运行 cpplint python 脚本:

execute_process(COMMAND cpplint path/To/File/To/Analyse.cpp)
Run Code Online (Sandbox Code Playgroud)

但是,我很确定这不是执行此操作的正确方法。

cmake cpplint

2
推荐指数
1
解决办法
3505
查看次数

C++中不允许使用static/global变量

我在C++类中定义了一个全局变量,如下所示:

std::string VAR = "HELLO_WORLD";
Run Code Online (Sandbox Code Playgroud)

但是cpplint告诉我:

不允许使用静态/全局字符串变量.[runtime/string] [4]

你知道为什么吗?

c++ cpplint

1
推荐指数
1
解决办法
1283
查看次数