Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
fix(avoid-mapping-selectors): allow ThisExpression in map (#287)
Browse files Browse the repository at this point in the history
Resolves #285
  • Loading branch information
timdeschryver committed Mar 26, 2022
1 parent 0c7da0c commit a0a3d87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/store/avoid-mapping-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default createRule<Options, MessageIds>({
)}[callee.object.callee.property.name='select']` as const

return {
[`:matches(${selectSelector}, ${pipeWithSelectAndMapSelector}) > CallExpression[callee.name='map']`](
[`:matches(${selectSelector}, ${pipeWithSelectAndMapSelector}) > CallExpression[callee.name='map']:not(:has(ThisExpression))`](
node: TSESTree.CallExpression,
) {
context.report({
Expand Down
13 changes: 13 additions & 0 deletions tests/rules/avoid-mapping-selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ export class CollectionService {
}
}
`,
// https://github.com/timdeschryver/eslint-plugin-ngrx/issues/285
`
import { Store } from '@ngrx/store'
class OkBecauseOfThis {
foo$ = this.store.select(selectIsAuthenticated).pipe(
take(1),
map((isAuthenticated: boolean) => (isAuthenticated ? true : this.router.parseUrl('/login'))),
)
constructor(private store: Store) {}
}`,
]

const invalid: () => RunTests['invalid'] = () => [
Expand Down

0 comments on commit a0a3d87

Please sign in to comment.