Hey @edamonoomph,
I confirm that your LCOV report is fine and there is no issue related to paths in your analysis. If your Segmentation.js
was not excluded from the analysis, the scanner would find it when parsing the LCOV report and you would not have the Unresolved paths error.
Testing details to confirm this:
Here is my project structure:
antoinevigneau@js$ tree -fa -I .git
.
├── ./.gitignore
├── ./assets
│ └── ./assets/Segmentation.js
└── ./reports
└── ./reports/lcov.txt
My .gitignore
states:
antoinevigneau@js$ cat .gitignore
# Scanner work dir
.scannerwork
# Reports dir
reports
Segmentation.js
is simply:
antoinevigneau@js$ cat assets/Segmentation.js
alert(1);
alert(2);
alert(3);
alert(4);
alert(5);
alert(6);
And the LCOV report is:
antoinevigneau@js$ cat reports/lcov.txt
TN:
SF:assets/Segmentation.js
DA:1,1
DA:3,2
DA:5,3
end_of_record
When I analyze this project, here are the important pieces of logs:
antoinevigneau@js[main]$ sonar-scanner \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.token=**** \
-Dsonar.organization=antoine-vigneau-sonarsource-github \
-Dsonar.projectKey=antoine-vigneau-sonarsource-github_js \
-Dsonar.sources=assets \
-Dsonar.javascript.lcov.reportPaths=reports/lcov.txt \
-X
[...]
10:33:44.421 INFO: Base dir: /Users/antoinevigneau/Documents/Experiments/js
10:33:44.421 INFO: Working dir: /Users/antoinevigneau/Documents/Experiments/js/.scannerwork
[...]
10:33:51.396 INFO: Indexing files...
10:33:51.396 INFO: Project configuration:
10:33:51.396 INFO: Excluded sources: **/build-wrapper-dump.json
10:33:51.424 DEBUG: 'assets/Segmentation.js' generated metadata with charset 'UTF-8'
10:33:51.425 DEBUG: Average line length for assets/Segmentation.js is 7
10:33:51.431 DEBUG: 'assets/Segmentation.js' indexed with language 'js'
10:33:51.436 INFO: 1 file indexed
[...]
10:34:00.260 INFO: Sensor JavaScript/TypeScript Coverage [javascript]
10:34:00.261 DEBUG: Property sonar.javascript.lcov.reportPaths is used.
10:34:00.261 DEBUG: Using 'reports/lcov.txt' to resolve LCOV files
10:34:00.261 INFO: Analysing [/Users/antoinevigneau/Documents/Experiments/js/reports/lcov.txt]
10:34:00.271 INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=11ms
So the file is well indexed as assets/Segmentation.js
and because the LCOV report referred it with the same path, it’s all ok (I can see the coverage on the SonarCloud UI)
However, when this file is excluded from the analysis, I can see the same output as you, basically the LCOV parsing fails because it can’t find this file.
Testing details
Now my .gitignore
is:
antoinevigneau@js[main]$ cat .gitignore
# Scanner work dir
.scannerwork
# Reports dir
reports
# Assets files
assets/Segmentation.js
Note that I also had to add another random file assets/file.js
so the analysis was not empty (otherwise pretty much nothing happens).
And the same analysis command outputs:
antoinevigneau@js[main]$ sonar-scanner \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.token=**** \
-Dsonar.organization=antoine-vigneau-sonarsource-github \
-Dsonar.projectKey=antoine-vigneau-sonarsource-github_js \
-Dsonar.sources=assets \
-Dsonar.javascript.lcov.reportPaths=reports/lcov.txt \
-X
[...]
10:41:53.377 INFO: Base dir: /Users/antoinevigneau/Documents/Experiments/js
10:41:53.377 INFO: Working dir: /Users/antoinevigneau/Documents/Experiments/js/.scannerwork
[...]
10:41:59.925 DEBUG: File '/Users/antoinevigneau/Documents/Experiments/js/assets/Segmentation.js' is excluded by the scm ignore settings.
[...]
10:42:01.754 INFO: Indexing files...
10:42:01.754 INFO: Project configuration:
10:42:01.755 INFO: Excluded sources: **/build-wrapper-dump.json
10:42:01.786 DEBUG: 'assets/file.js' generated metadata with charset 'UTF-8'
10:42:01.787 DEBUG: Average line length for assets/file.js is 7
10:42:01.795 DEBUG: 'assets/file.js' indexed with language 'js'
10:42:01.802 INFO: 1 file indexed
[...]
10:42:10.511 INFO: Sensor JavaScript/TypeScript Coverage [javascript]
10:42:10.511 DEBUG: Property sonar.javascript.lcov.reportPaths is used.
10:42:10.511 DEBUG: Using 'reports/lcov.txt' to resolve LCOV files
10:42:10.511 INFO: Analysing [/Users/antoinevigneau/Documents/Experiments/js/reports/lcov.txt]
10:42:10.515 WARN: Could not resolve 1 file paths in [/Users/antoinevigneau/Documents/Experiments/js/reports/lcov.txt]
10:42:10.515 DEBUG: Unresolved paths:
assets/Segmentation.js
10:42:10.515 INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=4ms
So in the end, the real question is why Segmentation.js
file is considered excluded by the SCM config?
I know you said:
We don’t have any ignore settings configured
But before we dive into the potentially hard task of debugging this, could you please double-check if this is true? I don’t see how the scanner could take that decision by itself…
Let me know what you find!
Antoine