Skip sonar code analysis if changed lines in PR is less than 10 lines

In a PR, I have just one line changed in non-test code. But sonarcode analysis is failing due to coverage less than 80%.

I am using Sonar Cloud in a maven based project containing both Java and Scala Code. I am using the default quality gate in my private projects.

Is there a way for me make sonar code analysis always pass if changed lines in a PR in non test code is less than 10 or 20?

Hey there.

In fact, that should be the default behavior! See the docs here.

Is it possible you have more than 20 New Lines in the PR, even if you only have 1 line to cover? You should see this info in the Size section of the same Measures page you shared a screenshot of.

I have only 1 line in actual main code and a test class code which is more than 20 lines. I am using the default quality gate.

My main code is under src/main and test code is under src/test.

But sonar analysis is showing failure.

How about this point?

I have total 75 lines of code in PR. One line in actual main code and 74 lines in test. The sonar configuration I have shared above.

If I just have under 20 lines in PR including both main and test code. It works. What I am looking for is only in main / non test code if I have less than 20 lines it should pass irrespective of how many lines are there in the test code. Is it possible?

Is this supported? If not can I raise a feature request for the same?

I see what you’re saying now. And unfortunately 7 years ago we also recognized that it would be better to use “Lines to cover” as the 20 line threshold. SONAR-11283

And the ticket was recently closed. :frowning:

I’m digging into it on my end, because the ticket makes a lot of sense.