We’re having an issue with SonarQube failing to parse most of our Vue typescript files, due to typescript specific syntax.
Versions:
SonarQube v. 8.7 (build 41497)
Vue v. 2.6.11
Typescript v 3.9.6
Errorlog:
09:44:51 INFO: 0 files ignored because of scm ignore settings
09:44:51 INFO: Quality profile for css: Sonar way
09:44:51 INFO: Quality profile for grvy: Sonar way
09:44:51 INFO: Quality profile for java: Sonar way
09:44:51 INFO: Quality profile for js: Sonar way Recommended
09:44:51 INFO: Quality profile for ts: Sonar way recommended
...
09:45:05 INFO: 472 source files to be analyzed
09:45:05 INFO: Analyzing 472 files using tsconfig: [...]
09:45:15 INFO: 2/472 files analyzed, current file:[...]
09:45:15 ERROR: Failed to parse file [...] at line 55: Unexpected token (20:10)
09:45:18 ERROR: Failed to parse file [...] at line 57: Unexpected token (19:12)
09:45:21 ERROR: Failed to parse file [...] at line 19: Unexpected token (10:19)
09:45:25 ERROR: Failed to parse file [...] at line 22: Unexpected token (11:33)
09:45:25 INFO: 8/472 files analyzed, current file:[...]
09:45:28 ERROR: Failed to parse file [...] at line 124: Unexpected token (24:31)
09:45:32 ERROR: Failed to parse file [...] at line 54: Unexpected token (25:18)
09:45:35 ERROR: Failed to parse file [...] at line 16: Unexpected token (11:37)
09:45:35 INFO: 12/472 files analyzed, current file: [...]
All the errors with “unexpected tokens” above points to Typescript syntax in our @Props where we use ! to annotate the prop is required shown below
The project is about ~14k lines of code, using Node 14.15.
I’ll see if we can get our SonarQube updated to 8.8.
The odd thing is, that the scan passes successfully allowing us to view the scan report and everything.
It just bugs me out, that our sonarqube uses 10mins trying to parse our Typescript files, while our slightly larger Java project (16k lines of code) zooms through Sonar in ~40 seconds.
We also have cases where it fails to parse the code where we have your suggestion with both Vue’s and Typescript’s non-null assertation @Prop({required: true}) private foo!
16:18:20 ERROR: Failed to parse file [src/main/vue/src/components/EmneSideMenu.vue] at line 31: Unexpected token (12:32)
which points to this line of code
We’re running SonarQube Community Edition Version 8.7 (build 41497), but as I’m not the owner of the server, upgrading to 8.8 may take some time as it has to go through “needed” bureaucratic loops, but I’ll get back to you as soon as I get it upgraded
I tried to reproduce the parse error on my computer with the same code snippet. My parse did not fail, however. (I am running 8.8 EE though.) If you craft a barebones example that fails on your end, I’ll be glad to run it to reproduce on mine.
Hi Jasper. Thank you for composing a test case that fails on your system.
I could not reproduce the error. I analyzed your code on a client running SonarScanner 4.5.0.2216 and server running SonarQube 8.8.0.42792 (also build 42792).
Today after upgrade to my SonarQube server to 8.8.0.42792. we encountered this same problem by scanning vue file. Do we have any update on this. Thanks in advance for all helps here.
We identified the cause of these failures and consequently created a ticket that we will address as soon as possible. In the meantime, you can use the following temporary workaround:
.vue files must be specified in the "files" property of the tsconfig.json file.
Please let us know if the problem persists even with the workaround.
According to the TSConfig Reference, you’re not supposed to use patterns in the "files" property but rather specify the path to each file. Assuming you have src/A.vue, src/B.vue, …, and src/Z.vue files in your project, your tsconfig file would then need to look as follows:
It then won’t work with "./*.vue" because TypeScript compiler doesn’t walk the file system and collect files matching provided patterns for the particular case of the "files" property.
I understand it’s cumbersome to explicitly specify the path of each .vue file, but as mentioned in my previous message, it’s a temporary workaround until we actually fix the issue.