SonarLint: TypeScript not working

When updating bindings, the plugin successfully downloads all dependencies, starts TS Server and starts checking one file that is open. But the check of this file lasts indefinitely, until I kill the NodeJs process.
When checking the .js files everything goes fine, the problem is only with .ts and .tsx files
My colleague checked this on his computer, he has the same problem

In the console I see the following:

In the console I see the following:
SonarTS Server is started
SonarTS Server connected to 52718
Server started on 64120
No analysis configurators found
Using connection ‘Sonar’ for project ‘react’
Analysing ‘index.tsx’…

Plugin versions:

  • SonarScala: 1.5.0.315
  • SonarPython: 1.14.1.3143
  • SonarJava: 5.13.1.18282
  • SonarHTML: 3.1.0.1615
  • SonarXML: 2.0.1.2020
  • SonarKotlin: 1.5.0.315
  • SonarPHP: 3.2.0.4868
  • SonarTS: 1.9.0.3766
  • SonarJS: 5.2.1.7778
  • SonarRuby: 1.5.0.315

Hello Vladislav,

Thanks for joining the community and for raising this issue!

It’s not the first time we hear about it, but we are having hard times reproducing it.

Could you tell us a bit more about your environment:

  • what version of IntelliJ and SonarLint do you use ?
  • do you have node executable in your path ?
  • did you configure the Node.js path property in the SonarLint settings ?
  • what project did you use ? could you send it to us, or at least try to provide a reproducer project ?

Thanks,
Damien

  1. PHP Storm: 2020.1.2

  2. Yes, I have. (C:\Program Files\nodejs)

  3. I tried writing it in Analysis properties, the problem persisted. But SonarLint automatically finds my current NodeJs

  4. This is a private project of my company, unfortunately I can not share the code of this project, but I have created a project for you which reproduces the problem described by me.

Download project: test.zip (1.1 KB)

I see it now but based on the traces I see in the logs, I suspect your SonarQube does not use the latest version of the JS/TS analyzer:

Starting SonarTS server

SonarTS has been deprecated recently and replaced by the SonarJS plugin. Could you try updating the plugins used by your SQ server ? You can try to install the latest SonarJS (7.1) and remove SonarJS.

This could help fix the problem directly, and if not at least we will try to investigate on an actively maintained plugin.

Thanks
Damien

This may be a problem for me.
I work for a large company and it is unlikely that they will be able to quickly change the plugin versions, as this may affect other projects.

What do you mean ? ( You can try to install the latest SonarJS (7.1) and remove SonarJS. )

Sorry, it was a typo. I meant that you can try to install latest SonarJS (that replaces SonarTS) and uninstall SonarTS.

I didn’t reproduce using your test project.

Out of curiosity, could you try to analyze your test project without connecting it to SonarQube ? And with the latest version of SonarLint (4.13, that you may already have). It should normally use the latest SonarJS version embedded in the plugin, and I would like to see if a similar problem occurs.

Unfortunately this doesn’t help.
I disabled connecting to SonarQube, and it still 0 errors.

3

Ok so in this case the analysis finished, it’s a different behavior than the original error you reported, when you were connected to the server.

I managed to get issues though. One useful thing you can do when the plugin does not behave correctly is to activate more logs. See here for an explanation.

In this case there were several problems with your tsconfig.json file:

  • the “jsx” option was not permitted (“react-jsx”). You have to use “react”. This trace appears in the extended logs.

  • the files at the root level were not detected for analysis because they were not declared. You have to add

    “files”: [
    “bug.ts”,
    “index.tsx”
    ],

I guess this second point only applies for your reproducer project though.

Could you try to activate verbose logs, change this “jsx” setting in the tsconfig.json file, and retry on your project, with or without connecting it to your SonarQube ?

Thanks
Damien

Thank you so much, Damien Urruty
Changing the tsconfig.json file helped me
I reconnected to my SonarQube server, but thanks to Verbose output and Analysis logs, I saw that the error was in

“jsx”: “react-jsx”

