鱿鱼:Android 上的最大继承深度

2022-01-17 00:00:00 sonarqube java

这是我的设置:

  • SonarQube 5.6.6
  • SonarJava 插件 4.8.0.9441

代码:

public class BaseActivity extends android.app.Activity {}

public class FooActivity extends BaseActivity {}

SonarQube 认为 FooActivity 违反 squid:MaximumInheritanceDepth:

SonarQube thinks that FooActivity violates squid:MaximumInheritanceDepth:

这个班级有 6 个家长,超过 5 个授权.

This class has 6 parents which is greater than 5 authorized.

android.app.Activity 是 Android 原生 API.Activity 的任何超类在计算违反此规则时是否应该被忽略?

android.app.Activity is Android Native API. Shouldn't any super classes of Activity be ignored when calculating violations for this rule?

这是一个错误吗?

推荐答案

这不是bug,而是配置问题.规则 squid:S110 可以配置为过滤掉类从继承树.默认情况下,不会忽略任何类,规则只是计算继承级别的数量,直到达到 Object 类.为了配置过滤类,您必须设置 filteredClasses 规则属性.

This is not a bug, but rather a configuration issue. Rule squid:S110 can be configured to filter out classes from the inheritance tree. By default, no class is ignored and the rule simply count the number of inheritance levels till reaching Object class. In order to configure filtered classes, you have to set up the filteredClasses rule property.

请注意,计划更新规则以不简单地从总继承深度中排除过滤类,而是在达到过滤类后立即停止增加继承级别.该修复将在处理 Jira 票证 SONARJAVA-2252 时完成.

Note that it is plan to update to rule to not simply exclude filtered classes from the total inheritance depth, but stop incrementing inheritance levels as soon as reaching a filtered class. The fix will be done when handling Jira ticket SONARJAVA-2252.

相关文章