Cannot view imported ESLint Findings into SonarQube

  • SonarQube: 10.6, self hosted
  • Eslint: 7.32.0 Is this version supported???
  • New code rule: Previous version
  • how is SonarQube deployed: zip, sonar-scanner-cli version 6.1.0.4477

I’m trying to apply eslint error on sonarcloud, like those from eslint-plugin-import, but it never generates any issue on SonarQube.
Example of change I expected to see an issue from eslint but SonarQube does not report it in my PR.

  • I’ve configured sonar.eslint.reportPaths=reports/eslint-report.json
  • I’ve generated and persisted this file in CI (CircleCI) before running the sonarcloud job.
  • The sonarcloud seems to import it correctly and the file has a comment in there which should trigger the new code rule, but it does not show as an issue in the the Sonarcloud website and neither the PR.

CI log

00:02:13.181 INFO  Sensor JavaScript/TypeScript analysis [javascript] (done) | time=13296ms
00:02:13.182 INFO  Sensor CSS Rules [javascript]
00:02:13.182 INFO  Sensor CSS Rules is restricted to changed files only
00:02:13.185 INFO  No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
00:02:13.185 INFO  Sensor CSS Rules [javascript] (done) | time=4ms
00:02:13.186 INFO  Sensor Import of ESLint issues [javascript]
00:02:13.186 INFO  Importing /home/circleci/neutron/reports/eslint-report.json
00:02:13.208 INFO  Sensor Import of ESLint issues [javascript] (done) | time=23ms
00:02:13.208 INFO  Sensor IaC Docker Sensor [iac]
00:02:13.209 INFO  Sensor IaC Docker Sensor is restricted to changed files only
00:02:13.214 INFO  0 source files to be analyzed
00:02:13.258 INFO  0/0 source files have been analyzed
00:02:13.259 INFO  Sensor IaC Docker Sensor [iac] (done) | time=50ms
00:02:13.259 INFO  Sensor TextAndSecretsSensor [text]
00:02:13.259 INFO  Sensor TextAndSecretsSensor is restricted to changed files only
00:02:13.259 INFO  Available processors: 16
00:02:13.259 INFO  Using 16 threads for analysis.

Example of report from eslint

[
  {
    "filePath": "/home/circleci/neutron/src/app/constants/test-selectors/index.js",
    "messages": [
      {
        "ruleId": "import/named",
        "severity": 2,
        "message": "ACCOUNT_SELECTORS not found in './account-selectors'",
        "line": 4,
        "column": 35,
        "nodeType": "Identifier",
        "endLine": 4,
        "endColumn": 52
      },
      {
        "ruleId": "import/named",
        "severity": 2,
        "message": "SHIPT_IDENTIFIER_SELECTORS not found in './my-orders-selectors'",
        "line": 18,
        "column": 3,
        "nodeType": "Identifier",
        "endLine": 18,
        "endColumn": 29
      },
      {
        "ruleId": "import/export",
        "severity": 2,
        "message": "Multiple exports of name 'DELIVERY_DETAILS_SELECTORS'.",
        "line": 53,
        "column": 1,
        "nodeType": "ExportAllDeclaration",
        "endLine": 53,
        "endColumn": 50
      },
      {
        "ruleId": "import/named",
        "severity": 2,
        "message": "AVAILABLE_ROUTES_SELECTORS not found in './available-routes-selectors'",
        "line": 60,
        "column": 10,
        "nodeType": "Identifier",
        "endLine": 60,
        "endColumn": 36
      },
      {
        "ruleId": "import/export",
        "severity": 2,
        "message": "Multiple exports of name 'DELIVERY_DETAILS_SELECTORS'.",
        "line": 80,
        "column": 42,
        "nodeType": "Identifier",
        "endLine": 80,
        "endColumn": 68
      }
    ],
    "errorCount": 5,
    "fatalErrorCount": 0,
    "warningCount": 0,
    "fixableErrorCount": 0,
    "fixableWarningCount": 0,
    "source": "I OMMITED THIS PART TO NOT SHOW SOURCE CODE OF THE PROJECT IN HERE",
    "usedDeprecatedRules": []
  }
]

sonar-project.properties

sonar.projectKey=A_VALID_PROJECT_KEY_OMMITED
sonar.host.url=A_VALID_SERVER_URL_OMMITED

