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.
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.
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.
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 ?
Thanks for the additional context, @Yassin. 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.
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.