I am using SonarQube 9.9 LTS (Developer Edition), Scanner (4.8.0.2856-windows). This is deployed using zip.
I enabled the rule “JavaScript parser failure” for my quality profile but looking at the logs it seems that the Scanner skips the files with errors (in this case the parsing error) instead of analyzing it and reporting back that there is a Parsing failure.
I’m using Jenkins as a CI and I tried setting the “sonar.analysis.failOnError” attribute in the Jenkinsfile on “true” but there were no results.
Let’s say any *.vue file with a syntax error (I’m sorry. Maybe I should’ve said that this is about a JS *.vue file)
For example in my case the error (from SQ log) looks something like and then this is not reported back as a problem:
ERROR: Failed to parse file [file_name.vue] at line X: Unexpected token, expected “,”
After further investigations the problem seems to be:
Adding a syntax error in an already existing file results in skipping the file (although the log shows it as an ERROR) and the analysis is successful
Adding a new file with a syntax error results in the report of this code smell (A JavaScript syntax problem) - Which is the expected behavior for both cases.
If I understand correctly, having activated the S2260 rule, you expected files with syntax errors to report an issue in SonarQube, while they were skipped from the analysis and did not report anything.
Is that correct?
That’s correct but please keep in mind the behavior from my previous comment.
I could add that by “already existing file” I’m talking about a file that was previously scanned at least once. (Maybe there is some caching setting I missed or?)
So you mean that activating the S2260 rule skipped the file from analysis?
Exactly! In the log file the error is reported (Syntax error) and then it says that the file is skipped.
Before activating the S2260 rule the behavior was pretty much the same (skipped the file with the error).
Keep in mind that if I create a new file with syntax errors in it, it is detected and handled properly.
An easy reproducer would be: Having a valid *.vue (e.g: sample vue file from their website) → Trigger an analysis → Add a syntax error in this file and trigger another analysis.
The scanner logs don’t mention any file skipping either:
INFO: 3 source files to be analyzed
ERROR: Failed to parse file [simple.vue] at line 11: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>? (11:0)
...
INFO: 3/3 source files have been analyzed
For reference, here is the JS vue file I’m using:
<script setup>
import { ref } from 'vue'
const greeting = ref('Hello World!')
var hello;
</script> <!-- deleting this line for syntax error -->
<template>
<p class="greeting">{{ greeting }}</p>
</template>
<style>
.greeting {
color: red;
font-weight: bold;
}
</style>