Skip to content

Add ESLint rule to prevent Observable-returning method calls in the async pipe (#5933)#5934

Open
Aryakoste wants to merge 1 commit into
DSpace:mainfrom
Aryakoste:esLint-rule
Open

Add ESLint rule to prevent Observable-returning method calls in the async pipe (#5933)#5934
Aryakoste wants to merge 1 commit into
DSpace:mainfrom
Aryakoste:esLint-rule

Conversation

@Aryakoste

Copy link
Copy Markdown
Contributor

References

We commonly call a component method directly as the input of the async pipe in templates, e.g. {{ getFoo$() | async }}. Because the method runs as part of template evaluation, Angular re-executes the whole RxJS pipeline (subscribe + unsubscribe) on every change-detection cycle instead of once — a real, recurring perf issue in this codebase (confirmed instances in audit-table, ePerson-data, and section-coar-notify components).

This PR adds a new dspace-angular-html ESLint rule, no-method-call-with-async-pipe, that flags this pattern anywhere it appears in a template — interpolations, bound attributes/events, @if/@for/@switch blocks, @defer triggers, @let, and object/array literals or optional-chaining wrapped around the pipe.

  • New rule: lint/src/rules/html/no-method-call-with-async-pipe.ts
  • Registered in lint/src/rules/html/index.ts and enabled in .eslintrc.json
  • Docs auto-generated via npm run docs:lint (docs/lint/html/index.md, docs/lint/html/rules/no-method-call-with-async-pipe.md)

Implementation note

The straightforward approach — an ESLint selector like BindingPipe[name="async"] > Call — turned out to miss common real-world cases, because @angular-eslint/template-parser's own visitor-keys map doesn't cover every expression AST node type (e.g. SafePropertyRead, LiteralMap), so ESLint's traversal silently stops before reaching calls wrapped in things like (getFoo$() | async)?.length or [ngClass]="{x: getFoo$() | async}". To get full, correct coverage, the rule instead walks each template expression with @angular/compiler's own RecursiveAstVisitor, which handles every AST node type regardless of that gap.

This rule does not attempt to fix existing offending call sites — per the issue, migrating those (subscribe in ngOnInit(), push into a BehaviorSubject, | async on that, unsubscribe in ngOnDestroy()) is a separate follow-up. The rule is not auto-fixable, since that migration can't be done mechanically.

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You do not need to complete this checklist prior creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • My PR aligns with Accessibility guidelines if it makes changes to the user interface.
  • My PR uses i18n (internationalization) keys instead of hardcoded English text, to allow for translations.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

@ybnd ybnd self-requested a review July 7, 2026 07:27
@lgeggleston lgeggleston added improvement performance / caching Related to performance, caching or embedded objects code task testing framework Related specifically to Unit or Integration (e2e) Tests labels Jul 7, 2026
@lgeggleston lgeggleston moved this to 🙋 Needs Reviewers Assigned in DSpace 11.0 Release Jul 7, 2026
@lgeggleston lgeggleston moved this from 🙋 Needs Reviewers Assigned to 👀 Under Review in DSpace 11.0 Release Jul 7, 2026
@lgeggleston

Copy link
Copy Markdown

Thank you for the PR @Aryakoste! You may have already seen this, but looks like this is failing a few build tests that will need to be addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code task improvement performance / caching Related to performance, caching or embedded objects testing framework Related specifically to Unit or Integration (e2e) Tests

Projects

Status: 👀 Under Review

Development

Successfully merging this pull request may close these issues.

Introduce ESLint rule to prevent Observable-return methods from being used in Angular templates

2 participants