platform icon indicating copy to clipboard operation
platform copied to clipboard

Incorrect behavior of @ngrx/avoid-mapping-selectors lint rule

Open yurakhomitsky opened this issue 3 years ago • 2 comments

Minimal reproduction of the bug/regression with instructions

image

Minimal reproduction of the bug/regression with instructions

  1. install ngrx-eslint-plugin: "@ngrx/eslint-plugin": "^14.0.2",
  2. add to eslint config : extends: ['plugin:@ngrx/recommended'],
  3. Use this.store.select(selector).pipe(switchMap, map)
  4. Note warning

Expected behavior there should not be a warning if there is an operator that changes the stream before the map

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

Ngrx: 13.1.0 Angular: 13.3.2 Node: 16.15.0

Other information

No response

I would be willing to submit a PR to fix this issue

  • [ ] Yes
  • [X] No

yurakhomitsky avatar Aug 04 '22 09:08 yurakhomitsky

Could you elaborate this use case a bit more please? In the snippet shown, the map that's giving the error isn't doing anything with the selector's result, so I would move it to the map logic of the switchMap.

timdeschryver avatar Aug 05 '22 12:08 timdeschryver

@timdeschryver, sorry for the lousy screenshot, here is another one. In my case, the map logic could be moved to switchMap's map.

However what if the logic in the switchMap's map would be hard to read and I would want to move it to a separate map

I was thinking about whether it is possible to not show a warning if there is a switchMap/mergeMap before the map operator in the store selector pipe chain.

image

yurakhomitsky avatar Aug 05 '22 13:08 yurakhomitsky