TS - Skipping files with no tsconfig.json

  • 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 have the same problem with SonarCloud and Azure DevOps with the SonarCloud extencion.

Did you manage to somehow fix this issue @pidmad92? Did anyone else perhaps encountered this issue or knows more about it? @Lena

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)

I guess should also work if set globally in the sonarqube as here: https://github.com/SonarSource/SonarTS/issues/803

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…

Sadly, we do not have any support included in our enterprise package. Not sure what anything else to try.

The issue seem to be caused by https://devblogs.microsoft.com/typescript/announcing-typescript-3-9/#solution-style-tsconfig.

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

Hi,

Could you share the content of your tsconfig file(s)?

FYI when we find at least one tsconfig file in the project we ask TypeScript compiler to provide list of files matching that tsconfig.

Hey Elena,

As we are using the solution style config from typescript, this the content of our tsconfig.app.json:

{
  "compilerOptions": {
    "outDir": "./out-tsc/app"
  },
  "extends": "./tsconfig.base.json",
  "files": ["src/main.ts", "src/polyfills.ts"],
  "include": ["src/type-definitions/*.d.ts"]
}

and tsconfig.base.json:

{
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  },
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "lib": ["es2018", "dom"],
    "module": "esnext",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "strict": true,
    "target": "es2015",
    "typeRoots": ["node_modules/@types"]
  }
}

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.

Thanks :smiley:

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?

Hey Elena,

We are using references to list other tsconfig files but I did not post that configuration as it is the basic one:

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    }
  ]
}

All three files were created by the Angular CLI, including the extends from the tsconfig.app.json. Nothing from these is “custom made”. :smiley:

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).

1 Like

Hi again

we’ve created this ticket https://github.com/SonarSource/SonarJS/issues/2051 to target this new project style.

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.