是否有可能在源代码中抑制声纳云的警告? [英] Is there a possibility to suppress warnings of sonarcloud in source code?
问题描述
我遇到了一些声纳云警告的问题,这些警告在不久的将来不会得到修复(现在应该被禁用).
I am facing an issue with some sonarcloud warnings that will not be fixed in the nearest future (and should be disabled for now).
在 CI 上构建期间,sonarcloud 会发出警告.没有任何本地分析器.有没有办法在项目、文件、类和/或方法级别上抑制源代码中的某些特定警告?
The warnings are raised by sonarcloud during build on CI. There are no any local analysers. Is there a way to suppress some specific warnings in source code on project, file, class and/or method levels?
官方文档没有太大帮助,至少我没有设法找到解决方案.
The official documentation is not of much help, at least I did not manage to find the solution.
声纳云是否尊重一些
#pragma warning disable S3881
或其他基于属性的方法或一些全局设置.
or other attribute based approach or some global settings.
推荐答案
有多种方法可以做到这一点(至少在 Java 中,但我认为它可能对你有所帮助)
There are multiple ways of doing so (at least in java, but i think it might help you anyways)
GUI 方式 - 您可以在其中定义要与特定规则匹配的密钥和文件模式.这允许您例如.排除规则的测试或文件夹
the GUI way - where you can define a Key and a file Pattern to be matched for a specific rule. This allows you to eg. exclude tests or folders for a rule
注释方式(Java 版本)-在 Java 中,您可以通过使用 //NOSONAR <可选原因>
跟踪它们来忽略扫描仪中的整行-我认为这也有效在 C# 中(但请验证,如果合适并让我们知道)
The comment way (java version) - in Java you can ignore whole lines from the scanner by trailing them with //NOSONAR <optional reason>
- i assume that this also works within C# (but please verify, if suitable and let us know)
Annoation 方式(java 版本) - 但看起来类似于 #pragma warning disable
The Annoation way (java version) - but looks similar to #pragma warning disable
@SuppressWarnings("squid:S2068")
是我们如何在 Java 中禁用代码块规则的方法 - 所以我假设您使用 #pragma warning disable S3881
的方法是正确的方向,但它应该是 #pragma warning disable csharpsquid:S3881
.
is the way, how we can disable a rule for a codeblock in Java - so i would assume your approache with #pragma warning disable S3881
is the right direction but it should be #pragma warning disable csharpsquid:S3881
.
正如所说,我不是 C# 开发人员,也不太熟悉该语言,但我希望 java 方式和 gui 方式能帮助您朝着正确的方向前进.
As said i am not a c# developer and not really familiar with that language, but i hope the java ways and the gui way, will help you move into the right direction.
这篇关于是否有可能在源代码中抑制声纳云的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!