Skip to content

The rule "@ngrx/prefix-selectors-with-select" sometimes crashes ESLint when checking destructured selectors from an adaptor's getSelectors method #4845

Open
@WDaleCP

Description

@WDaleCP

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

eslint-plugin

Minimal reproduction of the bug/regression with instructions

When I run the ng lint command in my project, the process errors with the following message:

Error when running ESLint: Cannot read properties of undefined (reading 'replace')
Occurred while linting C:\...\src\app\state\books.selector.ts:11
Rule: "@ngrx/prefix-selectors-with-select"

It appears that this error occurs due to a particular pattern where a selectAll selector is created with an entity adapter's getSelectors method, specifically when createSelector is used in the method's argument:

export const { selectAll: selectAllBooks } = booksAdapter.getSelectors(createSelector(selectBookInfo, (state) => state.books));

The process error does not occur if the value of the createSelector is stored in a variable before being used as an argument. The following is the code from the entire selector file:

import { createSelector, createFeatureSelector } from '@ngrx/store';
import { booksAdapter, BooksState } from './books.reducer';

export const selectBookInfo = createFeatureSelector<BooksState>('bookInfo');

export const { selectAll: selectAllBooks } = booksAdapter.getSelectors(createSelector(selectBookInfo, (state) => state.books));

Expected behavior

The linter should evaluate this selector creation regardless of whether a variable or a function call is passed into the getSelectors method.

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

NgRx store/entity/eslint-plugin: 19.2.1
Angular: 19.2.15
Node: 22.16.0
Browser: N/A
Operating system: Windows 11

Other information

No response

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

  • Yes
  • No

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions