Using esLint scanner for SonarQube 7.9

Hi all,

I am trying to migrate from SonarQube 6.7.7 to SonarQube 7.9.1

I tried to scan using esLint Scanner and the it run. But the result is not as expected. The codes is in javascript and it should have violation. Am I doing it wrong? How to scan with esLint scanner?

Thank you

hello @fanny_tan,

it’s not clear to me what you are trying to achieve. To scan JavaScript project, you should use SonarScanner , to import eslint issues, you should create the report and import it by setting sonar.eslint.reportPaths property.

Hi @saberduck

Sorry, could you please provide me the details about how to create this esLint report?

Have a look here [External Analyzer Reports] Report generation for several languages

Thank you so much @saberduck
I wil try it out :smiley:

Hello @saberduck

I have tried this command, but it failed to create report.json. So I try to find other command which is “npm i eslint -f json > test.json” and it has successfully created the report but I can’t import it to SonarQube.

Do you know why? Thank you

Please provide some details, what are you trying to do (which commands you are executing), and what is the output (logs).

Hi @saberduck

I am trying to create esLint Report and import the report to SonarQube 7.9.1.

Based on your suggestion, I try to create the report this command using eslint -f json -o report.json . I got this error log.

Then I found another command from other sites which is npm i eslint -f json > test2.json , the report is created. Here is the report that has been created using this command.
image

But when I try to import that report, it failed. Here is the log.

What should I do? :persevere:

hello @fanny_tan,

I think you are mixing some things. Command npm i eslint is actually using npm package manager to install eslint into your project. Once you have installed it, you should not launch npm i eslint, because that would just install it again.

You need to run eslint, to run locally installed package you can use npx eslint -f json > report.json

Also have a look at eslint documentation here https://eslint.org/docs/user-guide/getting-started

Hi @saberduck,

From your suggestion, I use this command “npx eslint -f json > report.json” and just get result as shown below :

Any idea? I just scan one file.js in this case.

Thankyou :frowning:

Hi @saberduck,

Do you mind to share your example project that has been successfully scanned using your command? Thank you.

Hello, anybody can help?

@fanny_tan, sorry command I gave you was incorrect, I copy&pasted wrong part from the previous post. It should be like written in the doc

npx eslint -f json -o report.json file.js (replace file.js with your file, or directory)

Also, please study documentation on eslint, https://eslint.org/docs/user-guide/getting-started , it will help you troubleshoot issues like this.

Dear @saberduck

Okay, thank you very much, I will try it out and notify you soon about the result :smiley:

Hi @saberduck,

I have scanned the file.js with eslint and I got a json file result that contains issues. The next step is importing external issues to SonarQube 7.9 with this command “.\sonar-scanner -Dsonar.eslint.reportPaths=path-to-report.json”, but the scanner said like shown below :

I expect all violation that has been found in report.json should be imported to SonarQube and I can view it on Issues list, but it didn’t. Instead, it clear up all issues that has been scanned before using SonarQube scanner.

Thank you :slight_smile:

A post was split to a new topic: Where to see eslint reports

Same with me!Do you solved?