Skip to content

no-negated-async

Reports !(x | async) and (x | async) === false in an Angular template. Only in .component.html files.

The async pipe returns null before the stream emits its first value, so the negated test is true while the data is still loading, and the template shows the empty or error state for a moment.

To fix, compare with the value the stream emits, or use @if and @else on the pipe’s result.

Reported
...
<p *ngIf="!(a$ | async)"></p>
<p [hidden]="(a$ | async) === false || x"></p>
<p *ngIf="!a$ | async"></p>
...
angular:
lint:
rules:
no-negated-async: warn # off, warn (default), error
html:
lint:
rules:
no-negated-async: warn # off, warn (default), error
svelte:
lint:
rules:
no-negated-async: warn # off, warn (default), error
vue:
lint:
rules:
no-negated-async: warn # off, warn (default), error

Enabled by the presets: html/angular-eslint-recommended.

Suppress one line with sudsy-disable-next-line no-negated-async in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
angular-eslint no-negated-async partial !(x | async) and (x | async) === false