EsLint issues Import fails with Expected BEGIN_ARRAY

I am trying to import EsLint Issues to my sonarCloud analysis. I wrote a custom formatter and when i execute locally sonar-scanner, everything works. If i run it on bitbucket server during pull request analysis, i got the error

ERROR: Error during SonarScanner execution
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
	at com.google.gson.Gson.fromJson(Gson.java:975)
	at com.google.gson.Gson.fromJson(Gson.java:901)
	at org.sonar.plugins.javascript.external.TslintReportSensor.importReport(TslintReportSensor.java:64)

My structure of the esLint Report is as defined in the documentation:

{issues: [{issues1}, {issue2},…]}

What can be the problem in this case, that i am getting this error?

Hi,

Can you share your formatted report?

 
Ann

my Report is:

{"issues":[{"engineId":"eslint","ruleId":"camelcase","primaryLocation":{"message":"Identifier 'v7_startTransition' is not in camel case.","filePath":"C:\\path\to\file\\App.tsx","textRange":{"startLine":21,"endLine":21,"endColumn":85}},"type":"BUG","severity":"MAJOR"},{"engineId":"eslint","ruleId":"@typescript-eslint/no-unused-vars","primaryLocation":{"message":"'id' is assigned a value but never used.","filePath":"C:\\Path\to\file.ts","textRange":{"startLine":86,"endLine":86,"endColumn":19}},"type":"BUG","severity":"MAJOR"}]}

i tried also with the json formatter, but then i get the error Message: Expected BEGIN OBJECT but was BEGIN ARRay

[{"engineId":"eslint","ruleId":"camelcase","primaryLocation":{"message":"Identifier 'v7_startTransition' is not in camel case.","filePath":"C:\\path\to\file\\App.tsx","textRange":{"startLine":21,"endLine":21,"endColumn":85}},"type":"BUG","severity":"MAJOR"},{"engineId":"eslint","ruleId":"@typescript-eslint/no-unused-vars","primaryLocation":{"message":"'id' is assigned a value but never used.","filePath":"C:\\path\to\file.ts","textRange":{"startLine":86,"endLine":86,"endColumn":19}},"type":"BUG","severity":"MAJOR"}]

So in the end both versions of the report don’t work

Hi,

I didn’t pay enough attention to your OP, for which I apologize.

You’re saying your report is in the Generic Issues format. With what parameter are you feeding it into analysis? Because if you’re feeding it in as the RHS of sonar.eslint.reportPaths, then it’s not surprising you get an error, since the report doesn’t match that expected format.

And on the topic of expected format, it doesn’t seem to match the format of the Generic Issue report either.

 
HTH,
Ann

I tried it based on this documentation with a custom formatter: How to import ESLint issues into SonarQube overview analysis in a frontend application | by José Queirós | Medium

and the second report was generated with “eslint --format=json -o eslint_report.json”, which was stated in the sonarCloud docs.

i tried it with both properties, but none of it worked
sonar.eslint.reportPaths = eslint_report.json
sonar.externalIssuesReportPaths = eslint_report.json

Hi,

Which report did you provide above? The one from the 3rd-party blog or the one from the command in our docs?

 
Thx,
Ann

First try was with the report from above from the 3rd party blog.

Second try was like describe here at the JS/TS section

: eslint -f json src -o eslint_report.json

  • sonar.eslint.reportPaths
    • Comma-delimited list of paths to JSON ESLint reports (use -f json ESLint option).

For me the section of Generic issue data sounded like any linters or static analysis tools which are not listed in the external analysis reports section.

If i am running the sonar scanner locally against sonarcloud(and use the report format from the third party blog), the eslint issues are shown in sonarcloud.
if i am using it the same way in my bitbucket pipeline i get the errors described as above.

If i really need to format my eslint report data like this: How do i get this rule information? How can i produce a report like this?

Hi,

Have you tried diff-ing the two reports?

 
Ann

i know whats the difference between the reports. The one from the 3rd party blog has the array of issues wrapped in an issues object and the other one only has the array of issues.
That is my problem with Sonarcloud. If i am using the report from the 3rd party blog where i have an Object that contains the array, i get the error message that Sonarcloud expects an Array, but it was an Object. If i am using the report generated with -f json, where i have the array, Sonarcloud complains that it expects an object at Line 1 Column 2, but it was an array.
So with those error messages I am running in circles.

Hi,

Can you provide the report generated with

?

Because what you posted here

doesn’t match what I see in the eslint docs

 
Thx,
Ann