☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

if...else-if 分枝数量应在规定范围之内

9.1.13 ID_if_tooManyElseIf
目录 › next › previous

if...else-if 分枝过多不利于阅读和维护,而且执行时需逐一判断各分枝的条件,效率较低,建议改为遵循某种算法的索引结构。

示例:

if (rabbit) {
}
else if (hamster) {
}
// ... 3000 branches ...
// Computers have the courage to execute,
// but do you have the courage to read?
else {
}

建议 if...else-if 分枝数量不超过 5 个。

配置

maxElseIfCount: 分枝数量上限,超过则报出

相关

ID_switch_tooManyCases

参考

CWE-1121
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.