eslint-plugin-rxjs
eslint-plugin-rxjs copied to clipboard
Rule idea: no-unnecessary-combinelatest
One issue that we keep finding in our codebase (a surprisingly large number of times): using combineLatest for only one observable. Usually, it's the result of refactoring code, that originally had multiple observables passed in, until it has only one left, but then forgetting to remove the combineLatest.
For example, code like this:
combineLatest([
this.fooService.get$(),
this.barService.get$()
]).subscribe(...)
...often gets refactored into something like this:
combineLatest([
this.fooBarService.get$()
]).subscribe(...)
...and then we'll forget to remove the now unnecessary combineLatest call. If this plugin could somehow flag occurrences of the latter, it would be a huge help to us.
FYI, to help avoid edge cases, this would still be valuable to us even if it is was limited to only checking when combineLatest is declared with an array literal, like above, and should skip checking if an array variable is passed in, since that might not have a checkable length until runtime. e.g.:
observables = [of(1)];
combineLatest(observables).subscribe(...)