Sudden increase of false positives for S4325 (Redundant casts should be avoided)

  • ALM used : Azure DevOps
  • CI system used : Azure DevOps
  • Languages of the repository : C#, TypeScript

Since June 19, we noticed a sudden increase of code smells in our TypeScript project (from 23 to 84), most of them seem to be false positives for S4325.
And all of our Pull requests get a lot of warnings for those issues.

Instructions like this would trigger it :
const val : Result = state.evaluationResult?.result as Result

We think this is a false positive as state.evaluationResult?.result would be of type Result | undefined and compiler (in strict mode) will refuse to set it to val without cast.

Did you change anything to the rule ?
I don’t see any change to our pipeline.

UPDATE : Something changed: there are way less log lines this week than previous week.
But versions of the task and scanner are identical (SonarScanner

Analyzer logs startup are:

INFO: Sensor JavaScript analysis [javascript]
INFO: Creating TypeScript program
INFO: 1 source file to be analyzed
INFO: TypeScript configuration file C:\a\3\s\.scannerwork\.sonartmp\2361194183431520906.tmp
INFO: Creating TypeScript program (done) | time=1594ms
INFO: Starting analysis with current program
INFO: Analyzed 1 file(s) with current program
INFO: 1/1 source file has been analyzed
INFO: Hit the cache for 0 out of 1
INFO: Miss the cache for 1 out of 1: FILE_CHANGED [1/1]
INFO: Sensor JavaScript analysis [javascript] (done) | time=15251ms

And then logs seems to loop around tsconfig.json files found
(we are using NX with libs, we have several of those for each lib) with a lot of logs like this:

INFO: Creating TypeScript program
INFO: TypeScript configuration file ...\tsconfig.json
INFO: Creating TypeScript program (done) | time=2860ms
INFO: Starting analysis with current program
INFO: 122/613 files analyzed, current file: xxx.ts
INFO: Analyzed 263 file(s) with current program

But now it seems to scan everything as one set

INFO: Sensor JavaScript/TypeScript analysis [javascript]
INFO: 618 source files to be analyzed
INFO: 8/618 files analyzed, current file: ....ts
INFO: 617/618 files analyzed, current file: ....ts
INFO: 618/618 source files have been analyzed
INFO: Hit the cache for 0 out of 618
INFO: Miss the cache for 618 out of 618: FILE_CHANGED [618/618]
INFO: Sensor JavaScript/TypeScript analysis [javascript] (done) | time=355290ms

Our Sonar task :

  - task: SonarCloudPrepare@1
    displayName: "Prepare UI analysis on SonarCloud"
      workingDir: "Front"
      SonarCloud: "..."
      organization: "..."
      scannerMode: CLI
      configMode: manual
      cliProjectKey: ${{parameters.module_name}}
      cliProjectName: ${{parameters.module_name}}
      cliProjectVersion: $(Build.BuildNumber)
      extraProperties: |

Okay, I think I found the issue, thanks to this topic.

Adding the configuration sonar.typescript.tsconfigPaths to point to the root config file seemed to fix my issue.

I think all people using NX will have that issue, you should communicate a bit about that !


Hi @Julien_N,

thanks for your feedback. Indeed last changes seem to have affected projects with several tsconfigs. Happy to read the workaround is working for you. We are discussing internally to have a bugfix release ASAP.

Sorry for the inconvenience,