PR check the whole file and not just changed code in Azure DevOps

Would appreciate assistance on how to configure SonarCloud pull request to only look at code that we have changed and not analyse the whole file.

For example, code that was not changed in the PR gets flagged like this:

I have followed the SonarCloud Labs for Azure Devops to configure the PR;s but nowhere could I find where I could change these settings. Then I checked the documentation available and also could not find any additional information that would help to specify that it only checks changed code.

Details about our SonarCloud project:

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
  • CI system used Azure DevOps
  • Languages of the repository are SQL, C# and JavaScript
  • Our SonarCloud project is private so unfortunately can’t share the URL

Thank you in advance.

Hi @Carike and welcome to the community !

Has this issue already been reported on the target branch of your PR ? Or at least the default branch of the repo ?

Hi @mickaelcaro

Thank you very much for the welcome :slight_smile:

The issue currently reported, is on a new feature branch and I can’t find that it has been flagged on our default branch either.

We have had SonarCloud implemented on our code base about two years, but only recently started with the PR decorations and it’s flagging lot of code.

So, of course, these need to be resolved but currently, we just want to check the code that changed in the PR. From the screenshot, you can see that that line of code was unchanged. A colleague mentioned that he read somewhere that it should just check the new code and wondering if we can configure it somewhere.

Thanks again for the assistance!

If there have been some file move or renaming, those issues might be raised if they have not been before, so if you didn’t find this issue on any branch, i think that this is the normal behavior then.

@mickaelcaro we have not moved or renamed the files, and in this example that commented line has been there for a while. So we are wondering why it is now being flagged since it’s not new.

On this one PR we have found more than 50 issues flagged, that is not related to the code changes made. Therefore feel that they are incorrectly being flagged during the PR. It’s also not just this branch but many others as well.

Is there a way we could perhaps configure the “sensitivity” of how the items get flagged?

Thanks again!

Is the target branch of your PR the default branch of your repo ? Or a feature branch that may be not rebased since a long time ?

No in this instance the target branch was a feature branch that was recent created from the Master-branch.

We are nearing the LOC count of our plan and I am wondering if that might not be also causing the issue since it can’t complete the analysis of the other branches.

@mickaelcaro I am going to do a bit more digging on our SonarCloud setup and will then perhaps ask for your guidance again, but thank you for your assistance so far.

1 Like