sonar.sources=src
sonar.exclusions=**/*.java,**/*.kt,**/*.e2e.js
sonar.eslint.reportPaths=reports/eslint-report.json

Activating verbose, it seems the files are being uploaded, but somehow it is never generated an issue

01:24:14.515 INFO  Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=312ms
01:24:14.515 INFO  Sensor Import of ESLint issues [javascript]
01:24:14.515 INFO  Importing /home/circleci/neutron/reports/eslint-report.json
01:24:14.529 DEBUG Saving external ESLint issue { file:"/home/circleci/neutron/src/app/constants/test-selectors/index.js", id:import/named, message:"ACCOUNT_SELECTORS not found in './account-selectors'", line:4, offset:34, type: BUG, severity:MAJOR, remediation:5 }
01:24:14.536 DEBUG Saving external ESLint issue { file:"/home/circleci/neutron/src/app/constants/test-selectors/index.js", id:import/named, message:"SHIPT_IDENTIFIER_SELECTORS not found in './my-orders-selectors'", line:18, offset:2, type: BUG, severity:MAJOR, remediation:5 }
01:24:14.536 DEBUG Saving external ESLint issue { file:"/home/circleci/neutron/src/app/constants/test-selectors/index.js", id:import/export, message:"Multiple exports of name 'DELIVERY_DETAILS_SELECTORS'.", line:53, offset:0, type: BUG, severity:MAJOR, remediation:5 }
01:24:14.537 DEBUG Saving external ESLint issue { file:"/home/circleci/neutron/src/app/constants/test-selectors/index.js", id:import/named, message:"AVAILABLE_ROUTES_SELECTORS not found in './available-routes-selectors'", line:60, offset:9, type: BUG, severity:MAJOR, remediation:5 }
01:24:14.537 DEBUG Saving external ESLint issue { file:"/home/circleci/neutron/src/app/constants/test-selectors/index.js", id:import/export, message:"Multiple exports of name 'DELIVERY_DETAILS_SELECTORS'.", line:80, offset:41, type: BUG, severity:MAJOR, remediation:5 }
01:24:14.537 INFO  Sensor Import of ESLint issues [javascript] (done) | time=22ms
01:24:14.537 INFO  Sensor IaC Docker Sensor [iac]
01:24:14.537 INFO  Sensor IaC Docker Sensor is restricted to changed files only
01:24:14.542 INFO  0 source files to be analyzed
01:24:14.588 INFO  0/0 source files have been analyzed

Hello!

Are you reviewing a Pull Request in SonarQube instead of your main branch? I think based on your post, that’s the case.

If that’s the case, do you have any modified lines in the PR or branch that correspond to the same files and lines where there are issues reported by ESLint?

I’m asking because SonarQube will only raise issues related to changed lines in a PR context. It would be interesting to see if the results are the same or different re: the esLint issues on your main branch.

Hi Colin,

I’m running this in a Draft PR, not the main branch. After adding sonar.eslint.reportPaths=reports/eslint-report.json to the sonar-project.properties file, I noticed that issues previously reported in the PR by the predefined rules in the SonarQube UI (e.g., no-unused-vars) are no longer appearing.

WITHOUT sonar.eslint.reportPaths=reports/eslint-report.json, it shows the default rules


WITH sonar.eslint.reportPaths=reports/eslint-report.json, it does not show neither the default rules nor the ones inside reports/eslint-report.json

 {
    "filePath": "src/app/modules/comms/components/sprinklr/message/chat-media.component.js",
    "messages": [
      {
        "ruleId": "no-unused-vars",
        "severity": 2,
        "message": "'unusedVar' is assigned a value but never used.",
        "line": 11,
        "column": 7,
        "nodeType": "Identifier",
        "messageId": "unusedVar",
        "endLine": 11,
        "endColumn": 16
      }
    ],
    "errorCount": 1,
    "fatalErrorCount": 0,
    "warningCount": 0,
    "fixableErrorCount": 0,
    "fixableWarningCount": 0,
    "source": "import React, { useState } from 'react';\nimport { Image, Text, View } from 'react-native';\nimport { Icon } from '@root/components'; SOME OTHER SOURCE CODE I AM HIDING",
    "usedDeprecatedRules": []
  }

Could there be a configuration in the SonarQube administration that overrides or conflicts with changes made to the sonar-project.properties file? Alternatively, is there a quota or limitation in place, such as restricting a maximum number of issues per PR, maximum or a limit on issue alerts per month, or @sonarqube-commenter-prd affect it somehow?

I’ve checked Administration -> External Analyzers -> ESLint Report Files for any relevant configurations but didn’t find anything that might be causing this. Adding the report path (reports/eslint-report.json) there also didn’t resolve the issue.

Hey @Roni_Castro

Based on this screenshot, you appear to be using an unofficial method to enable PR analysis/decoration on SonarQube’s Community Build. This is easy to tell because the official integration (Developer Edition +) does not support in-line issue annotation.

As a result won’t be able to support you around PR analysis / GitHub integration in this Community, and I suggest you raise an issue with the maintainer of this method if you want to pursue it further.

1 Like