the default value react puts, I changed it to

“jsx”: “react”

and everything worked.
Happy new year and all the best to you

1 Like

Now everything works fine, but I noticed that SonarLint write Found 0 issues for all tests files in the src/tests folder
There are files with the extension: *.test.ts, *.test.tsx
I tried adding a “include” rule to tsconfig for these files, but it didn’t help

React 17 requires “jsx”: “react-jsx”, without this rule it will not run, you need to fix this problem in your plugin, otherwise users will constantly have to manually change this rule to check Sonar

When i trying to analyze .test.tsx file

Trigger: ACTION
[Action] 1 file(s) submitted
No analysis configurators found
Using connection ‘[HIDED]’ for project ‘[HIDED]’
Analysing ‘[HIDED].test.tsx’…
Starting analysis with configuration:
[
projectKey: [HIDED]
baseDir: [HIDED]
extraProperties: {}
inputFiles: [
file:///[HIDED].test.tsx (UTF-8) [test]
]
]

Start analysis
Index files
Language of file ‘file:///[HIDED].test.tsx’ is detected to be ‘TypeScript’
1 file indexed
Available languages:

  • Scala => “scala”
  • Python => “py”
  • Java => “java”
  • HTML => “web”
  • JSP => “jsp”
  • XML => “xml”
  • Kotlin => “kotlin”
  • PHP => “php”
  • TypeScript => “ts”
  • JavaScript => “js”
  • Ruby => “ruby”
    Quality profiles:
  • java: ‘Sonar way extended’ (492 rules)
  • js: ‘Sonar way Recommended’ (128 rules)
  • jsp: ‘Sonar way’ (0 rules)
  • kotlin: ‘Sonar way’ (30 rules)
  • php: ‘Sonar way’ (87 rules)
  • py: ‘Sonar way’ (31 rules)
  • ruby: ‘Sonar way’ (29 rules)
  • scala: ‘Sonar way’ (28 rules)
  • ts: ‘Sonar way recommended’ (112 rules)
  • web: ‘Sonar way’ (18 rules)
  • xml: ‘Sonar way’ (4 rules)
    ‘JavaSquidSensor’ skipped because there is no related file in current project
    ‘Scala Sensor’ skipped because there is no related file in current project
    ‘Python Squid Sensor’ skipped because there is no related file in current project
    Execute Sensor: JavaXmlSensor
    ‘HTML’ skipped because there is no related file in current project
    ‘XML Sensor’ skipped because there is no related file in current project
    ‘Kotlin Sensor’ skipped because there is no related file in current project
    ‘PHP sensor’ skipped because there is no related file in current project
    ‘Analyzer for “php.ini” files’ skipped because there is no related file in current project
    ‘Contextual SonarTS’ skipped because there is no related file in current project
    ‘SonarJS’ skipped because there is no related file in current project
    ‘ESLint-based SonarJS’ skipped because there is no related file in current project
    ‘Ruby Sensor’ skipped because there is no related file in current project
    Done in 24ms

Processed 0 issues in 0 ms
Found 0 issues

Hello Vladislav,

Happy new year!

The “react-jsx” option has been introduced in the Typescript 4.1 version, which I assume you are using. The JS analyzer embeds Typescript 3.8.3, that’s why it doesn’t understand the option and can not run the analysis. We plan to update Typescript to the latest version, but we don’t have an ETA.

One possible temporary workaround would be to duplicate your existing tsconfig.json file. You could then change the “jsx” property to use “react”, and tell the analyzer to use this new tsconfig.json, by using the sonar.typescript.tsconfigPath property. You can configure this value with the scanner as any other property or through SonarLint in Settings > Tools > SonarLint > Project Settings > Analysis properties.

I’m afraid we can’t provide a better alternative for the moment.

About your test files that are not analyzed, using the include should be sufficient (it works for me). It might be related to use of SonarTS, do you observe the same problem when not connected to SonarQube ? Was your company able to update the plugins on SonarQube side ?

3 Likes