{"record":{"id":"a11266a152d228da","repo":"oxc-project/oxc","slug":"expected-property-shorthand","errorCode":null,"errorMessage":"Expected property shorthand.","messagePattern":"Expected property shorthand\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/object_shorthand.rs","lineNumber":34,"sourceCode":"use serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{Rule, TupleRuleConfig},\n    utils::deserialize_regex_option,\n};\n\nfn expected_all_properties_shorthanded(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected shorthand for all properties.\").with_label(span)\n}\n\nfn expected_literal_method_longform(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected longform method syntax for string literal keys.\").with_label(span)\n}\n\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}","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/oxc-project/oxc/blob/a3d33dda7cb69da23db4fcaa2c0c05de61e760a1/crates/oxc_linter/src/rules/eslint/object_shorthand.rs#L16-L52","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Collapse the pair: `{ name: name }` -> `{ name }`.","Run `oxlint --fix` to convert every occurrence in one pass.","If a key must differ from the value name, that is fine - the rule only flags identical pairs.","Use config options (`ignoreConstructors`, `methodsIgnorePattern`) for the rare intentional exceptions."],"exampleFix":"// before\nfunction makeUser(name, role) {\n  return { name: name, role: role };\n}\n\n// after\nfunction makeUser(name, role) {\n  return { name, role };\n}","handlingStrategy":"validation","validationCode":"function findIdenticalPairs(objNode) {\n  return objNode.properties.filter(p => p.type === 'Property' && !p.computed &&\n    p.key.type === 'Identifier' && p.value.type === 'Identifier' && p.key.name === p.value.name);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write `{ key }` whenever the value variable has the same name.","Let the autofix migrate legacy `{ x: x }` code in bulk.","Use ignoreConstructors / methodsIgnorePattern for deliberate exceptions."],"tags":["lint","eslint","oxlint","object-literal","shorthand","es6"],"backgroundTag":"object-shorthand-style","analyzedSha":"a3d33dda7cb69da23db4fcaa2c0c05de61e760a1","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}