Add ESLint rule to prevent Observable-returning method calls in the async pipe (#5933)#5934
Open
Aryakoste wants to merge 1 commit into
Open
Add ESLint rule to prevent Observable-returning method calls in the async pipe (#5933)#5934Aryakoste wants to merge 1 commit into
Aryakoste wants to merge 1 commit into
Conversation
|
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. |
ybnd
reviewed
Jul 8, 2026
| * RecursiveAstVisitor, which correctly covers the full expression AST regardless of what | ||
| * @angular-eslint/template-parser exposes to ESLint's selector engine. | ||
| */ | ||
| class AsyncPipedCallVisitor extends RecursiveAstVisitor { |
Member
There was a problem hiding this comment.
Good catch on those selectors, I wasn't aware of that!
ybnd
suggested changes
Jul 8, 2026
Member
There was a problem hiding this comment.
↑ those CI failures are due to the new lint rule
This rule does not attempt to fix existing offending call sites — per the issue, migrating those (...) is a separate follow-up.
The rule is not auto-fixable, since that migration can't be done mechanically.
It won't be possible to auto-fix, but we'll still need to sort out that "follow up step" within this PR as we did in previous PRs that introduced new configuration or rules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
References
We commonly call a component method directly as the input of the
asyncpipe 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 inaudit-table,ePerson-data, andsection-coar-notifycomponents).This PR adds a new
dspace-angular-htmlESLint rule,no-method-call-with-async-pipe, that flags this pattern anywhere it appears in a template — interpolations, bound attributes/events,@if/@for/@switchblocks,@defertriggers,@let, and object/array literals or optional-chaining wrapped around the pipe.lint/src/rules/html/no-method-call-with-async-pipe.tslint/src/rules/html/index.tsand enabled in.eslintrc.jsonnpm 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)?.lengthor[ngClass]="{x: getFoo$() | async}". To get full, correct coverage, the rule instead walks each template expression with@angular/compiler's ownRecursiveAstVisitor, 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 aBehaviorSubject,| asyncon that, unsubscribe inngOnDestroy()) 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!
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.