Skip to content

Commit 4b0c6de

Browse files
fix(eslint-plugin): avoid-combining-selectors with arrays should warn (#3566)
Closes #3566
1 parent aa46bbc commit 4b0c6de

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

modules/eslint-plugin/spec/rules/avoid-combining-selectors.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ class NotOk {
8080
`
8181
import { Store } from '@ngrx/store'
8282
83+
class NotOkWithArrays {
84+
readonly vm$: Observable<unknown>
85+
86+
constructor(store: Store, private store2: Store) {
87+
this.vm$ = combineLatest([
88+
store.select(selectItems),
89+
store.select(selectOtherItems),
90+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
91+
this.store2.select(selectOtherItems),
92+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
93+
])
94+
}
95+
}`
96+
),
97+
fromFixture(
98+
`
99+
import { Store } from '@ngrx/store'
100+
83101
class NotOk1 {
84102
vm$ = combineLatest(
85103
this.store.pipe(select(selectItems)),
@@ -94,6 +112,20 @@ class NotOk1 {
94112
`
95113
import { Store } from '@ngrx/store'
96114
115+
class NotOkWithArray {
116+
vm$ = combineLatest([
117+
this.store.pipe(select(selectItems)),
118+
this.store.pipe(select(selectOtherItems)),
119+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]
120+
])
121+
122+
constructor(private store: Store) {}
123+
}`
124+
),
125+
fromFixture(
126+
`
127+
import { Store } from '@ngrx/store'
128+
97129
class NotOk2 {
98130
vm$ = combineLatest(
99131
this.customName.select(selectItems),

modules/eslint-plugin/src/rules/store/avoid-combining-selectors.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,21 @@ export default createRule<Options, MessageIds>({
4242
storeNames
4343
)})` as const;
4444

45+
const selectsInArray: TSESTree.CallExpression[] = [];
4546
return {
46-
[`CallExpression[callee.name='combineLatest'][arguments.length>1] ${pipeableOrStoreSelect} ~ ${pipeableOrStoreSelect}`](
47+
[`CallExpression[callee.name='combineLatest'] ${pipeableOrStoreSelect} ~ ${pipeableOrStoreSelect}`](
4748
node: TSESTree.CallExpression
4849
) {
49-
context.report({
50-
node,
51-
messageId,
52-
});
50+
selectsInArray.push(node);
51+
},
52+
[`CallExpression[callee.name='combineLatest']:exit`]() {
53+
for (const node of selectsInArray) {
54+
context.report({
55+
node,
56+
messageId,
57+
});
58+
}
59+
selectsInArray.length = 0;
5360
},
5461
};
5562
},

0 commit comments

Comments
 (0)