SonarLint IntelliJ + Typescript

Hi, I have problems with IntelliJ and latest sonarLint plugin (4.7).
I installed Typescript globally
npm install -g typescript
and set the NODE_PATH
setx NODE_PATH %AppData%\npm\node_modules
but the plugin can’t find node.js
“Node.js >= 8.x is required to perform JavaScript or TypeScript analysis. Check the SonarLint Log for details.”
or tsconfig.json
org.sonarsource.nodejs.NodeCommandException: No tsconfig.json file found, analysis will be stopped.

Hello, thanks for reporting this.

Could you please enable “Analysis logs” and “Verbose output” on the SonarLint console, and post here (between ``` characters) what is logged the first time you open a .js or .ts file?

Also, when does this happen? Does your project structure contain a tsconfig.json?

Is SonarLint console available on IntelliJ or on on Eclipse?

Yes, as described in the SonarLint FAQ, you will find it:

  • In IntelliJ, in the “Log” tab of the “SonarLint” Tool Window

  • In Eclipse, in the “Console” View

Language of file 'file:///C:/project/src/app/app.module.ts' is detected to be 'ts'
1 file indexed
'JavaSquidSensor' skipped because there is no related file in current project
'Python Sensor' skipped because there is no related file in current project
Execute Sensor: JavaXmlSensor
Execute Sensor: HTML
'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
'JavaScript analysis' skipped because there is no related file in current project
Execute Sensor: TypeScript analysis
SonarJS eslint-bridge server is up, no need to start.
Found 0 tsconfig.json file(s): []
Generating temporary tsconfig is not supported in SonarLint context.
No tsconfig.json file found, analysis will be stopped.
org.sonarsource.nodejs.NodeCommandException: No tsconfig.json file found, analysis will be stopped.
	at org.sonar.plugins.javascript.eslint.TypeScriptSensor.tsConfigs(TypeScriptSensor.java:164)

and the tsconfig.json is to find under file:///C:/project/tsconfig.json

Thank you for the details.

This is… Unfortunate and unexpected :sweat_smile:. I am starting to wonder whether the tsconfig.json is outside of the directory structure that is visible in the IDE - which could explain why the TypeScript analyzer is not able to locate it.

Which directory is the base directory of your project in the IDE?

Additionally, could you please provide the following info:

  • IDE and version
  • Whether your project uses connected mode or not
  • If connected mode is used, versions of the server and of the plugins installed on the server

Finally, if the tsconfig.json's location is indeed outside of the project’s base directory, you should be able to set its location through the sonar.typescript.tsconfigPath property (Settings > Tools > SonarLint > Project Settings > Analysis properties).

The project structure is:
C:/project/module1/src/app/app.module.ts
C:/project/module1tsconfig.json
C:/project/module1angular.json
C:/project/module2/src/app/app.module.ts
C:/project/module2tsconfig.json
C:/project/module2angular.json

I’ve imported more modules in my project.
and so far…

IDE IntelliJ Ultimate 2020.1.1
not connected mode
And indeed when I set the property sonar.typescript.tsconfigPath manually the sonar lint started to work with ts files.

I have the same issue, it seems to be related to IntelliJ dev environments located somewhere different than the projects. For me for example, the scenario looks like this:
My IntelliJ dev environment is located at c:\devenvs\intellij, while my project is at c:\repos\project. Note that there are a total of 43 tsconfig.json files in this project. Sonarlint logs this (I already had to manually configure the typescript location, otherwise it would’ve taken the built-in one):

Starting analysis with configuration:
[
  projectKey: com.dynatrace.oneagent:javascript
  baseDir: C:\devenvs\intellij
  extraProperties: {sonar.java.target=8, sonar.java.source=8, sonar.typescript.internal.typescriptLocation=c:\repos\project\node_modules}
  inputFiles: [
    file:///C:/repos/project/source/somefile.ts (UTF-8)
  ]
]
[... some useless stuff ...]
Execute Sensor: TypeScript analysis
SonarJS eslint-bridge server is up, no need to start.
Found 0 tsconfig.json file(s): []
Generating temporary tsconfig is not supported in SonarLint context.
No tsconfig.json file found, analysis will be stopped.

Let me also state that, if I manually configure the root tsconfig.json, it always says that:

Using c:\repos\project\tsconfig.json from sonar.typescript.tsconfigPath property
C:/repos/project/source/file.ts matched NO_CONFIG
1 source files to be analyzed
Skipping 1 files with no tsconfig.json

For me, it worked by fixing proxy. SonarLint could connect to central SonarQube server. Sonarlint version 5.3 and NodeJS 12.16.3.

@DerGernTod, are you still having the problem with the latest version of SonarLint?