oxc-project/oxc · warning · OxcDiagnostic
Do not access a member directly from an await expression.
Error message
Do not access a member directly from an await expression.
What it means
Diagnostic from the oxlint rule `unicorn/no-await-expression-member` (crates/oxc_linter/src/rules/unicorn/no_await_expression_member.rs). It fires when a property is accessed directly on an `await` expression, such as `(await getUser()).name`. The code runs correctly at runtime; the rule is stylistic: reading members off an inline await is easy to misread and hard to extend, so it asks you to bind the awaited result to a variable first.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/no_await_expression_member.rs:12
use oxc_ast::{
AstKind, MemberExpressionKind,
ast::{BindingPattern, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use crate::{AstNode, context::LintContext, rule::Rule};
fn no_await_expression_member_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Do not access a member directly from an await expression.")
.with_help("Assign the result of the await expression to a variable, then access the member from that variable.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoAwaitExpressionMember;
declare_oxc_lint!(
/// ### What it does
///
/// Disallows member access from `await` expressions.
///
/// ### Why is this bad?
///
/// When accessing a member from an `await` expression,
/// the `await` expression has to be parenthesized, which is not readable.
///
/// ### ExamplesView on GitHub (pinned to e1e7af627c)
Solutions
- Assign the awaited value first, then access the member: `const user = await getUser(); user.name`
- If the inline form is deliberate, suppress once with `// oxlint-disable-next-line unicorn/no-await-expression-member`
- If the team prefers inline awaits overall, turn the rule off in the rules section of .oxlintrc.json
Example fix
// before console.log((await getUser()).name); // after const user = await getUser(); console.log(user.name);
Defensive patterns
Strategy: validation
Prevention
- In async code, always bind `const x = await p` before touching x's members
- Run oxlint in the editor (VS Code extension) so this fires on save, not in CI
- Keep newly adopted style rules at warn level until the codebase is cleaned up
When it happens
Trigger: Any static or computed member access whose object is an AwaitExpression: `(await loadConfig()).retries`, `console.log((await getStats()).total)`, `(await readBlock())[0]`. The flagged shape is `(await x).y`, not the chained call `await x.y()`.
Common situations: One-off field reads in async functions; developers inlining awaits to save a line; teams enabling oxlint's unicorn preset (or raising lint severity from warn to error in CI) and hitting style failures on existing code.
Related errors
- Prefer `async`/`await` to the callback pattern
- Require or disallow "Yoda" conditions
- Unexpected `if` as the only statement in a `if` block withou
- Invalid group length in numeric value.
- `VirtualFree` failed during cleanup: {err}
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/f68b0c80f7d84f6a.
Report an issue: GitHub.