Does sonarqube analyze for unused code?

sonarqube

(Joy Basak) #1

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.


(Gilbert Rebhan) #2

Hi,
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
Regards,
Gilbert


(Joy Basak) #3

HI,
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.
Thanks.


(Gilbert Rebhan) #4

Hi,
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.
Regards,
Gilbert


(Joy Basak) #5

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


(Gilbert Rebhan) #6

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


(Joy Basak) #7

Couldnt find exclusion settings in my portal


(Joy Basak) #8

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


(Gilbert Rebhan) #9

Hi,
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.
Gilbert


(Joy Basak) #10

Same for me . Its 6


(Gilbert Rebhan) #11

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.
Gilbert


(Joy Basak) #12

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