SonarCloud Automatic Analysis Typescript LOC ignored

  • Github
  • Automatic Analysis
  • Typescript
  • The LOC of most typescript files is not represented in the overall LOC of the project, the single files do have the LOC measurement available when navigating on them, but already one level higher the LOC is represented as “–”. The whole LOC of the project is way too low. I also suspect, that most .ts files are not scanned properly at all.
  • Background Task: AYNB4Vx0wbqM-Aedui2I
  • According to other reports in this forum i suspect it is because of the automatic analysis, custom npm packages, tsconfigs from custom npm packages or something similar when not having an npm installed setup while analysing.
  • So my questions are, whats the error on the background task? Is the automatic analysis running npm install on the root folder? What are the requirements for a typescript project to be scannable?
  • Alternative: I’ll use Github Actions to scan

Hey there.

How is the root tsconfig.json file configured for this project? Feel free to share it here.

there is no root tsconfig.json

Okay. How are you compiling your Typescript code without a tsconfg.json file? Is it just a repository of raw Typescript files?

It is a mono repo, all “real” projects are under packages/projectA etc.
In those subfolders there is a tsconfig.json

Okay! That’s fine. Can you give an example of one of those, of a project in the monorepo you expect to be analyzed?

{
  "extends": "./node_modules/@css-ch/mycss-utility-lib/lib/config/tsconfig-angular.json",
  "exclude": [
    "**/dist/**/*"
  ],
  "compilerOptions": {
    "resolveJsonModule": true,
    "esModuleInterop": true
  }
}

Okay. It looks like indeed, the issue is that your tsconfg.json file extends from a file that only exists if dependencies has been fetched… which Automatic Analysis will not do for you.

This means switching to CI-based analysis would be necessary, where you’ve run your npm install or similar.

We’ve run into this case more than a few times. I’lll flag this for some expert attention (to see if we can at least document something better, if not fix the root problem).

1 Like

Ok thank you, we just implemented the github actions approach, which works as expected.

One thing is a bit strange:

  • We still have automatic analysis enabled on the root project, excluded packages/projectX etc. to be able to analyse the root without the pipeline (because we have no typescript code there, just config files, IaC, Pipeline etc.)
  • But since we excluded the packages/** the analysis is never refreshed even when we push things to the main, i’m wondering, if it is because there is nothing to analyse, or if there is another issue
  • I would expect sonar to update the main project with 0 files and everything A etc. after this update, but it seems like everything is skipped and therefore never updated

Hi @rfe-css,

You should be able to perform all of the analysis in the Github Action, disable Automatic Analysis, and remove the excluded packages/**. This should fix the issue you are encountering.

We are looking into improving this experience, as it not might be easy to know what to do when this happens.

Best,
Gabriel

Sadly it is not possible to disable automatic analysis for the project, trying leads to 500 error

Hey there.

It sounds like a known bug where a project is converted to a monorepo after automatic analysis has already run – take a look at this thread:

2 Likes

Ok thank you, removed the “root” project and recreated it as monorepo which did work. :+1:

1 Like

Sure thing. I’ll push a bit internally to get this bug looked at.

1 Like