SonarQube analysis skips files with errors and returns SUCCESS

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.

Any ideas on how to solve this?

Hey there.

Can you provide an example of a file that when (failed) to be parsed, doesn’t report the issue?

Hello!

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 “,”

It would help a lot if you can provide an easy reproducer, like a specific file.

Hello!

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.

Hi @CoVlado,

sorry for the late answer, we are looking into this.

Cheers,
Victor

Hello @CoVlado,

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?

Best,
Ilia

Hello!

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?)

Hello @CoVlado,

I could add that by “already existing file” I’m talking about a file that was previously scanned at least once

So you mean that activating the S2260 rule skipped the file from analysis?
What was the behaviour before activating it?
Could you share a reproducer?

Best,
Ilia

Hello!

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.

Hello @CoVlado,

I tried the following reproducer without success:

  1. activate S2260
  2. add valid vue file, I used the example provided at the top of this page
  3. scan
  4. introduce a syntax error: I deleted the </script> line
  5. scan
  6. my local SQ 9.9 shows an S2260 error as it should

Was there an action of activating rule S2260 in there that is missing?

Hello!

Could you try this sequence:

  1. add valid vue file
  2. scan
  3. Introduce the syntax error
  4. scan
  5. activate S2260
  6. scan

Hello @CoVlado,

I have reproduced your steps with the file I mentioned above, but I am indeed generating an issue for rule S2260 on step 6:

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>

I’m using:

  • SQ 9.9 CE
  • Scanner 4.7

Am I missing something?