False positive: using 'class' attribute in JSX without React

SonarCloud is raising an issue which I believe to be a false positive. When using the class attribute in JSX but without React, it is flagged as an unknown attribute by Sonar.

Basic info

  • CI: Jenkins
  • Language: TSX
  • Quality profile: Sonar way (built in)

The issue

We use the StencilJS framework. Our code is written as TSX. The React package is installed, but not used in this part of the code.

Stencil uses the normal class attribute, as opposed to className in React. Since a few days, however, our TSX code using class attributes is getting flagged by SonarCloud with the typescript:S6747 rule: Unknown property ‘class’ found, use ‘className’ instead.

In fact, using class here is correct, while using className would be incorrect and give a TypeScript error.

Example code

render() {
	return (
		<div class="my-class">Sonar doesn't like this</div>
	);
}

For now, I can work around this by marking the issues as false positive. It would be great if this problem could be fixed.

If you need any additional info, let me know.

2 Likes

Thanks @matsgottenbos for reporting, indeed it’s a FP.

Just created a ticket to better handle cases like this.

We’re having the same issue, our Sonarcloud analysis suddenly reported 161 code smell issues after the last PR merge :pensive:.



1 Like

Thanks @dgonzalezr,

we’ll try to prioritize this ticket for our next hardening. In the meantime, feel free to mark the issues as “won’t fix” or disable the rule in your quality profile.

Cheers,
Victor

This looks like a much larger issue than just the stencilJS. using @react-three/fiber and after the updates to Sonar Way quality gate on 2023/10/05 it has flagged a large amount of “invalid” jsx property usage. We have the types installed and they weren’t flagged as issues prior.

Thanks Scott,

thanks for the feedback, we’ll have this into account.

In the meantime, there is a workaround you all can use @dgonzalezr @matsgottenbos @Scott_Beck by whitelisting specific JSX attributes in the rule parameters:

Cheers,
Victor