Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trick sonar into ignoring commented code

Tags:

sonarqube

I was wondering if there is a way to trick sonar into neglecting commented out code while still keeping it inside. I would like to leave the snippet of code in there for modifications at a later date but would also like to increase compliance.

I have this for example // bdgItems.setGpIncrease(zero); and this is where i get compliance issuses. on the other hand regular comments like // get data points is no cause for issue. I'd like to keep the commented code in there to pick up where I left off in the next cycle of development, but like i said, reduce the issues. Ive tried a few ways in tricking it like // [DELETE THIS] bdgItems.setGpIncrease(zero); or // bdgItems . setGpIncrease ( zero ); with spaces in between words but it still knows! I was wondering if some of you vets knew any tricks [i'm fairly new to sonar].

Thanks in advance!

like image 819
erp Avatar asked Apr 13 '26 22:04

erp


2 Answers

It's not recommended, as Mithfindel already advised.

Simply replace dots and semi-colons with underscore.


Code sample: documentClient.deleteDatabase("dbs/" + DATABASE_ID, null);

The resulting comment without the warning would be: // documentClient_deleteDatabase("dbs/" + DATABASE_ID, null)_

like image 179
Rasshu Avatar answered Apr 18 '26 14:04

Rasshu


This is a typical technical debt management issue.

If you "leave it there for later", then you are indeed adding technical debt into your source code, that you intend on repaying later. So SonarQube flagging this commented out code as issues is intended behavior.

You still have the option to flag those issues as false positives, but I do believe you should keep them as true issues, if only to remind yourself of coming back to fix them.

like image 32
Mithfindel Avatar answered Apr 18 '26 16:04

Mithfindel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!