Search code examples
javacommentssonarqubetodo

How to handle TODO comments when sonar error is encountered


We have an application which is big and we have added the TODO rule to the quality gates which gives error if TODO comments are found. If we just removing the TODO comment (which is scary) it works but the whol purpose of adding TODO comment is lost. Is there still a way to keep the TODO comment by adding anything extra which way we can defer the TODO task ?(which is giant task for example) .


Solution

  • Remove the TODO, stop using them for anything that's not short term (for the length of a ticket or fork) and move them into tickets on your ticket tracking system.

    TODO comments have multiple problems:-

    • they can be hard to find if you are using an IDE which doesn't auto locate them. (I know Devs who use sublime or even Emacs so a specific search would be needed)

    • whose job is it to find and fix these?

    • how is time spend on them tracked?

    • they can get out of date, like most comments. If someone fixes the problem without reading the TODO and leaves it there, it causes confusion. If another fix inadvertently fixes it, the comment is unknowingly left there.

    • You now have two issue tracking systems, one of internal documentation and one in whatever issue tracking system you use.

    • If you are writing TODOs then you are the very person with the knowledge to fix it. Someone coming along later will have to fix it based on a very short comment without description.

    There's nothing more irritating than a piece of code by a developer who was too lazy to do a good job, so left it for the next guy

    enter image description here

    or one who wasn't lazy but was too scared to break something and just ended up making the problem more complex with minimal comments suggesting there's a problem

    enter image description here