SonarEsLintPlugin icon indicating copy to clipboard operation
SonarEsLintPlugin copied to clipboard

EsLint Custom Rules

Open bhavin-vadgama opened this issue 6 years ago • 11 comments

I have these three other eslint plugins that I want to integrate into sonarqube v.6.7.2. A. redux-saga B. react C. jsx-a11y

and below is my sonar-project.propeties file:


sonar.projectKey=abc sonar.projectName=xyz sonar.projectVersion=0.0.0.1 sonar.sources=app/ sonar.exclusions= app/utils/**/*, sonar.language=js sonar.javascript.file.suffixes=.js,.jsx sonar.profile=ReactJs sonar.eslint.eslintpath=node_modules/eslint/bin/eslint.js sonar.eslint.eslintconfigpath=package.json sonar.eslint.eslintrulesdir=react,redux-saga,jsx-a11y sonar.sourceEncoding=UTF-8 sonar.login=pqr sonar.password=jkl


These three plugins rules are specified on eslint-rules.properties file and it is showing these rules on sonarqube also. but the problem here is that sonarqube is not generating any report related to these three rules even I have intentionally made a mistake.

can you please check whether I have specified "sonar.eslint.eslintrulesdir" path right or I am missing something. Please help me with this I am into this issue since past 3 days.

bhavin-vadgama avatar Apr 06 '18 06:04 bhavin-vadgama

I hava the same problem

double-yaya avatar Aug 28 '19 08:08 double-yaya

I have these three other eslint plugins that I want to integrate into sonarqube v.6.7.2. A. redux-saga B. react C. jsx-a11y

and below is my sonar-project.propeties file:

sonar.projectKey=abc sonar.projectName=xyz sonar.projectVersion=0.0.0.1 sonar.sources=app/ sonar.exclusions= app/utils/**/*, sonar.language=js sonar.javascript.file.suffixes=.js,.jsx sonar.profile=ReactJs sonar.eslint.eslintpath=node_modules/eslint/bin/eslint.js sonar.eslint.eslintconfigpath=package.json sonar.eslint.eslintrulesdir=react,redux-saga,jsx-a11y sonar.sourceEncoding=UTF-8 sonar.login=pqr sonar.password=jkl

These three plugins rules are specified on eslint-rules.properties file and it is showing these rules on sonarqube also. but the problem here is that sonarqube is not generating any report related to these three rules even I have intentionally made a mistake.

can you please check whether I have specified "sonar.eslint.eslintrulesdir" path right or I am missing something. Please help me with this I am into this issue since past 3 days.

Have you found the problem? Can you let me know?

double-yaya avatar Aug 28 '19 09:08 double-yaya

Hi,

As I wrote in the README recently, you have a native support of ESLint in the latest versions of SonarQube. Therefore, if you have the possibility, I would recommend to use this preferred alternative.

If for some reason, you cannot use it, let me know, I will fix this issue, once for good.

Thanks,

Sylvain

On Wed, Aug 28, 2019 at 11:20 AM double-yaya [email protected] wrote:

I have these three other eslint plugins that I want to integrate into sonarqube v.6.7.2. A. redux-saga B. react C. jsx-a11y

and below is my sonar-project.propeties file:

sonar.projectKey=abc sonar.projectName=xyz sonar.projectVersion=0.0.0.1 sonar.sources=app/ sonar.exclusions= app/utils/**/*, sonar.language=js sonar.javascript.file.suffixes=.js,.jsx sonar.profile=ReactJs sonar.eslint.eslintpath=node_modules/eslint/bin/eslint.js sonar.eslint.eslintconfigpath=package.json sonar.eslint.eslintrulesdir=react,redux-saga,jsx-a11y sonar.sourceEncoding=UTF-8 sonar.login=pqr sonar.password=jkl

These three plugins rules are specified on eslint-rules.properties file and it is showing these rules on sonarqube also. but the problem here is that sonarqube is not generating any report related to these three rules even I have intentionally made a mistake.

can you please check whether I have specified "sonar.eslint.eslintrulesdir" path right or I am missing something. Please help me with this I am into this issue since past 3 days.

Have you found the problem? Can you let me know?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sleroy/SonarEsLintPlugin/issues/3?email_source=notifications&email_token=ABL7XERPKYL4RHJ7JA5XJGDQGY7NLA5CNFSM4EZGG7TKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5KOZNA#issuecomment-525659316, or mute the thread https://github.com/notifications/unsubscribe-auth/ABL7XETZW7CGPIVNPSQ4KMTQGY7NLANCNFSM4EZGG7TA .

sleroy avatar Aug 28 '19 19:08 sleroy

