oxc-project/oxc · warning · OxcDiagnostic
Expected expression to be used
Error message
Expected expression to be used
What it means
Diagnostic from oxlint's no-unused-expressions rule. An expression statement that only computes and discards a value has no effect and usually hides a missing call, assignment, or cast. Options: allowShortCircuit (a && b()), allowTernary (a ? b() : c()), allowTaggedTemplates, enforceForJSX, and ignoreDirectives for directive prologues.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_unused_expressions.rs:19
use oxc_ast::{
AstKind,
ast::{ChainElement, Expression, UnaryOperator},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::Deserialize;
use serde_json::Value;
use crate::{
AstNode,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn no_unused_expressions_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected expression to be used")
.with_help("Consider using this expression or removing it")
.with_label(span)
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct NoUnusedExpressions(Box<NoUnusedExpressionsConfig>);
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoUnusedExpressionsConfig {
/// When set to `true`, allows short circuit evaluations in expressions.
allow_short_circuit: bool,
/// When set to `true`, allows ternary operators in expressions.
allow_ternary: bool,
/// When set to `true`, allows tagged template literals in expressions.
allow_tagged_templates: bool,
/// When set to `true`, enforces the rule for unused JSX expressions also.
#[serde(rename = "enforceForJSX")]View on GitHub (pinned to e1e7af627c)
Solutions
- Delete the statement or give it an effect (call it, assign it, export it).
- Enable "allowShortCircuit": true for a && b() style and "allowTernary": true for side-effectful ternaries in .oxlintrc.json.
- Convert the ternary to if/else when you do not want to relax the rule.
- Wrap intended template tags with "allowTaggedTemplates": true (e.g. gql`...`).
Example fix
// before
isReady && bootstrap();
// after
if (isReady) bootstrap();
// or .oxlintrc.json: "no-unused-expressions": ["error", { "allowShortCircuit": true }] Defensive patterns
Strategy: validation
Prevention
- Write side effects as statements: if/else instead of bare ternaries or short-circuit chains.
- If your team relies on a && b() guards, set "allowShortCircuit": true once in .oxlintrc.json instead of sprinkling disables.
- Delete probe expressions from debugging sessions before committing.
When it happens
Trigger: Set<number>; as a bare statement; 1 as number; window!; a + b; isReady && bootstrap(); without allowShortCircuit; cond ? f() : g(); without allowTernary.
Common situations: Guard-style short-circuit calls in a codebase where the options are off; leftover probe expressions from debugging; non-null assertions and type casts used as statements.
Related errors
- Expected method{method_name_str} to have this.
- {prefix} {{ after '{keyword}'{condition_if_needed}.
- Enforce default clauses in switch statements to be last
- Expected a function {style}.
- Accessor pair {getter_key} and {setter_key} should be groupe
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/a402b386f5711c73.
Report an issue: GitHub.