Sonar can't even detect a variable that was used inside a function

False-positives happen.

This smells a bit like an issue that was reported in the past:

You can see in that thread there’s an open ticket – in the meantime, can you make sure your project is built?