Importing eslint into sonarqube

eslint
typescript
sonarts

(Venkata Nandagiri) #1

I have a eslint file generated through external resources and wanted to import the report into SonarQube.

Reference: https://docs.sonarqube.org/display/PLUG/Importing+TSLint+and+ESLint+issues+for+TypeScript+files

Software installed: SonarQube 7.2

Sonar property used: -Dsonar.typescript.eslint.reportPaths=“ref to my eslint report”

Content of the elint report file:

<jslint>
<file name="C:\Tools\Jenkins\workspace\FunctionalTesting\MyProject\app\src\indexOne.js">

<issue reason="Expected indentation of 4 spaces but found 2. (indent)" evidence=" super(props);" char="1" line="7"/>

<issue reason="Expected indentation of 4 spaces but found 2. (indent)" evidence=" this.state = {};" char="1" line="8"/>

<issue reason="Expected indentation of 4 spaces but found 1 tab. (indent)" evidence="	const {title} = this.props;" char="1" line="12"/>

<issue reason="'title' is assigned a value but never used. (no-unused-vars)" evidence="	const {title} = this.props;" char="9" line="12"/>

<issue reason="img elements must have an alt prop, either with meaningful text, or an empty string for decorative images. (jsx-a11y/alt-text)" evidence=" <img src=""/>" char="7" line="14"/>

<issue reason="Expected indentation of 0 spaces but found 2. (indent)" evidence=" };" char="1" line="27"/>

</file>
</jslint>

But I dont see the report imported into Sonarqube, rather it shows the eslint findings by using SonarTS plugin. But none of the findings from the above file are imported. Is there anything I am missing?


Native Eslint Support
(Tibor Blenessy) #2

Hello,

the imported report should be in json format, you can set it using -f json when launching ESLint.

Also from the report it seems that you are linting JS file, SonarTS will only show issues on TypeScript files. We plan to implement import of ESLint issues also for JS files, but this is not done yet (see MMF-1231 )


(Venkata Nandagiri) #3

I have used some external plugins to generate the file in json format and I am going to use SonarQube just to import the file using sonar.typescript.eslint.reportPaths=report.json file.
data.txt (3.5 KB)

File is attached with this (changed extension to .txt from .json) . But it is not working.

Sonar scanner command:
bat "${sonarScanner} -Dsonar.sources=${sonarSource} -Dsonar.language=${sonarLan} -Dsonar.host.url=${sonarQubeURL} -Dsonar.projectKey=${sonarProjectKey} -Dsonar.projectName=${sonarProjectKey} -Dsonar.projectVersion='6' -Dsonar.typescript.eslint.reportPaths=${jsonReport}"

jsonReport points to json file.


(Tibor Blenessy) #4

Can you please sent the logs when you run the scanner? Are you analyzing TypeScript files?


(Stas Vilchik) #5

Hello,

Looks like ESLint and JSLint were mixed. The report is a JSLint one, however SonarTS supports the ESLint one.


(Venkata Nandagiri) #6

Let me give the details:

My TypeScript file: IndexOne.ts

import React from 'react';
import PropTypes from 'prop-types';
import './styles/styles.css';

export default class HelloWorld extends React.Component {
  constructor(props) {
  super(props);
  this.state = {};
  }

  render() {
	const {title} = this.props;
    return (
      <img src=""/>
    );
  }
}

// Proptypes
HelloWorld.propTypes = {
  title: PropTypes.string.isRequired
};

// Default proptypes
HelloWorld.defaultProps = {
  title: 'Hello'
  };

Issues file: data.txt (attached here)
data.txt (3.5 KB)

Sonar scanner command:

bat "${sonarScanner} -Dsonar.sources=${sonarSource}  -Dsonar.host.url=${sonarQubeURL} -Dsonar.projectKey=${sonarProjectKey} -Dsonar.projectName=${sonarProjectKey} -Dsonar.projectVersion='6' -Dsonar.typescript.eslint.reportPaths=${jsonReport}"

${jsonReport} --> Points to the path of the file data.txt

INFO: Sensor SonarTS [typescript]
ERROR: No tsconfig.json file found for [file:///C:/Tools/Jenkins/workspace/FunctionalTesting/\myproject/App/src/indexOne.ts] (looking up the directories tree until project base directory [C:\Tools\Jenkins\workspace\FunctionalTesting]). This file will not be analyzed.

Actually, I dont have tsconfig.json file. I just wanted to try to import the attached data.txt file.


(Stas Vilchik) #7

You need to have the tsconfig.json in the root of your project.

You can read more about it in the official TypeScript documentation.


(Tibor Blenessy) #8

Just to complete, we would like to remove the requirement of tsconfig.json file, here is an issue you can follow.

https://github.com/SonarSource/SonarTS/issues/444