Configure the Lines metric in Quality Gate

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?


Welcome to the community!

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.