Skip to content

Commit

Permalink
fix(no-ignored-replay-buffer): check if bufferSize is set in config o…
Browse files Browse the repository at this point in the history
…ption for shareReplay

Fixes cartant#100
  • Loading branch information
skrtheboss committed May 12, 2023
1 parent c09676b commit 5936c92
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
23 changes: 22 additions & 1 deletion source/rules/no-ignored-replay-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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,
});
}
}
},
};
},
Expand Down
10 changes: 10 additions & 0 deletions tests/rules/no-ignored-replay-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5936c92

Please sign in to comment.