Some Unity related inspections are disabled by default now?

I've just started my tiny side project in Unity 6 and noticed that Rider ignores null coalescing on some Unitys Object. Why are they disabled now? Did they fixed it somehow in Unity 6 and they're not relevant anymore? Or did this inspections just ended up disabled by some mysterious reason?

0
1 comment

The way we handle null comparisons in Unity changed a couple of versions ago, and we replaced these inspections with an informational highlight that shows you when you're actually checking for the lifetime of the native object, rather than shouting at you that you're possibly unintentionally not checking it.

Essentially, the inspections that are now disabled by default have a couple of problems. Firstly, we didn't cover all expressions, so there were some times when you used ?? and ?. and we didn't show any inspections (e.g. the return value of method calls). Secondly, C# has lots of ways of checking for null that don't use the equality operators, and we didn't cover them all, especially the several different kinds of pattens and nested patterns.

So we implemented this, and the inspections got a lot more noisy. Turns out most codebases have lots of places where there are (implicit) null checks and now Rider is shouting to you about something that doesn't always have a clear fix. Too many inspection highlights and the warning loses its value - it's just annoying and people ignore it.

But thirdly, and most importantly, we realised that these inspections are showing you warnings for normal C# behaviour, and that's confusing, especially for people new to Unity or C#. So we flipped things. Instead of complaining about normal C# behaviour, we now show an informational highlight (an inlay icon) next to == and != operators that are comparing Unity objects to null. We think this is a much better solution. We've swapped a warning (as though you've done something wrong) for an informational highlight (letting you know something extra/unexpected is happening). The idea is that you learn that these objects are special and get special behaviour for equality operations. If you don't see the icon, then you're not doing the lifetime check. If you want to do the lifetime check, you need to be explicit about comparing with null, and you'll get the icon.

So that left us the existing (fixed) inspections, plus some new ones for pattern matching. We could remove them completely, but we thought some people might prefer them, so we left them in, but disabled by default. So you can still get the warnings if you want to, but they can be very noisy, so it's up to you.

As for the “repeated access of a property on built in component is inefficient”, then unfortunately, that inspection just has too many edge cases. After repeatedly fixing some over several releases, we decided to cut our losses. We can't guarantee that this inspection is always correct, so we'll disable it by default.

0

Please sign in to leave a comment.