-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a preblematic component to test sonar failures
Signed-off-by: Luiz Bezerra <[email protected]>
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/suite-base/src/components/ProblematicComponent/ProblematicComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]> | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
|
||
type Props = { | ||
userName: string; | ||
}; | ||
|
||
const ProblematicComponent: React.FC<Props> = ({ userName }) => { | ||
const [count, setCount] = useState<number>(0); | ||
const [data, setData] = useState<any>(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 ( | ||
<div> | ||
<h1>Hello, {userName}</h1> | ||
<p>Counter: {count}</p> | ||
<button onClick={handleClick}>Increment</button> | ||
{/* Renderização condicional sem verificação adequada */} | ||
{data ? <div>{data.name}</div> : <p>Loading...</p>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProblematicComponent; |