{"record":{"id":"672d326b45c6e040","repo":"oxc-project/oxc","slug":"unexpected-mix-of-shorthand-and-non-shorthand-prop","errorCode":null,"errorMessage":"Unexpected mix of shorthand and non-shorthand properties.","messagePattern":"Unexpected mix of shorthand and non-shorthand properties\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/object_shorthand.rs","lineNumber":50,"sourceCode":"\nfn expected_property_shorthand(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected property shorthand.\").with_label(span)\n}\n\nfn expected_property_longform(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected longform property syntax.\").with_label(span)\n}\n\nfn expected_method_shorthand(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected method shorthand.\").with_label(span)\n}\n\nfn expected_method_longform(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected longform method syntax.\").with_label(span)\n}\n\nfn unexpected_mix(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected mix of shorthand and non-shorthand properties.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct ObjectShorthand(Box<ObjectShorthandConfig>);\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(default)]\npub struct ObjectShorthandTupleConfig(ShorthandType, ObjectShorthandOptions);\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\")]\n#[serde(default, deny_unknown_fields)]\npub struct ObjectShorthandOptions {\n    avoid_quotes: bool,\n    ignore_constructors: bool,\n    avoid_explicit_return_arrows: bool,\n    #[serde(default, deserialize_with = \"deserialize_regex_option\")]","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/oxc-project/oxc/blob/a3d33dda7cb69da23db4fcaa2c0c05de61e760a1/crates/oxc_linter/src/rules/eslint/object_shorthand.rs#L32-L68","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nconst foo = { x, y: 2 };\n\n// after (all longform)\nconst foo = { x: x, y: 2 };","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — use \"consistent\" instead of \"consistent-as-needed\" if mixes are okay\n{ \"rules\": { \"object-shorthand\": [\"warn\", \"consistent\"] } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["oxlint","eslint","style","object-literal","consistency"],"backgroundTag":"eslint-object-shorthand","analyzedSha":"a3d33dda7cb69da23db4fcaa2c0c05de61e760a1","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}