我有下面的代码块,声纳识别它是重复的。有没有人能告诉我怎么纠正这个问题。
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并将其应用于相应的ids。
发布于 2020-10-22 21:04:11
我相信customer.workSavings
是一个对象,customer.workSavings.total
是customer.workSavings.total
的一个属性。如果这是真的,那么在customer.workSavings
为空的情况下,当然customer.workSavings.total
也为空,声纳检测到您检查了相同的逻辑,并显示了重复的逻辑。
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
已经为null,则无需检查customer.workSavings.total
是否为null
发布于 2020-10-22 23:02:45
当SonarQube报告重复数据块时,它表示相关数据块与同一文件或另一个文件中的数据块完全相同。关于这个块的逻辑的问答是不相关的。
通常,左边距将显示一条垂直的蓝色线条,指示该块是另一个块的副本。如果您单击垂直蓝色线,它将告诉您另一个复制的块在哪里。
https://stackoverflow.com/questions/64490212
复制相似问题