Language : Java SonarQube version : Version 10.1 (build 73491)
Issue :
We have added the Lines metric in our Quality Gate to ensure that a Pull Request is flagged if it contains more than 500 Lines of code.
However, this should be configurable as it also ends up counting comments, lines in test and even readme files.
Is there no way to make this metric Language specific?
Say, we should be able to set a path and Sonar should only report Lines changed in that path?
This is a nice idea. Unfortunately, there’s no good way to implement it.
First, what you’re looking for is Lines of Code, rather than Lines. But Lines of Code isn’t available to Quality Gates.
Second, if you put a Lines / LOC limit on New Code in your Quality Gate, it would apply not just to your PRs, but also to your underlying project as well, meaning your development branch would fail the Quality Gate when it had accumulated 500 new Lines (of Code).
And, I think this is an intriguing idea, so I’m going to bring it to the Product Managers’ attention. But don’t expect movement on it any time soon.
It is fairly straightforward.
So as a developer, I will be writing feature code, corresponding tests and related comments/docs in the same PR.
However, I want to do gatekeeping only for the effective lines of code written in the PR.
If a PR has 10 lines of code and another 20 lines of tests + comments + docs, I should only be gatekeeping the actual lines of code (for java, src/main/java only).
Currently, all lines changed get counted and it prevents this gatekeeping.