如何在不运行python程序的情况下检查错误.我想得到错误消息,说明我的错误在哪一行.但我不想执行该程序.
当使用 MSBuild 针对项目运行各种分析器时,所有失败都将以“静态分析结果交换格式 (SARIF)”格式输出(参见例如https://github.com/sarif-standard/sarif-spec)。例如,构建可能会产生以下结果
{
"version": "0.1",
"toolInfo": {
"toolName": "Microsoft (R) Visual C# Compiler",
"productVersion": "1.1.0",
"fileVersion": "1.1.0"
},
"issues": [
{
"ruleId": "SA1401",
"locations": [
{
"analysisTarget": [
{
"uri": "C:\\SomeFile.cs",
"region": {
"startLine": 708,
"startColumn": 30,
"endLine": 708,
"endColumn": 36
}
}
]
}
],
"shortMessage": "Field must be private",
"fullMessage": "A field within a C# class has an access modifier other than private.",
"properties": {
"severity": "Warning",
"warningLevel": "1",
"defaultSeverity": "Warning",
"title": "Fields must …Run Code Online (Sandbox Code Playgroud) 我的公司使用 SonarQube 已经有一段时间了,现在我们安装了最新的 SonarQube 版本 6.4,我们想升级我们正在使用的质量配置文件。
据我所知,不再需要使用 FindBugs、PMD 和 Checkstyle 插件,因为 SonarJava 插件中的规则包含其他插件中的所有规则。
我想使用“Sonar way”内置配置文件,但我注意到它只包含 SonarJava 存储库中所有规则的子集。Sonar 方式有 292 条规则,SonarJava 规则库中有 427 条规则。我注意到“声纳方式”中缺少一些重要规则。
问题是:
我正在尝试CppCheck在Ubuntu中使用该工具。我运行了以下命令
cppcheck --enable=all --check-config --suppress=missingIncludeSystem main.c 2>err.txt
Run Code Online (Sandbox Code Playgroud)
它创建err.txt的文件,但它是空的。
如何获得评分或检查main.c文件中的代码。
我们使用声纳进行代码分析。对于这样的课程
public class Car {
private Engine engine;
// getter setter for engine
}
Run Code Online (Sandbox Code Playgroud)
我们收到错误,例如
Non-abstract classes and enums with non-static, private members should explicitly initialize those members, either in a constructor or with a default value.
我们通常使用 Jackson 序列化我们的对象,因此构造函数不会在我们的代码中的任何地方使用。那么为什么我还需要编写构造函数呢?禁用此规则是否有意义? 规则链接
另一件事,如果我更改代码如下
private Engine engine = null;
Run Code Online (Sandbox Code Playgroud)
错误不会被抛出。默认情况下,所有 Java 引用都分配有空值。这条线是在欺骗声纳吗?这应该是声纳中的一个错误吗?
我有ViewStatePOJO 类,它们的构造函数带有许多参数。问题是 PMDExcessiveParameterList对他们施加了违规行为。
现在我试图抑制所有以ViewState.java(例如 in DashboardViewState.java)结尾的类的这种违规行为。我已将其添加到我的rules-pmd.xml:
<rule ref="category/java/design.xml/ExcessiveParameterList">
<properties>
<!--Ignore ExcessiveParameterList on ViewState classes -->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration['*ViewState.java']"/>
</properties>
</rule>
Run Code Online (Sandbox Code Playgroud)
问题是,这将压制所有针对ExcessiveParameterList哪个阶级的违规行为。我究竟做错了什么?
java static-analysis pmd suppress-warnings static-code-analysis
我想对 C/C++ 代码运行某种 linter 或静态代码分析,如果存在缺少文档的代码(例如没有 doxygen 样式文档注释的函数),则会发出警告。换句话说,我想强制执行某些代码标准。我研究了clang-tidy和cppcheck,但没有走得太远。
为了让我更清楚我对 Python 的期望,我习惯了这样的事情:
$ cat test.py
def answer():
return 42
$ python3 -m pylint test.py
************* Module test
test.py:1:0: C0111: Missing module docstring (missing-docstring)
test.py:1:0: C0111: Missing function docstring (missing-docstring)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
Run Code Online (Sandbox Code Playgroud) 我想强制某个结构永远不会直接访问它的字段,总是使用结构函数.
例:
struct NoOutsideAccess { int field1;}
struct example {NoOutsideAccess f1;}
NoOutsideAccess noa;
example * ex;
&noa // OK
&ex->noa // OK
noa.field1; // ERROR
ex->f1.field1 // ERROR
Run Code Online (Sandbox Code Playgroud)
我看过C解析器和分析工具,但我不确定我能用它们做到这一点.
我不想更改结构,因为它的字段将直接在其他模块中使用.在这种情况下,我想要一些脚本来指出它的使用位置,以便不应该改变它的模块.
但我确实发现了一个副本,不确定是否会匹配每个用法,但会给它一个镜头.
以下功能比使用memcpy安全吗?Memcpy在Checkmarx静态代码分析中给出以下“ Improper_Null_Termination”错误:at行中的字符串被at终止其终止的空字节。但是,如果我使用以下功能,Checkmarx不会出现问题:
void myMemCpy(void *dest, void *src, size_t n)
{
// Typecast src and dest addresses to (char *)
char *csrc = (char *)src;
char *cdest = (char *)dest;
// Copy contents of src[] to dest[]
for (int i=0; i<n; i++)
cdest[i] = csrc[i];
}
Run Code Online (Sandbox Code Playgroud)
使用此函数代替memcpy()是否有任何问题?
通过在PVS-Studio中进行一些代码分析,它给了我一些警告消息。
我在头文件中有以下语句:
constexpr int MIN_ALLOWED_Y { 0 };
Run Code Online (Sandbox Code Playgroud)
在源文件中:
std::make_pair<const int, const int>( std::move( MIN_ALLOWED_Y ), std::move( MAX_ALLOWED_Y ) )
Run Code Online (Sandbox Code Playgroud)
在上面的表达式中,我曾经std::move转换MIN_ALLOWED_Y为 xvalue,因为我认为std::make_pair只接受右值;
// from https://en.cppreference.com/w/cpp/utility/pair/make_pair
template< class T1, class T2 >
constexpr std::pair<V1,V2> make_pair( T1&& t, T2&& u );
Run Code Online (Sandbox Code Playgroud)
但我收到如下警告消息:
V833 Passing the const-qualified object 'MIN_ALLOWED_Y' to the 'std::move' function disables move semantics.
Run Code Online (Sandbox Code Playgroud)
这是有效的警告吗?如果是这样那我该怎么办?我应该删除std::move(也许在这种情况下它是多余的?)?
更好的问题是哪里不应该使用std::move?