Skip to content

Commit

Permalink
added a preblematic component to test sonar failures
Browse files Browse the repository at this point in the history
Signed-off-by: Luiz Bezerra <[email protected]>
  • Loading branch information
luluiz committed Oct 9, 2024
1 parent c413af7 commit db55cf7
Showing 1 changed file with 50 additions and 0 deletions.
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';

Check failure on line 4 in packages/suite-base/src/components/ProblematicComponent/ProblematicComponent.tsx

View workflow job for this annotation

GitHub Actions / lint (ubuntu-20.04)

Replace `'react'` with `"react"`

type Props = {
userName: string;
};

const ProblematicComponent: React.FC<Props> = ({ userName }) => {
const [count, setCount] = useState<number>(0);
const [data, setData] = useState<any>(null);

Check failure on line 12 in packages/suite-base/src/components/ProblematicComponent/ProblematicComponent.tsx

View workflow job for this annotation

GitHub Actions / lint (ubuntu-20.04)

Unexpected any. Specify a different type

// 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;

0 comments on commit db55cf7

Please sign in to comment.