Typescript deprecation false-positives

Template for a good false-positive report, formatted with Markdown:

  • versions used: SonarCloud, SonarScanner 4.4.0 (tried 4.6.0-2311 and that didn’t help)

  • minimal code sample to reproduce (with analysis parameter, and potential instructions to compile).

import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';


@Component({
  selector: 'sonar-rxjs-issue-demo',
  template: '<h1>Hello World!</h1>'
})
export class SonarRxJSIssueDemoComponent {

  constructor(private http: HttpClient) {
  }

  method1() {
    this.http.get('/api/some-url')
      .subscribe(() => console.log('Next1'));// shouldn't be marked as deprecated https://github.com/ReactiveX/rxjs/blob/6.6.3/src/internal/Observable.ts#L80
  }

  method2(): void {
    this.http.get('/api/some-url')
      .subscribe({ next: () => console.log('Next2') }); // shouldn't be marked as deprecated https://github.com/ReactiveX/rxjs/blob/6.6.3/src/internal/Observable.ts#L73
  }
}

This afternoon (3/26/21), my pipelines started to suddenly fail due to a sudden increase in Sonar issues with my Typescript code (Angular 11.0.8 with RxJs 6.6.3). Looks like the scanner started to flag any use of the subscribe method of the RxJS observable class as issues (Deprecated APIs should not be used, minor code smell).

Tried to change things around and noticed this is affecting all uses of the subscribe method overloads, even the non-deprecated ones. Found this thread that mentioned something similar (Unexpected deprecation warnings reported - #3 by JounQin), and from what I can tell the related SonarJS change was released today (related to my issue? not sure).

I was originally running TypeScript 4.0.5 and tried to upgrade to 4.2.3 and that didn’t help. Also tried to upgrade my sonar-scanner to 4.6.0, which also didn’t help.


Can you look into this and advise on how to resolve it?

Thanks.
edit: grammar and formatting

2 Likes

I had the same problem, but It fixed alone. Today we get the same problem. What’s wrong?

Hello,

I think it’s because of new versión of sonar-javascript-plugin that references to typescript 4.2.3.
Wich version have your Sonarcloud of this plugin? You could try with prior versions.

See this links:

I have the same problem. Does anybody know how to fix it?

1 Like

Same problem.
Can anyone officially confirm if this is really a false alarm?

And when is it getting resolved?

Same situation here.

I ran my builds again over this past weekend and not seeing the failures anymore. Definitely didn’t change anything on my build servers (though npm install did get rerun), so thinking that SonarCloud silently fixed the issue? Not really sure, given that it seems that some other users are still affected.

It’s not solved at our side - still reproduced.

Hello there,

Sorry for the long delay.

First thing first, let me give you some context about the issue magically disappearing and coming back. SonarCloud experienced an incident on March 26, which was the reason why you guys observed these weird occurrences.

Coming back to the original problem, I didn’t manage to reproduce the false-positive with the code snippet provided. The JavaScript analyzer uses TypeScript compiler under the hood. As a result, a tsconfig file (especially the compiler options part) might impact the behaviour of the rule.

It’s only a possibility, but I would like to start the investigation with that first. @bahizi Would you mind sharing such a file ?

Best,
Yassin

Thanks for the additional context, @Yassin_Kammoun. I think the 03/26/21 incident you mentioned is what affected my builds as I haven’t been able to reproduce the issue for weeks now.

Still, below is my main tsconfig.json file in case those still encountering the issue would like to compare.

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "esModuleInterop": true,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
  },
  "exclude": ["node_modules", "tmp"]
}

Is our main tsconfig.json file. And we still have this problem.

    {

      "compileOnSave": false,

      "compilerOptions": {

        "baseUrl": "./",

        "outDir": "./dist/out-tsc",

        "sourceMap": true,

        "declaration": false,

        "downlevelIteration": true,

        "experimentalDecorators": true,

        "moduleResolution": "node",

        "resolveJsonModule": true,

        "importHelpers": true,

        "target": "es2015",

        "module": "es2020",

        "lib": ["es2018", "dom"]

      }

    }

Hello Yulia,

I apologise for the delay in coming back to you.

The JavaScript analyser currently deployed on SonarCloud uses a more recent version of TypeScript since your post, namely TypeScript 4.3.2. It’s not impossible that this solved your problem. Give it a try and analyze again your project on SonarCloud. If these false positives are stil raised, please share a minimal code snippet that reproduces the problem.

Regards,
Yassin

Thank you, the issue was solved.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.