bdovaz
bdovaz

Reputation: 111

SonarQube using it with Unity 3D tons of problems

I'm trying to setup Sonar on our organization that we mostly make Unity projects.

Our problem is that the rules provided to C# language are not always the same in Unity context.

  1. In Unity there is a MonoBehaviour class that if you declare some methods (Awake, Start) they are being called by reflection:

https://docs.unity3d.com/ScriptReference/MonoBehaviour.html

So in this case I have tons of "Remove this unused private member".

Is there a way to tell, don't apply that rule if my class derives from MonoBehaviour (or AssetPostprocessor, etc...) and my method name is for example "Awake"? I mean, is there a way to set a custom rule and invalidate other one?

  1. The same applies to Unity serialization system. You can have a private field with [SerializeField] attribute and it gets automatically initialized by Unity:

https://docs.unity3d.com/ScriptReference/SerializeField.html

In this case I get tons of "Make "{FIELD}" "readonly"" if my field has a default value because it's Unity then who "fills" that value updated/changed from inspector but if I make it readonly it won't work in Unity's serialization system.

Thanks.

Upvotes: 3

Views: 2486

Answers (1)

Tamas
Tamas

Reputation: 6420

Thank you for reporting these issues. We haven't tested Unity projects with SonarQube, but it's on our radar as the community and the Unity based code base is huge.

At this point I can't suggest any other workaround for your first problem (convention based reflection) but to disable that rule. I created a JIRA ticket to investigate the options: https://jira.sonarsource.com/browse/SLVS-1104

And here is the ticket for the readonly field problem. That's definitely something that can be easily fixed. It will be part of the next release: https://jira.sonarsource.com/browse/SLVS-1105

Upvotes: 4

Related Questions