在Sonar中,如何防止检查某些包中的某些规则?
我们有一个具有公共部分的 Android/Blackberry 项目。显然,该部分是为了编译到 Android 和 Blackberry 目标而编写的,因此无法使用一些较新的 Java 功能(例如,Integer.valueOf)。我想跳过一些专门针对该部分的规则。有办法做到这一点吗?
We have an Android/Blackberry project with a common part. That part, obviously, is written to compile to both Android and Blackberry targets, and, consequently, cannot use some of the newer Java features (e.g., Integer.valueOf). I'd like to skip some of the rules specifically for that part. Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将公共部分分离到自己的项目中,则可以添加新的质量配置文件 在 Sonar 中(您在其中停用了这些规则)并将其分配给您的公共项目。
除此之外,您可以使用
注释来抑制单行警告(请参阅常见问题解答 )。
If you separate the common part to an own project you can add a new Quality Profile in Sonar (where you deactivated these rules) and assign it to your common project.
Apart from that you can use the
comment to supress a warning on a single line (see FAQ).
这是一个较旧的问题,我认为同时有一个更好的解决方案:
将 // NOSONAR 添加到相关类以某种方式解决了该问题。但我认为这是有问题的,因为在这种情况下根本不会应用任何规则。不过还有另一种方法可以解决这个问题:
忽略多个条件的问题
示例:< /strong>
我想忽略所有 java 文件中 com.foobar.domain 包中针对编码规则 MagicNumbers 的所有问题。
在 Sonar 中导航到您的项目,转到“Configuration\Settings\Issues”,然后在“Ignore Issues on Multiple Criteria”中添加:
这一切在链接文档中也得到了很好的解释。
This is an older question and I think meanwhile there is a better solution:
Adding // NOSONAR to the relevant classes solves the issue somehow. But I think this is problematic since no rules will be applied in this case at all. There is another way to solve this though:
Ignore Issues on Multiple Criteria
Example:
I want to ignore all issues against coding rule MagicNumbers in the package com.foobar.domain in all my java files.
In Sonar navigate to your project, go to Configuration\Settings\Issues and in Ignore Issues on Multiple Criteria add:
This is all also explained very nicely in the linked documentation.