我已将所有 python 项目源放在一个文件夹中。运行以下命令pylint似乎只是在每个源文件中查找和分析重复项,而不是在我想要的所有源文件中查找和分析重复项:
pylint --disable=all --enable=duplicate-code /some/source/folder/
Run Code Online (Sandbox Code Playgroud)
有没有办法在许多源文件中查找重复的代码?
python code-analysis static-analysis pylint code-duplication
这似乎是一件非常简单的事情,但我找不到相关信息。在 Visual Studio 中,计算所有项目的代码指标非常容易,我希望在 Azure DevOps 中的构建管道期间执行相同的操作。
有人做过这样的事吗?
我.editorconfig在整个解决方案中使用全局级别的文件。到目前为止,这工作正常。现有规则确实有效。
现在我想要为我的测试项目和课程制定规则VSTHRD200,我添加了以下几行:
# Test projects
[{IntegrationTest.*,Test.*}.csproj]
dotnet_diagnostics.VSTHRD200.severity = none # VSTHRD200: Use "Async" suffix for async methods
dotnet_analyzer_diagnostic.VSTHRD200.severity = none # VSTHRD200: Use "Async" suffix for async methods
# Test classes
[Test*.cs]
dotnet_diagnostics.VSTHRD200.severity = none # VSTHRD200: Use "Async" suffix for async methods
dotnet_analyzer_diagnostic.VSTHRD200.severity = none # VSTHRD200: Use "Async" suffix for async methods
Run Code Online (Sandbox Code Playgroud)
这些规则确实以某种方式起作用,我在输出窗口中看不到警告。但这些规则不适用于category-Style,意味着我确实看到测试方法的卷线,这些方法在编辑器中没有后缀Async。
我已经添加了dotnet_analyzer_diagnostic.category-Style.severity = none像 VS 2019 建议的那样,并将它们放置在测试项目和类的部分标题下,但我有一种感觉,它将禁用所有样式规则。
有没有办法只禁用VSTHRD200错误代码的样式?
我有一个C++/CLI项目,它使用CWinFormsControl和CWinFormsView在我的MFC视图中创建.NET控件.要做到这一点,我需要#include"afxwinforms.h".
当我在项目上运行代码分析时,我总是得到关于我所包含的一些MFC类的警告.例子:
3>Running Code Analysis...
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.h(87) : warning: CA1704 : Microsoft.Naming : In method 'CWin32Window::CWin32Window(HWND__*)', correct the spelling of 'Wnd' in parameter name 'hWnd' or remove it entirely if it represents any sort of Hungarian notation.
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.h(87) : warning: CA1704 : Microsoft.Naming : In method 'CWin32Window::CWin32Window(HWND__*)', correct the spelling of 'h' in parameter name 'hWnd' or remove it entirely if it represents any sort of Hungarian notation.
3>warning: CA1051 : Microsoft.Design : …Run Code Online (Sandbox Code Playgroud) mfc code-analysis c++-cli suppress-warnings visual-studio-2008
我们计划使用Splint作为C代码库的代码分析器.但我们之前从未尝试过Splint工具,因此我们希望您对其进行改进,利弊.
给出以下代码:
bool doGoodThing;
switch (some_variable)
{
case 1:
case 2:
doGoodThing = true;
default:
doGoodThing = false;
}
Run Code Online (Sandbox Code Playgroud)
最新gcc版本足够智能,可以检测何时分配变量但仍未使用,等等.是否有任何编译器或标志可以触发警告说整个开关对这样的代码没有任何意义?
更新:问题不在于doGoodThing变量.这是一个愚蠢的switch陈述,没有多大意义.
更新2:在你将"重复"选民标记为重复之前通过它 - 再次阅读一个问题.这不是关于"案件"之后缺少"休息"声明的警告.这是关于死代码,逻辑错误,编译器对代码的静态语义分析.如果没有"休息",我不需要警告.
sum = 0;
for (i = 1; i <= n; i++) { //#1
for (j = 1; j <= i * i; j++) { //#2
if (j % i == 0) { //#3
for (k = 1; k <= j; k++) { //#4
sum++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
以上让我感到困惑
Suppose #1 runs for N times
#2 runs for N^2 times
#3 runs for N/c since for N inputs N/c could be true conditions
#4 runs for N times
Run Code Online (Sandbox Code Playgroud)
因此大致我可以看O(N ^ …
我在GitHub中托管了我的源代码库.我现在希望我的Sonar实例(部署在Amazon EC2上)定期从git存储库中提取以分析代码库.该项目是一个简单的JavaScript项目,我不想让ANT,Maven或Jenkins参与其中,但只需Sonar定期提取代码.
这可能吗?
javascript code-analysis static-code-analysis sonar-runner sonarqube
我正在尝试使用visual studio的代码分析功能.不幸的是(或幸运的是?),我住在加拿大,代码分析抱怨我的拼写"颜色"这个词.我正在尝试使用自定义词典,但VS2013似乎忽略了它.
这是字典相对于项目(和解决方案)的位置:

这是字典文件的内容:
<Dictionary>
<Words>
<Unrecognized>
<Word></Word>
</Unrecognized>
<Recognized>
<Word>colour</Word>
</Recognized>
<Deprecated>
<Term PreferredAlternate=""></Term>
</Deprecated>
<Compound>
<Term CompoundAlternate=""></Term>
</Compound>
<DiscreteExceptions>
<Term></Term>
</DiscreteExceptions>
</Words>
<Acronyms>
<CasingExceptions>
<Acronym></Acronym>
</CasingExceptions>
</Acronyms>
</Dictionary>
Run Code Online (Sandbox Code Playgroud)
我也尝试剔除自定义词典的内容:
<Dictionary>
<Words>
<Recognized>
<Word>colour</Word>
</Recognized>
</Words>
</Dictionary>
Run Code Online (Sandbox Code Playgroud)
有谁知道发生了什么以及如何解决这个问题?
我试图找到未使用Visual Studio 2012代码从任何其他代码(CA1811)https://msdn.microsoft.com/en-us/library/ms182264 (v = vs.110).aspx调用的私有方法尽管将项目代码分析规则设置为" 所有规则 " ,但分析购买它并未检测到它.这个有可能?在这种情况下,如何配置我的项目解决方案?如果安装任何扩展,我宁愿它是免费的.谢谢!
code-analysis ×10
c# ×3
c ×2
azure-devops ×1
big-o ×1
c++ ×1
c++-cli ×1
code-metrics ×1
devops ×1
editorconfig ×1
for-loop ×1
java ×1
javascript ×1
mfc ×1
msbuild ×1
pylint ×1
python ×1
sonar-runner ×1
sonarqube ×1
splint ×1
vb.net ×1