Hi all, we are seeing a lot of false positives when we have code like this:
val foo = something ?: error("Some error")
val bar = somethingElse ?: error("Some other error")
We are using both foo and bar on the next line, but Sonar gets confused and reports a “Unused local variables should be removed”.
I understand that handling that error([...]) must not be trivial, and I don’t want to disable the check because is very useful in a lot of other places in the codebase, but these examples are definitely false positives.
I looked into the issue you describe and could unfortunately not reproduce it. We did have a couple of false positives with this rule in the past, when projects were not ideally configured (see this ticket), however this should be fixed in current versions of all products.
Can you please confirm whether or not you are running SonarLint in connected mode? If you are running it in connected mode, is it connected to a SonarQube server or SonarCloud? If it is SonarQube, which version?