From 5936c92af6a1d8a25b76e814dfe0dfac63131f6f Mon Sep 17 00:00:00 2001 From: skrtheboss Date: Fri, 12 May 2023 17:40:13 +0200 Subject: [PATCH] fix(no-ignored-replay-buffer): check if bufferSize is set in config option for shareReplay Fixes #100 --- source/rules/no-ignored-replay-buffer.ts | 23 ++++++++++++++++++++++- tests/rules/no-ignored-replay-buffer.ts | 10 ++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/source/rules/no-ignored-replay-buffer.ts b/source/rules/no-ignored-replay-buffer.ts index 1bb286ee..f785c1de 100644 --- a/source/rules/no-ignored-replay-buffer.ts +++ b/source/rules/no-ignored-replay-buffer.ts @@ -3,7 +3,10 @@ * can be found in the LICENSE file at https://github.com/cartant/eslint-plugin-rxjs */ -import { TSESTree as es } from "@typescript-eslint/experimental-utils"; +import { + AST_NODE_TYPES, + TSESTree as es, +} from "@typescript-eslint/experimental-utils"; import { getParent } from "eslint-etc"; import { ruleCreator } from "../utils"; @@ -56,6 +59,24 @@ const rule = ruleCreator({ ) => { const callExpression = getParent(node) as es.CallExpression; checkNode(node, callExpression); + + const shareReplayConfig = callExpression.arguments[0]; + + if (shareReplayConfig?.type === AST_NODE_TYPES.ObjectExpression) { + const bufferSizeProp = shareReplayConfig.properties.find( + (p) => + p.type === AST_NODE_TYPES.Property && + p.key.type === AST_NODE_TYPES.Identifier && + p.key.name === "bufferSize" + ); + + if (!bufferSizeProp) { + context.report({ + messageId: "forbidden", + node, + }); + } + } }, }; }, diff --git a/tests/rules/no-ignored-replay-buffer.ts b/tests/rules/no-ignored-replay-buffer.ts index 6f764f6d..061c4e4e 100644 --- a/tests/rules/no-ignored-replay-buffer.ts +++ b/tests/rules/no-ignored-replay-buffer.ts @@ -127,6 +127,16 @@ ruleTester({ types: false }).run("no-ignored-replay-buffer", rule, { ~~~~~~~~~~~ [forbidden] ` ), + fromFixture( + stripIndent` + // namespace shareReplay ignored + import * as Rx from "rxjs"; + import { shareReplay } from "rxjs/operators"; + + const a = Rx.of(42).pipe(shareReplay({ refCount: 1 })); + ~~~~~~~~~~~ [forbidden] + ` + ), fromFixture( stripIndent` // namespace class ignored