Does sonarqube analyze for unused code?

Hi, I have configured sonarqube server and analyzed my .net project. I have some piece of code which doesn’t have any reference (unused code) but I couldn’t see those as Code smell or Bug or Vulnerable.
Does sonarCube performs checks for unused code? or I missed some configuration?

Any help would be appreciated.

depending on the analyzer plugins you’ve installed in your Sonarqube instance you should see a lot of rules for Unused code, Dead stores … etc. see https://yoursonarhost/coding_rules?q=Unused

I’m using Csharp plugin . But I’m pretty much sure that sonarqube does the check for unused code.The above link you shared is not accessible for me.

of course you need to adjust the URL for your instance. Replace yoursonarhost with the name of your instance or instance:port if you don’t use port 80.

Ah Apologies, I wasn’t look into the above URL i though it was kind of global domain . Let me try once .

Also check whether those unused code related rules are activated in your Quality Profile and the exclusion settings.

Couldnt find exclusion settings in my portal

yes I got the exclusion setting but here it seems empty.

if you use the filter for C# analyzer = https://yoursonarhost/coding_rules?languages=cs&q=Unused
my instance with the latest C# analyzer 7.9 (build 7583) installed shows 6 rules.
All of them are included in the default Quality Profile “Sonar way” that ships with the C# analyzer.

Same for me . Its 6

OK, maybe you need to adjust the file suffix , see https://yoursonarhost/admin/settings?category=c%23 !?
The default setting is .cs
If you didn’t set a specific Quality Profile, the C# Sonar Way will be used.
And if your exclusion setting is empty - means no files excluded - there should be issues if unused code is detected, see rule description for examples and do a small test with those snippets.

1 Like

Again its correct… set as .cs :sweat: :sweat: