We’re in the process of setting up Sonarcloud and we’d like to enforce that too many code comments aren’t added to new code as some engineers insist upon adding a comment to every line of code, including import lines.
It has been discussed with them, however, with them being an outsourced team they’re choosing to ignore the requests to not do that and so one option would be to enforce it as part of a quality gate in the CI/CD process.
Ideally, there should be fewer code comment lines than code lines added in a new Pull Request, however, the only quality gate/rules I can find only allow me to fail a quality gate check if the number of comment lines is too low or less than a certain percentage and not if it’s greater.
You’re right. This was a conscious choice on our end because Quality Gates are, unfortunately, pretty easy to misconfigure (even I get confused by whether I’m setting a gate that requires a certain comment line density or fails at that density), so we tried to make it user-proof.
You’re the first user in our memory to want developers to add fewer comments!
Since what you’re asking isn’t possible, I’ve moved your post to our PM for a Day category where users with similar use-cases might chime in.
Thanks for the response. I’ll look at an alternate check to implement what I need for now then.
The idea on our side is we promote writing clean code that is its own documentation versus having code comment lines for (quite literally) every line of code that gets added or is in the same file as changes, in each Pull Request.
Being able to specify that up to say 10% or 15% of a set of changes in a Pull Request can be comment lines, would be very useful. That ensures they focus on adding comments where it’s needed most and not for basic things like an import statement at the top of a Python file.