Skip to content

Commit 568dbe3

Browse files
authored
fix(eslint-plugin): only lint NgRx selectors in prefix-selectors-with-select (#4995)
Closes #4447
1 parent c1f4fc5 commit 568dbe3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

modules/eslint-plugin/spec/rules/store/prefix-selectors-with-select.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ const valid: () => (string | ValidTestCase<Options>)[] = () => [
4545
`
4646
const { selectItems, ...rest } = getSelectors(adapter);
4747
`,
48+
// Issue #4447: Should not flag custom types that end with 'Selector' but are not NgRx selectors
49+
`type RowSelector<T> = { row: T };
50+
interface ItemData {
51+
id: number;
52+
name: string;
53+
active: boolean;
54+
}
55+
const item: RowSelector<ItemData> = {
56+
row: {
57+
id: 1,
58+
name: 'Test',
59+
active: false,
60+
},
61+
};`,
62+
`
63+
interface CustomSelector {
64+
data: string;
65+
}
66+
const config: CustomSelector = { data: 'test' };
67+
`,
4868
];
4969

5070
const invalid: () => InvalidTestCase<MessageIds, Options>[] = () => [

modules/eslint-plugin/src/rules/store/prefix-selectors-with-select.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@ export default createRule<Options, MessageIds>({
158158
: null;
159159

160160
const hasSelectorType =
161-
typeName !== null && /Selector$/.test(typeName);
161+
typeName !== null &&
162+
[
163+
'MemoizedSelector',
164+
'MemoizedSelectorWithProps',
165+
'Selector',
166+
'SelectorWithProps',
167+
].includes(typeName);
162168

163169
const isSelectorCall =
164170
init?.type === 'CallExpression' && isSelectorFactoryCall(init);

0 commit comments

Comments
 (0)