SonarQube Server Developer Edition v2025.1 (102418)
using GitHub Actions (actions/sonarqube-scan-action@v2.0.1) on self-hosted Linux runner
Would like to understand why certain files report as 0% coverage
Reviewed sonar-project.properties to ensure files are not excluded in any way
My entire project is TypeScript. Most of the files have coverage reported correctly, but a few files in my project report as having 0% code coverage in the SonarQube UI even though they do have test coverage. I have noticed at least 5 files that have this issue. 4 of these files are in the same folder, but there are other files in that same folder that do have coverage reported. The lcov and corresponding HTML report generated by the testing library (vitest with nyc coverage) do show these files as having non-zero coverage, and I am reasonably confident that these TS files are not excluded by configuration in sonar-project.properties. I do have multiple lcov files that get generated and are all used for the scan, but this generally seems to work fine. I do not see any error logs in the sonar scanner step of my GitHub CI action. I am trying to understand what is causing these files to report 0% code coverage when I am expecting a non-zero value
First, you mention having multiple lcov files. Would the coverage for the 0-coverage files be clustered in any particular one of these? Perhaps one or more files simple isn’t being picked up or parsed successfully?
Can you add -Dsonar.verbose=true to the analysis command line and share your analysis log?
The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.
Thanks for the response, Ann. I have shrunk my analysis to only include the lcov file that is relevant to the TS files that are being unexpectedly reported as having 0% coverage and run the scan with verbose enabled. I am seeing the following debug log for 14 different files (including all of the files that I noted in my original post), for many different lines per file: DEBUG: Problem during processing LCOV report: can't save DA data for line 15 of coverage report file (java.lang.IllegalArgumentException: Line with number 15 doesn't belong to file app.ts).
I saw something like this recently (but can’t find the thread). It was something about a transformation of the files during the build process leading to analysis getting files that no longer matched the files that the coverage report was created from.
I don’t have any transformations happening during the build process that would cause this, but I searched for related errors in this forum and found someone else who had the same problem as me. It seems that my problem is that in my monorepo (which I didn’t realize would be relevant, which is why I didn’t include it in my initial post) I have files at the same relative path in 2 different folders and am generating the coverage in each of those folders independently. Every one of the lines about processing the LCOV report where “line doesn’t belong to file” are about files in folderA which have a matching route in folderB. I run my tests in each folder and then sonar scan with all of the files in place where they were originally generated. folderB/coverage/lcov.info includes SF paths that are relative to folderB, but there are files at the same relative path in folderA, so I’m assuming that the sonar scan doesn’t consider the context/location of the coverage file that it is analyzing.
I have now solved this issue by setting my --cwd option for my test command (using nyc) to the root of the monorepo, so that the lcov files include more context in the source file paths (folderA/app.ts and folderB/app.ts rather than just app.ts). I am still confused on why this happened also for file paths that only exist in one module, but the issue is resolved now, so the answer isn’t all that important at this point.
Thanks so much for commenting and leading me to find the information that I needed!