After analyzing my code with SonarLint, I get the following smell code: "Local variables should not be declared and then immediately returned or thrown".
Even if this is not blocking and the component works perfectly.
I think there is a better way to post the return in the function but I don't see how, if anyone knows the trick.
here is my component :
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;
CodePudding user response:
just for code brief, change the first line from
const columnsEventModal= Column[] = [...]
return columnsEventModal;
to the line
return [...]
because you dont do anything in between insertion and return statement, Sonar doesnt understand why you would allocate a variable