New Code line offset in HTML files during SonarCloud analysis

Hello Team,

We are observing an issue with SonarCloud New Code detection for an updated HTML file, where the lines highlighted as New Code do not align with the actual changes made in the source file.

CI system used

Local execution using sonar-scanner

Scanner command used

sonar-scanner

analysis_redacted_1.txt (1.4 KB)

Languages of the repository

HTML

SonarCloud project URL

Not public

github diff for p.r branch :

Pull Request URL

Error observed

We added the following content to an existing HTML file:

<section class="card">
    <h2>Ho__c</h2>
    <p>Full CRUD permissions.</p>
</section>

This block was added between lines 77–80 in the source file (as shown in the editor and GitHub diff).

After running a SonarCloud analysis, the New Code section in the SonarCloud UI highlights lines 78–81 instead.

As a result:

One newly added line (line 77) is not marked as New Code

One unchanged line (line 81) is incorrectly marked as New Code

This suggests a one-line offset between the SCM diff and SonarCloud’s New Code calculation.

Steps to reproduce :

Added html to github repo.

Ensure SCM is enabled and accessible from the terminal.

Run sonar-scanner analysis on the main branch to sonarcloud.

Create a pull request branch in github with above change.

sync with github in local repo ( terminal ).

Run sonar-scanner on the pull request branch.

Compare the GitHub diff with the New Code highlighted in SonarCloud.

Potential workaround

No workaround identified so far.
The issue currently blocks accurate New Code identification.

Questions / request for clarification

Is this New Code line shift expected behavior in SonarCloud?

Does SonarCloud normalize line endings, whitespace, or HTML content in a way that could affect line numbering?

If this behavior is not expected, is it a known issue or are there recommended steps to resolve it?

Environment details

Sonar Edition: SonarCloud

Scanner: SonarScanner

File type: .html

Lines involved:

Source editor / GitHub diff: 77–80

SonarCloud New Code: 78–81

Hi,

The answer is going to be the same as in your other thread

Make sure the prerequisites are fully in place.

If you want to try to go further with this, please add -Dsonar.verbose=true to your analysis command line and post the full analysis log, redacted only as necessary. The one you’ve posted here is… not useful.

 
Ann

I have attached verbose logs :

sonar_masked.log (59.4 KB)

My sonar properties file :

sonar.organization=dhanushterala1509

sonar.projectKey=dhanushterala1509_testhtml

sonar.host.url=https://sonarcloud.io

sonar.token=xxxxxx

sonar.pullrequest.key=5

sonar.pullrequest.branch=dhanushterala1509-patch-7

sonar.pullrequest.base=main

sonar.verbose=true

Hi,

Thanks for the logs and properties. I didn’t bring this up earlier because you resolved the problem, but I do see this:

12:48:30.483 INFO: SonarScanner 4.8.0.2856

The current version of SonarScanner CLI is 8.0.1.

It’s probably not the problem, but there’s a lot of ground between your version and the current version, so let’s start by upgrading that to eliminate the variable.

For that matter, you’re on Git 2.46

12:48:41.859 DEBUG: git --version returned: git version 2.46.0

When the current version is 2.52. Can you upgrade that as well?

I also see this:

Of course that lines up with your configuration:

Since this is at root about your SCM data, can you help me understand why no CI vendor is detected and you don’t rely on the automatic configuration of those PR parameters?

And once you’ve done those upgrades, can you run analysis again to see if that fixes the problem?

 
Thx,
Ann

I’m just relying on local sonar-scanner and analysis is succesfull. I that’s should n’t be an issue with CI vendor. we manually configured and It is working fine. Issue is with New Code detection.

I just updated the git version and sonar-scanner version and re-ran the analysis.

sonar_masked_1.log (61.5 KB)

Hi,

I take it this analysis exhibited the same problem?

I’d rather not dismiss this so cavalierly. Can you share why you need to configure the PR parameters manually? What CI are you using?

 
Ann