Sonarqube is taking formatted code as new code and messing up code coverage. How to prevent?

  • which versions are you using - 6.7.5 Community version
  • what are you trying to achieve - Code coverage on new code
  • what have you tried so far to achieve this

Ours is a legacy project where our business unit has decided to have a strict check on new code coverage to be at a minimum of 80%. The code is in Java and we are using JaCoCo to calculate code coverage.

The only problem is that formatted code is being taken as new code and messing up the new code coverage.

Is there any way we can ignore code formatting changes as new code changes for Sonar?

Any help on this is truly appreciated.

Hi,

Welcome to the community!

“New” code is recognized based on SCM blame data. If you’re checking in changes to the files, then those updated lines are going to be seen as new even though the changes were just whitespace.

Sorry, but I can only recommend that you limit your format updates to the code that’s actually being touched anyway.

 
:woman_shrugging:
Ann

Hi There :slight_smile:

Is there any update on this?
Or are there plans to offer such rules, to exclude whitespace changes from “new line” detection?

Hi @Johannes_Paul,

This is a question to direct to the maintenance team of your SCM provider. As I said 2 years ago, we just go by what they tell us.

 
:woman_shrugging:
Ann