Skip to content

Commit b9d40ff

Browse files
authored
Create no-nested-pipe.ts
this is just new rule created based on the no-nested-subscribe, in our code we found this one of big issue when its making code complex and have certain issue as well so we wanted to avoid nested pipe in the code currently there is not other solution available in the next
1 parent c09676b commit b9d40ff

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

source/rules/no-nested-pipe.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @license Use of this source code is governed by an MIT-style license that
3+
* can be found in the LICENSE file at https://github.com/cartant/eslint-plugin-rxjs
4+
*/
5+
6+
import { TSESTree as es } from "@typescript-eslint/experimental-utils";
7+
import { getParent, getTypeServices } from "eslint-etc";
8+
import { ruleCreator } from "../utils";
9+
10+
const rule = ruleCreator({
11+
defaultOptions: [],
12+
meta: {
13+
docs: {
14+
description: "Forbids the calling of `pipe` within a `pipe` callback.",
15+
recommended: "error",
16+
},
17+
fixable: undefined,
18+
hasSuggestions: false,
19+
messages: {
20+
forbidden: "Nested pipe calls are forbidden.",
21+
},
22+
schema: [],
23+
type: "problem",
24+
},
25+
name: "no-nested-pipe",
26+
create: (context) => {
27+
const { couldBeObservable, couldBeType } = getTypeServices(context);
28+
const argumentsMap = new WeakMap<es.Node, void>();
29+
return {
30+
[`CallExpression > MemberExpression[property.name='pipe']`]: (
31+
node: es.MemberExpression
32+
) => {
33+
if (
34+
!couldBeObservable(node.object) &&
35+
!couldBeType(node.object, "Pipeable")
36+
) {
37+
return;
38+
}
39+
const callExpression = getParent(node) as es.CallExpression;
40+
let parent = getParent(callExpression);
41+
while (parent) {
42+
if (argumentsMap.has(parent)) {
43+
context.report({
44+
messageId: "forbidden",
45+
node: node.property,
46+
});
47+
return;
48+
}
49+
parent = getParent(parent);
50+
}
51+
for (const arg of callExpression.arguments) {
52+
argumentsMap.set(arg);
53+
}
54+
},
55+
};
56+
},
57+
});
58+
59+
export = rule;

0 commit comments

Comments
 (0)