How do I ignore duplicated code report in Sonar?(如何忽略 Sonar 中的重复代码报告?)
问题描述
SonarQube 向不同的简单 POJO 类报告为重复代码块",如下所示.在这种情况下,A 和 B 是不同的角色.所以,我认为我不应该创建抽象类.
公共类 A{私人字符串 xxx;//省略其他字段.公共 A() {}公共字符串 getXxx() {返回xxx;}公共无效 setXxx(字符串 xxx){this.xxx=xxx;}//省略其他字段的 setter 和 getter}公共类 B{私人字符串 xxx;//省略其他字段.公共 B() {}公共字符串 getXxx() {返回xxx;}公共无效 setXxx(字符串 xxx){this.xxx=xxx;}//省略其他字段的 setter 和 getter}
严重性为主要.所以,我想忽略它.然后,我将@SuppressWarning("common-java:DuplicatedBlocks") 和@SuppressWarning("all") 添加到这两个类中.但也不容忽视.
虽然在
有时 Sonar 报告的情况并不严重,但又取决于项目性质 :)
但是,就像上面评论中提到的@Stephen,如果 xxx
是相同的字段和继承是有意义的,那么你可以有父抽象类来避免报告.
SonarQube reports as "block of duplicated code" to different simple POJO class like below. In this case, A and B are different role. So, I think that I should not create abstract class.
public class A{
private String xxx;
// omitted other fields.
public A() {}
public String getXxx() {
return xxx;
}
public void setXxx(String xxx) {
this.xxx= xxx;
}
// omitted other fields' setter and getter
}
public class B{
private String xxx;
// omitted other fields.
public B() {}
public String getXxx() {
return xxx;
}
public void setXxx(String xxx) {
this.xxx= xxx;
}
// omitted other fields' setter and getter
}
The severity is Major. So, I would like to ignore it. Then, I added @SuppressWarning("common-java:DuplicatedBlocks") and @SuppressWarning("all") to both classes. But it could not be ignored.
Though similar question was raised in JIRA, but it have been not solved. My SonarQube's version is 6.5. Thanks!
Putting this into the answer section to attach a screenshot:
If you are confident enough that those two blocks of code have different roles, then you can change the reported severity level to Minor
or Info
from web-console. For example, see the screenshot below:
Sometimes Sonar reports as severe on things which are not really severe, but again depends on the project nature :)
However, like @Stephen mentioned on a comment above, if xxx
are same field and inheritance makes sense, then you can have parent abstract class to avoid the report.
这篇关于如何忽略 Sonar 中的重复代码报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何忽略 Sonar 中的重复代码报告?
基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01