SonarQube
Enterprise Edition Version 8.3.1 (build 34397)
what are you trying to achieve
I am trying to get and Angular project to be succesfully analyzed by SonarQube. We have a standard structure (with tsconfig, tslint and everything else being in the root of the project directory). Even though SonarQube finds the tsconfig.json file, it keeps ignoring all of the typescript files in the project and it is only analyzing the html, css and javascript ones.
what have you tried so far to achieve this
I have looked into similar threads regarding this issue, I have tried changing the base path of the sources directory to no avail.
Logs:
INFO: Sensor TypeScript analysis [javascript]
INFO: Using TypeScript at: '/home/ubuntu/azure-agent/_work/1/s/node_modules'
INFO: Found 1 tsconfig.json file(s): [/home/ubuntu/azure-agent/_work/1/s/tsconfig.json]
INFO: 218 source files to be analyzed
INFO: Skipping 218 files with no tsconfig.json
INFO: 218/218 source files have been analyzed
INFO: Sensor TypeScript analysis [javascript] (done) | time=3775ms
What exactly do I need to do here in order to solve this issue? Thank you!
I’ve just had this one within an ADO Pipeline, the solution seems to be to explicitly point to tsconfig.json. In a SonarQubePrepare@4 task it is possible to define extraProperties, and there one can put sonar.typescript.tsconfigPath=./tsconfig.json (or wherever it is)
Sadly, I did try every possible path for the tsconfig and the sources directory path. It does find the tsconfig file it just choses to ignore it for some reason.
Since you are using enterprise edition, maybe you have a direct contact with support from SonarSource people? Would be interesting to know what do they say…
But even if I pass the tsconfig.app.json (the one with the entrypoints), sonarqube is unable to parse the entry points and as such ignores everything except main.ts and polyfills.ts.
What is an estimate for when this is going to be officially supported (as this is how Angular 10 and Typescript 3.9 have their config files going onwards)? @Lena
If the provided config is tsconfig.app.json, sonarqube will only find the two files in the files array because it cannot parse the entrypoints looking for more files. This in now the standard way that angular will structure the tsconfig (into 3 or more files if tests are included and what not, the root being the regular tsconfig, the so called solution tsconfig). I presume sonarJS needs to be updated to parse that reference tsconfig or at least the tsconfig.app.json one.
In all examples I found references is used to list other tsconfig files. Why are you using extends?
I believe extends should be supported out of the box, but as you have files defined, this list of files is considered final (parent tsconfig is not taken into consideration).
Could you clarify how your 2 tsconfigs define actual list of project files?
All three files were created by the Angular CLI, including the extends from the tsconfig.app.json. Nothing from these is “custom made”.
As per what tsconfig we are pointing sonar to, I have tried either the solution style one tsconfig.json (with the references - not working at all) and the tsconfig.app.json from above (which only gets us two files).
FYI here is a potential workaround that seems to be working for me. I create a special tsoncofig, tsconfig.sonar.json and point sonarqube explicitly to that. In the file I put
/*
This is tsconfig is not used for compilation. It is here to support sonarqube.
*/
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"rootDir": "src"
}
}
I think one of the keys is inheriting the base and including the rootDir. It would definitely be nice if sonarqube could properly handle the angular tsconfig out of the box though.
The issue 2051 is reported as fixed in 6.4 version of SonarJS and yet we are observing the same. We have Angular 10.0 project, SonarQube 8.5.1 (with bundled SonarJS 6.5.0). The sensor excludes all ts files but two. The workaround provided by @chriswininger helps though, thank you
INFO: Sensor TypeScript analysis [javascript]
INFO: Found 2 tsconfig.json file(s): [/home/vsts/work/1/s/tsconfig.json, /home/vsts/work/1/s/e2e/tsconfig.json]
INFO: 171 source files to be analyzed
INFO: Skipping 168 files with no tsconfig.json
INFO: Analyzing 2 files using tsconfig: /home/vsts/work/1/s/tsconfig.app.json
INFO: Version of TypeScript used during analysis: 3.8.3
INFO: Analyzing 1 files using tsconfig: /home/vsts/work/1/s/tsconfig.spec.json
INFO: 171/171 source files have been analyzed
INFO: Sensor TypeScript analysis [javascript] (done) | time=6646ms