From db55cf762ea03f96108833d7954531d6793bf352 Mon Sep 17 00:00:00 2001 From: Luiz Bezerra Date: Wed, 9 Oct 2024 13:45:51 +0100 Subject: [PATCH] added a preblematic component to test sonar failures Signed-off-by: Luiz Bezerra --- .../ProblematicComponent.tsx | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 packages/suite-base/src/components/ProblematicComponent/ProblematicComponent.tsx diff --git a/packages/suite-base/src/components/ProblematicComponent/ProblematicComponent.tsx b/packages/suite-base/src/components/ProblematicComponent/ProblematicComponent.tsx new file mode 100644 index 0000000000..58cd786b0f --- /dev/null +++ b/packages/suite-base/src/components/ProblematicComponent/ProblematicComponent.tsx @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// SPDX-License-Identifier: MPL-2.0 + +import React, { useState, useEffect } from 'react'; + +type Props = { + userName: string; +}; + +const ProblematicComponent: React.FC = ({ userName }) => { + const [count, setCount] = useState(0); + const [data, setData] = useState(null); + + // Problema de complexidade - lógica de ramificação excessiva + const handleClick = () => { + if (count === 0) { + setCount(count + 1); + } else if (count > 0 && count < 5) { + setCount(count + 2); + } else if (count >= 5 && count < 10) { + setCount(count + 3); + } else { + setCount(0); + } + }; + + // Uso de "any", falta de tratamento de erro + useEffect(() => { + fetch('/api/data') + .then(async (response) => await response.json()) + .then((result: any) => { + setData(result); + }) + .catch((error) => { + console.log('Erro:', error); // Código que não lida adequadamente com o erro + }); + }, []); + + return ( +
+

Hello, {userName}

+

Counter: {count}

+ + {/* Renderização condicional sem verificação adequada */} + {data ?
{data.name}
:

Loading...

} +
+ ); +}; + +export default ProblematicComponent;