My environment is as follows: sonar:6.1 sonareslintplugin:0.1.1 jdk:1.8

sonar-project.properties: sonar.projectKey=company:my-application sonar.projectName=My Application sonar.projectVersion=1.0 sonar.sourceEncoding=UTF-8 sonar.sources=src sonar.exclusions=/node_modules/ #sonar.tests=src/app #sonar.test.inclusions=**/*.spec.ts sonar.eslint.eslintconfigpath=.eslintrc.js sonar.eslint.eslintrulesdir=rule

sonar web configuration: image

sonar analysis log: 16:04:30.403 DEBUG - Split 2 files into 1 batches for processing 16:04:30.403 DEBUG - Executing EsLint with command: node C:\Users\Administrator.DCITSDC-LKIU0SB\AppData\Roaming\npm\node_modules\eslint\bin\eslint.js -f json --rules-dir E:\eslint\Test\rule --output-file E:\eslint\Test.sonar.sonartmp\2287655680825963988.tmp --config E:\eslint\Test.eslintrc.js E:/eslint/Test/src/index.js E:/eslint/Test/src/merge.js 16:04:30.403 DEBUG - Executing EsLint with command: node C:\Users\Administrator.DCITSDC-LKIU0SB\AppData\Roaming\npm\node_modules\eslint\bin\eslint.js -f json --rules-dir E:\eslint\Test\rule --output-file E:\eslint\Test.sonar.sonartmp\2287655680825963988.tmp --config E:\eslint\Test.eslintrc.js E:/eslint/Test/src/index.js E:/eslint/Test/src/merge.js 16:04:31.316 INFO - Sensor Linting sensor for Javascript files (done) | time=922ms

Execution results under eslint command line: image

double-yaya avatar Aug 29 '19 01:08 double-yaya

OK thanks for the complete report. I will treat it this week.

sleroy avatar Sep 01 '19 16:09 sleroy

OK thanks for the complete report. I will treat it this week.

Do you have any results?

double-yaya avatar Sep 17 '19 07:09 double-yaya

SonarQube version 6.1 is not available for Download. I am beginning the tests with the LTS 6.7

sleroy avatar Sep 19 '19 12:09 sleroy

Here are my explanations.

I created a project exampleApp into the github project for demonstration.

Here : https://github.com/sleroy/SonarEsLintPlugin/tree/master/exampleProject

First preliminary steps are :

  • Copy the plugin jar into the extensions/plugin folder of your SonarQube installation
  • Creates a profile including the plugin rules (javascript language)
  • If you do not see your custom rules availables for the Javascript language it means that your custom definitions have not been loaded.

If your custom rules have not been loaded, the sonar-scanner log will display messages as such :

INFO: Rule react-jsx-filename-extension has not yet being defined into the EsLint plugin
INFO: Rule react-jsx-filename-extension has not yet being defined into the EsLint plugin
INFO: Rule react-jsx-filename-extension has not yet being defined into the EsLint plugin
INFO: Rule react-jsx-one-expression-per-line has not yet being defined into the EsLint plugin
INFO: Rule react-jsx-one-expression-per-line has not yet being defined into the EsLint plugin
INFO: Sensor Linting sensor for Javascript files [eslintplugin] (done) | time=1118ms

It means that the SonarEsLint plugin does not have a Sonar definition for these eslint rlues.

You need to add them.

sleroy avatar Sep 19 '19 13:09 sleroy

Now the explanation on how to add them :

By default the plugin is loading a default set of rules defined here :

https://github.com/sleroy/SonarEsLintPlugin/blob/master/src/main/resources/eslint/eslint-rules.properties

As you can see, for each rule of eslint, you have to define a set of properties to populate the Sonar Javascript profile. Without these informations the new rules are not being imported.

I cannot add dynamically rules form ESLint since it is not supported by SonarQube. Rules have to be defined and loaded at the SonarQube startup.

How to add the eslint plugin extra rules ?

a) Fork the file eslint-rules.properties and send me the modifications to merge

The plugin will integrate the new rules for the other users.

b) Pass the definitions through the admin tab in SonarQube

image

image

We have a bug : what has been implemented in the TSLint package is not working..

I will fix it now.

sleroy avatar Sep 20 '19 09:09 sleroy

Important : when a rule from an ESLint plugin is detected by the plugin, I am assigning the ESLint violation to the rule "Unknown rule" like in the caption below :

Therefore unless you provide the proper definition for this rule, you will have several violations with this description :

image

image image

sleroy avatar Sep 20 '19 13:09 sleroy

ok ,I'll test,thank you

double-yaya avatar Sep 23 '19 05:09 double-yaya