oxc-project/oxc · warning · OxcDiagnostic

Expected property shorthand.

Error message

Expected property shorthand.

What it means

Diagnostic from `object-shorthand` in its default `always` (apply-to-properties) mode. A property whose key string equals the identifier it references is written longform, `{ x: x }`, and ES6 shorthand `{ x }` is required. Oxc reports the ObjectProperty span where key and value are identical identifiers and apply_to_properties is on.

Source

Thrown at crates/oxc_linter/src/rules/eslint/object_shorthand.rs:34

use serde::Deserialize;

use crate::{
    AstNode,
    context::LintContext,
    rule::{Rule, TupleRuleConfig},
    utils::deserialize_regex_option,
};

fn expected_all_properties_shorthanded(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Expected shorthand for all properties.").with_label(span)
}

fn expected_literal_method_longform(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Expected longform method syntax for string literal keys.").with_label(span)
}

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)
}

View on GitHub (pinned to a3d33dda7c)

Solutions

  1. Collapse the pair: `{ name: name }` -> `{ name }`.
  2. Run `oxlint --fix` to convert every occurrence in one pass.
  3. If a key must differ from the value name, that is fine - the rule only flags identical pairs.
  4. Use config options (`ignoreConstructors`, `methodsIgnorePattern`) for the rare intentional exceptions.

Example fix

// before
function makeUser(name, role) {
  return { name: name, role: role };
}

// after
function makeUser(name, role) {
  return { name, role };
}
Defensive patterns

Strategy: validation

Validate before calling

function findIdenticalPairs(objNode) {
  return objNode.properties.filter(p => p.type === 'Property' && !p.computed &&
    p.key.type === 'Identifier' && p.value.type === 'Identifier' && p.key.name === p.value.name);
}

Prevention

When it happens

Trigger: `const o = { name: name, value: value };`, `return { user: user };`, or arrow-function object returns `() => ({ id: id })`. Fires on ObjectProperty nodes whose key and value are the same identifier; constructor methods may be exempted via `ignoreConstructors`, and matched method names via `methodsIgnorePattern` regex.

Common situations: Default-enabled rule in most shared configs, so newly linted legacy ES5 code floods with this; refactors that inline variables into object literals without collapsing the pair.

Related errors


AI-assisted analysis of oxc-project/oxc@a3d33dda7c (2026-08-20). Data as JSON: /api/errors/a11266a152d228da. Report an issue: GitHub.