Test local changes before you make a PR

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • My question is, if I am working on a local fix, and am not sure if that fix will work or not, to say, exclude some files from being analyzed, is there a way for Sonar Cloud to scan those changes that I made locally prior to making a PR?

Hi @AnnL ,

Yes, there is way to scan your changes locally using SonarLint! You can then bind or create a connection to your SonarCloud account/organization and then sync those changes with SonarLint. Download the extension for your IDE (as shown in the link above) and follow the instructions for your IDE.

Here are additional links for your reference:

We are working on updating and combining our SonarLint docs, so that’s why the instructions are spread out.

Please note the limitations as explained in Frequently asked questions about SonarLint.

Hi Joe,

Thank you for getting back to me. Unfortunately that doesn’t solve my issue. Firstly, our pipes are not a VS item (nor the other ones you mentioned), but moreover, the code I am looking to scan is not a question of syntactical correctness, but rather to understand whether my sonar.exclusions are working properly.

Essentially, what I would like to be able to do is, check whether my coverage percentage will increase prior to making a PR (by excluding a set of files).

How could one best accomplish that?

Thank you,
Ann

Hi @AnnL ,

In both of these cases, you should download the Sonar scanner and scan it against your own instance of SonarQube (or private SonarQube projects if you have a global SonarQube instance).

For confirming if your sonar.exclusions are working, this depends on what settings may exist at various levels of scanning: directly at CI/build/local level (within sonar-project.properties or at the command invocation of sonar-scanner), at Project level in the SonarQube UI (you can put project settings for sonar.exclusions here), or at global level (in Administration menu).

For checking whether your coverage percentage will increase prior to making a PR, you should use branch analysis (using sonar.branch.name parameter) and scanning your branch there, then when you are ready, you can make a PR.

By the way, if you want to exclude files from coverage, you should use sonar.coverage.exclusions, not sonar.exclusions.