Disallow using ReplaySubject, publishReplay or shareReplay without specifying the buffer size (rxjs-x/no-ignored-replay-buffer)

April 18, 2025 ยท View on GitHub

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, ๐Ÿ”’ strict.

This rule effects failures if the buffer size of a replay buffer is not explicitly specified.

Rule details

Examples of incorrect code for this rule:

import { ReplaySubject } from "rxjs";
const subject = new ReplaySubject<number>();
import { of, shareReplay } from "rxjs";
of(42).pipe(shareReplay({ refCount: true }));

Examples of correct code for this rule:

import { ReplaySubject } from "rxjs";
const subject = new ReplaySubject<number>(1);
import { ReplaySubject } from "rxjs";
const subject = new ReplaySubject<number>(Infinity);
import { of, shareReplay } from "rxjs";
of(42).pipe(shareReplay({ refCount: true, bufferSize: 1 }));

When Not To Use It

If you don't care about implicitly defaulting to Infinity in your replay buffers, then you don't need this rule.

Resources