SonarLint Connected Mode VSCode New Code Definitions

Please provide

  • Operating system: Windows 10 Enterprise
  • SonarLint plugin version: v4.12.0
  • Programming language you’re coding in: Apex
  • Is connected mode used: yes
    • Connected to SonarCloud or SonarQube (and which version): SonarQube Data Center Edition - v9.9.6 (build 92038)

And a thorough description of the problem / question:

We want to use SonarLint focus: new code. In our project the developer create their feature branches from int and merge them to int. Therefore, the new code strategy of reference branch would be optimal, which is currently not supported for SonarLint.
Hence, we have decided to define new code with the number of days setting. Our development sprints take 14 days, thus we have defined 14 days as the NCD on the SonarQube project level.

It seems that SonarLint is not taking the project level NCD but the branch specific setting for main. It worked if NCD of main branch was 14 days, but now it is set to previous version. In the documentation it was written that branch specific settings are not supported, so I thought it would be ok to define it just for the sonar cli scanner used in our pipelines.

Configuration:

sonar-project.properties file at root of our repository and connected mode with new code focus:

How can we achieve that SonarLint is defining new code based on 14 days time period?

Thank you in advance for providing some clarification on how SonarLint defines new code.

Kind regards,
Leo

I figured out why it probably doesn’t work as wanted:

When I don’t define any branch specific NCD, SonarLint correctly takes the 14 Days defined at project level.

Is there a way to overwrite the NCD with a sonar scanner parameter to use project version instead of 14 days?
For lower environments I could use -Dsonar.newCode.referenceBranch to overwrite the project definition. I don’t see a parameter that does the similar for project version (e.g. -Dsonar.newCode.projectVersion).

Hello @xL3o,

Your analysis is correct:

  • The “Reference branch” New Code Definition is not supported in SonarLint SonarQube for IDE
  • SQ-IDE relies only on the New Code Definition set at the project level

There is a relatively old ticket on our side to support branch-level NCD. I will discuss internally how to prioritize it.

Unfortunately, scanner parameters are ignored in SonarQube for IDE.

The only workaround I can suggest for now is to choose a NCD, define it at the project level, and remove overrides at the branch level.