oxc-project/oxc · warning · OxcDiagnostic
Unexpected mix of shorthand and non-shorthand properties.
Error message
Unexpected mix of shorthand and non-shorthand properties.
What it means
Diagnostic from the oxlint `object-shorthand` rule with the `consistent-as-needed` option. It fires when a single object literal mixes shorthand properties (`{ x }`) with longform properties (`{ y: 2 }`). Under consistent-as-needed, every property must be shorthand as long as no property forces longform; a mix is reported via `unexpected_mix` (object_shorthand.rs:49-52).
Source
Thrown at crates/oxc_linter/src/rules/eslint/object_shorthand.rs:50
fn expected_property_shorthand(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected property shorthand.").with_label(span)
}
fn expected_property_longform(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected longform property syntax.").with_label(span)
}
fn expected_method_shorthand(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected method shorthand.").with_label(span)
}
fn expected_method_longform(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected longform method syntax.").with_label(span)
}
fn unexpected_mix(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected mix of shorthand and non-shorthand properties.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct ObjectShorthand(Box<ObjectShorthandConfig>);
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(default)]
pub struct ObjectShorthandTupleConfig(ShorthandType, ObjectShorthandOptions);
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default, deny_unknown_fields)]
pub struct ObjectShorthandOptions {
avoid_quotes: bool,
ignore_constructors: bool,
avoid_explicit_return_arrows: bool,
#[serde(default, deserialize_with = "deserialize_regex_option")]View on GitHub (pinned to a3d33dda7c)
Solutions
- Make the object consistent: either expand all properties to longform (`{ x: x, y: 2 }`) or, when every key matches a variable, shorten all of them (`{ x, y }`).
- Rename the local variable so the key can stay shorthand and the mix disappears.
- Relax the option to `consistent` (only flags mixes, does not demand all-shorthand) or `always`.
- Suppress with an inline disable comment for objects that must mix (e.g. when a computed key forces longform).
Example fix
// before
const foo = { x, y: 2 };
// after (all longform)
const foo = { x: x, y: 2 }; Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json — use "consistent" instead of "consistent-as-needed" if mixes are okay
{ "rules": { "object-shorthand": ["warn", "consistent"] } } Prevention
- Adopt one convention for property shorthand and apply it in code review.
- Let `oxlint --fix` expand all properties to longform when an object must mix forms.
- Watch refactors that rename variables away from their keys — that is when mixes sneak in.
When it happens
Trigger: Configure `"object-shorthand": ["error", "consistent-as-needed"]` and write an object like `const foo = { x, y: 2 };` where `x` is shorthand and `y` is longform. ESLint's original rule reports the shorthand property `x` because `y` already forces longform.
Common situations: React props objects built from mixed variables and computed values; config objects where some keys differ from the variable name; enabling consistent-as-needed on a legacy codebase that never normalized this; refactors that rename a variable so it no longer matches its key.
Related errors
- Expected {setter_key} to be before {getter_key}.
- Expected shorthand for all properties.
- Expected longform property syntax.
- Expected longform method syntax.
- Enforce `test` and `it` usage conventions
AI-assisted analysis of oxc-project/oxc@a3d33dda7c (2026-08-20).
Data as JSON: /api/errors/672d326b45c6e040.
Report an issue: GitHub.