Skip to content

Rule idea: no-unnecessary-combinelatestΒ #107

@bmarcotte

Description

@bmarcotte

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(...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions