ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
7.96k stars 1.95k forks source link

false positive for rule @ngrx/no-multiple-actions-in-effects #4409

Closed FabienDehopre closed 1 week ago

FabienDehopre commented 2 weeks ago

Which @ngrx/* package(s) are the source of the bug?

eslint-plugin

Minimal reproduction of the bug/regression with instructions

export const saveSearchCriteria$ = createEffect(
  (actions$ = inject(Actions$), store = inject(Store), saveLoadService = inject(SaveLoadService)) => {
    return actions$.pipe(
      ofType(SearchCriteriaActions.save),
      concatLatestFrom(() => store.select(inventoryFeature.selectInventoryItems)),
      concatMap(([{ searchCriteriaName }, inventoryItems]) => {
        const tags = Object.keys(inventoryItems)
          .filter((inventoryType) => {
            const [, inventorySearchType] = splitInventoryType(inventoryType as InventoryType);
            // eslint-disable-next-line @ngrx/no-multiple-actions-in-effects -- false positive
            return inventorySearchType === 'costCenter' || inventorySearchType === 'wbs';
          })
          .map((inventoryType) => splitInventoryType(inventoryType as InventoryType))
          .map(([value, type]) => ({ value, type }));
        return saveLoadService.saveSearch(searchCriteriaName, tags, false).pipe(
          map(() => SearchCriteriaActions.saveSucceeded()),
          catchError((error: Error) => {
            if (error instanceof HttpErrorResponse && error.status === 409) {
              return of(SearchCriteriaActions.saveAlreadyExists({ searchCriteriaName, tags }));
            }

            return defaultErrorHadnler(error, 'inventoryDomain.messages.saveSearchFailed', SearchCriteriaActions.saveFailed());
          })
        );
      })
    );
  },
  { functional: true }
);

Expected behavior

the line under the // eslint-disable-next-line @ngrx/no-multiple-actions-in-effects -- false positive should not trigger the no-multiple-actions-in-effects rule.

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

NgRx: 18.0.0 Angular: 18.0.4 Node: 20.14.0

Other information

No response

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

FabienDehopre commented 2 weeks ago

The code is coming from a private Azure DevOps repo. I can try to provide a public github repo if you really require it.

timdeschryver commented 1 week ago

Thanks for the reproduction @FabienDehopre , it helped to fix this issue. 👍