React Functional Component being picked up as a function

Hi all,

Just asking for any insight if anyone has experienced similar issues.
SonarCloud is picking up a React Functional Component as a standard function when running checks on a pull request on GitHub.
This means that it is bringing it up as a code smell that it is longer than 15 lines allowed for functions.

In the “Why is this an issue?” tab it specifies that React Functional Components will be excluded, but it is including them.

Any help will be greatly appreciated.

Hi @berndgevers,

thanks for reporting this. We may need to have a look at your component code. My first guess is that the React components detection may not be properly detecting all cases. Can you share with me via private message? Or reduce it to a bare minimum which still raises the false positive?


Hi Victor, sorry for taking so long to respond.
I masked a lot of the file, but tried to keep the structure of the file the same, hope this helps.

(PS, please excuse the clutteredness and size of the file, that’s what were busy cleaning up)

sample.txt (5.2 KB)

Thanks for the code @berndgevers ,

indeed there are some cases we should add to the component detection. I created a ticket to handle this.

Just a heads up: in the code you sent me there are still some functions (which do not return any JSX) which would still raise an issue for that rule if your threshold is set to 15 lines. Just a heads up in case you were expecting no issues at all.


1 Like