Sonar is considering 2 files with same name but at different path same files

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension) 9.9.1-community, scanner version 4.7.0.2747
  • how is SonarQube deployed: Helm
  • what are you trying to achieve Sonar should files at different locations 2 different files.
  • what have you tried so far to achieve this Tried looking for the way sonar indexes the files but couldn’t help.
Webapp:
src/features/Search/pages/ListPage                         |     100 |      100 |     100 |     100 |                                                                                                                                                                                                                                                      
  ListPage.tsx                                              |     100 |      100 |     100 |     100 |                                                                                                                                                                   

Chrome Extension: 
src/features/Search/pages/ListPage                                |     100 |      100 |     100 |     100 |                                                                                                                                                                                             
  ListPage.tsx                                                     |     100 |      100 |     100 |     100 |    

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hey there.

How do you know that Sonar is considering 2 files with same name but at different paths the same file? What leads you to believe that is true?

We are using jest to run the tests and generate the coverage report, jest shows full coverage for both the files but sonar is showing full coverage for only one. If you look at the jest logs from the original question and here is the sonar analysis output, I can confirm that both the files have different content as well.


y

1 Like

I can confirm Nirav’s experience. I have a project with multiple files with the same name at different directories and when the manually calculated coverage of all three files is averaged it matches the value assigned to the first file while the other two are marked at 0% coverage. Is there a known work around fro this behavior or is this unintended behavior?

@GTrac

That’s a very interesting observation (the averaging of the three files). I think I understood the issue @Nirav_Katarmal reported better based on that information. I will work on reproducing it, probably this next week!

Hey @GTrac

So far, I can’t reproduce the behavior you’re describing.

You can check out my sample app here, with two files named calculator.js in different directories. One has 100% coverage (expected) and the other 80% (also expected). You can see the results on SonarQube Cloud.

----------------|---------|----------|---------|---------|-------------------
File            | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------------|---------|----------|---------|---------|-------------------
All files       |      90 |      100 |      75 |      90 |                   
 app            |     100 |      100 |     100 |     100 |                   
  calculator.js |     100 |      100 |     100 |     100 |                   
 app2           |      80 |      100 |      50 |      80 |                   
  calculator.js |      80 |      100 |      50 |      80 | 2                 
----------------|---------|----------|---------|---------|-------------------

As far as I can tell, no averaging out here.

Do you see the same results against this repo? If so, I think it’s important you find a minimal reproducer so that we see the same results (and can figure out if there’s a problem to solve).