模块化javascript代码SONAR重复块



我有下面的代码块,SONAR将其识别为重复。有人能告诉我如何改正吗。

import fields from '../../utils/utils';
dispatch(
fields.change([
{
id: 'userData',
value: customer.eduSavings === null || customer.eduSavings.total === null ? ''
: customer.edusavings.toString()
},
{
id: 'emoloyeeData',
value: customer.workSavings === null || customer.workSavings.total === null ? ''
: customer.workSavings.toString()
}
])
)

Sonar表示,对value字段应用的null检查和toString((是重复的。如何循环使用fields.change并将其应用于相应的id。

我相信customer.workSavings是一个对象,而customer.workSavings.totalcustomer.workSavings.total的一个属性?如果这是真的,那么在customer.workSavings为空的情况下,当然customer.workSavings.total也为空,SONAR检测到您检查了相同的逻辑并显示了重复。

import fields from '../../utils/utils';
dispatch(
fields.change([
{
id: 'userData',
value: customer.eduSavings === null ? 
: customer.edusavings.toString()
},
{
id: 'emoloyeeData',
value: customer.workSavings === null ? 
: customer.workSavings.toString()
}
])
)

如果customer.workSavings已经为空,则无需检查customer.workSavings.total是否为空

当SonarQube报告重复时,表示有问题的块与同一文件或另一文件中的块完全重复。关于这个区块的逻辑的问题和答案是无关紧要的。

通常,左边距将显示一条垂直的蓝色线,指示该块是另一个块的副本。如果你点击垂直的蓝线,它会告诉你另一个复制块在哪里

最新更新