【发布时间】:2022-01-18 16:53:16
【问题描述】:
使用 SonarLint 分析我的代码后,我得到以下异味代码:“不应声明局部变量然后立即返回或抛出”。
即使这没有阻塞并且组件运行良好。
我认为有更好的方法可以在函数中发布 return,但我不知道如何,如果有人知道诀窍的话。
这是我的组件:
const ColumnModalEvent = (currency: any) => {
const columnsEventModal: Column[] = [
{
Header: () => <I18nWrapper translateKey="movement.type.fieldName" />,
accessor: 'type',
disableSortBy: true,
Cell: ({ value }) => (
<I18nWrapper translateKey={value} prefix="movement.type" />
),
},
{
Header: () => (
<I18nWrapper translateKey="movement.uniqueReference.fieldNameShort" />
),
accessor: 'uniqueRef',
},
{
Header: () => <I18nWrapper translateKey="movement.documentDate" />,
accessor: 'createdDate',
className: 'text-end',
headerClassName: 'text-end',
Cell: ({ value }) => <DateFormater dateToFomat={value} />,
},
];
return columnsEventModal;
};
export default ColumnModalEvent;
【问题讨论】:
标签: reactjs sonarqube sonarlint