Reactjs React JSX布尔条件导致声纳认知复杂性
由于函数的认知复杂性,我认为这可能是一个错误。我在大多数jsx中使用react{boolean&&语法,在扫描sonarqube之后,它显示了认知复杂性。是否有其他更好的方法来编写它,以便修复sonarqube问题。下面是我的示例语法Reactjs React JSX布尔条件导致声纳认知复杂性,reactjs,sonarqube,Reactjs,Sonarqube,由于函数的认知复杂性,我认为这可能是一个错误。我在大多数jsx中使用react{boolean&&语法,在扫描sonarqube之后,它显示了认知复杂性。是否有其他更好的方法来编写它,以便修复sonarqube问题。下面是我的示例语法 {loadStatus === 'success' && (<customtag> Sampletext </customtag>)} {loadStatus === 'error' && (<cu
{loadStatus === 'success' && (<customtag> Sampletext </customtag>)}
{loadStatus === 'error' && (<customtag2> Sampletext </customtag2>)}
{loadStatus === 'loading' && (<customtag3> Sampletext </customtag3>)}
{projStatus === 'success' && (<projcustomtag> Sampletext </projcustomtag>)}
{someOtherStatus === 'fetching' && (<somecustomtag> Sampletext </somecustomtag>)}
{loadStatus=='success'&&(Sampletext)}
{loadStatus=='error'&&(Sampletext)}
{loadStatus=='loading'&&(Sampletext)}
{projStatus=='success'&&(Sampletext)}
{someOtherStatus=='fetching'&&(Sampletext)}
我在一页中使用了上述语法(超过15次),这给了我一个问题。每个AND操作都被认为是+1复杂性。有没有办法,我可以修改语法以避免sonar错误。我认为最好是“如果”需要输入函数 但您在jsx中使用最多的是:
{loadStatus === 'success' ? 'this is ok' : null}
{loadStatus === 'error' ? 'you have error' : null}
{loadStatus === 'loading' ? 'loading' : null}
{loadStatus=='success'?这可以:null}
这是我今天在这方面看到的第四个或第五个问题,我想知道最近有什么更新触发了这一问题?我没有看到任何明显的方法来简化代码或降低复杂性(老实说,这并不难理解/推理)。每一行都是不同的、独特的。
{loadStatus === 'success' ? <div> this is ok </div> : null}