配置自定义质量门,默认 SonarQube 方式已作为初始参考并进一步调整和自定义(添加进一步检查)。我们当前的质量门如下(旧版本与当前版本):
Blocker issues: error threshold at 0
Complexity/class: error threshold at 12
Complexity/file: error threshold at 12
Complexity/function error threshold at 2
Coverage error threshold at 100 >> changed to 65
Critical issues error threshold at 0
Duplicated lines (%) error threshold at 5
Info issues error threshold at 10
Major issues error threshold at 50
Minor issues error threshold at 100
Overall coverage error threshold at 100 >> changed to 65
Public documented API (%) error threshold at 50
Skipped Unit tests error threshold at 0
Technical Debts error threshold at 10d >> change to (?? < 10)
Unit test errors error threshold at 0
Unit test failures error threshold at 0
要点是关于技术债务日,鉴于其他检查已放宽(复杂性和覆盖范围),应将其从 10 强制执行到更小的值。这确实是合理的:放宽一些规则,您应该有更多的受控技术债务保证金,因此可以缩短非受控技术债务累积天数的门槛。
然而,整体质量门应该以某种方式(数学上?)遵循一定的比例。
问题:鉴于上述放宽,如何计算最合适的技术债务门槛?
从一篇旧文章(2009 年,因此很可能不再适用)中扣除了以下公式:
TechDebt = (cost_to_fix_one_block * duplicated_blocks) + \
(cost_to fix_one_violation * mandatory_violations) + \
(cost_to_comment_one_API * public_undocumented_api) + \
(cost_to_cover_one_of_complexity * uncovered_complexity_by_tests) + \
(cost_to_split_a_method * function_complexity_distribution) + \
(cost_to_split_a_class * class_complexity_distribution)
注意:\
添加是为了便于阅读。
但是,有太多未知变量无法进行正确计算,但它并没有涵盖上述所有质量门项目(再次,它是一个旧参考)。
其他更近期的消息来源详细解释了相关项目,但没有说明如何按比例调整值。
( Admin / Configuration / Technical Debt ) 的默认值为30sonar.technicalDebt.developmentCost
分钟,这意味着 1 LOC (开发 1 行代码的成本)= 30,但仍然不是上述变量的粒度级别,在这种情况下也没有用处。