{"record":{"id":"593089e727fc82d8","repo":"oxc-project/oxc","slug":"expected-shorthand-for-all-properties","errorCode":null,"errorMessage":"Expected shorthand for all properties.","messagePattern":"Expected shorthand for all properties\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/object_shorthand.rs","lineNumber":26,"sourceCode":"        ArrowFunctionExpression, Expression, Function, ObjectExpression, ObjectProperty,\n        ObjectPropertyKind, PropertyKind,\n    },\n};\nuse oxc_ast_visit::{Visit, walk};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse 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","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/oxc-project/oxc/blob/a3d33dda7cb69da23db4fcaa2c0c05de61e760a1/crates/oxc_linter/src/rules/eslint/object_shorthand.rs#L8-L44","documentation":"Diagnostic from the `object-shorthand` rule with the `consistent-as-needed` option. Every property in the object could be written shorthand, but at least one is longform, so the rule demands all of them be shorthand for consistency. Oxc's config machinery (ObjectShorthandTupleConfig with ShorthandType ConsistentAsNeeded) drives this branch; the diagnostic labels the offending property span.","triggerScenarios":"`const x = 1, y = 2; const o = { x: x, y };` where every key equals its value-identifier, or `const o = { foo: foo, bar() {} }` under consistent-as-needed. Fires when the whole object is 'shorthand-able' but mixed or all-longform.","commonSituations":"Enabling consistent-as-needed in shared configs after code was written longform; merging objects during refactors that leave `{ x: x }` pairs behind.","solutions":["Convert all value-identical properties to shorthand: `{ x: x, y: y }` -> `{ x, y }`.","Use method shorthand for function values: `{ a: function () {} }` -> `{ a() {} }`.","Run `oxlint --fix` to rewrite the object automatically.","If the longform is intentional (computed or differently-named keys), pick the plain `always` option instead of consistent-as-needed."],"exampleFix":"// before\nconst x = 1, y = 2;\nconst o = { x: x, y: y };\n\n// after\nconst o = { x, y };","handlingStrategy":"validation","validationCode":"const hasValueIdenticalPair = /\\{\\s*[\\w$]+\\s*:\\s*[\\w$]+\\s*[\\},]/.test(objectLiteralSource) &&\n  objectLiteralSource.match(/([\\w$]+)\\s*:\\s*([\\w$]+)/g)?.every(m => { const [k, v] = m.split(':').map(s => s.trim()); return k !== v; });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When every key equals its value identifier, write all properties shorthand.","Pick `consistent-as-needed` only if the team wants the all-or-nothing style.","Rely on `oxlint --fix` to normalize objects during review."],"tags":["lint","eslint","oxlint","object-literal","shorthand","style"],"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"}