{"record":{"id":"09bc38b326bb0866","repo":"oxc-project/oxc","slug":"expected-method-shorthand","errorCode":null,"errorMessage":"Expected method shorthand.","messagePattern":"Expected method shorthand\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/object_shorthand.rs","lineNumber":42,"sourceCode":"\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}\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","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/oxc-project/oxc/blob/a3d33dda7cb69da23db4fcaa2c0c05de61e760a1/crates/oxc_linter/src/rules/eslint/object_shorthand.rs#L24-L60","documentation":"Diagnostic from `object-shorthand` with apply-to-methods on (the default `always`/`methods` ShorthandType). A method is written longform as a function-valued property, `{ a: function () {} }`, and ES6 method shorthand `{ a() {} }` is expected. Oxc flags ObjectProperty nodes whose value is a plain Function/ArrowExpression under the methods branch.","triggerScenarios":"`const server = { start: function () {...}, stop: function () {...} };` or `{ handler: (e) => {} }` under method checks. Options `avoidExplicitReturnArrows` and `methodsIgnorePattern` (a regex exempting method names) refine what is reported; arrow-function properties may be treated separately from function expressions.","commonSituations":"ES5-era object module patterns (`var api = { init: function () {} }`) being linted with modern defaults; bundling legacy libraries into a linted monorepo.","solutions":["Convert to method shorthand: `{ start: function () {} }` -> `{ start() {} }`.","Set `methodsIgnorePattern` for names that must stay function properties (e.g. generators used as values).","Use `oxlint --fix` for a bulk rewrite.","If arrow semantics (`this` binding) matter, keep arrows but as `start: () => {}` only if configured to allow them, or refactor to methods."],"exampleFix":"// before\nconst api = {\n  start: function () { return 1; },\n};\n\n// after\nconst api = {\n  start() { return 1; },\n};","handlingStrategy":"validation","validationCode":"const hasLongformMethod = /:\\s*(function|\\([^)]*\\)\\s*=>)/.test(objectLiteralSource);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer `{ method() {} }` over `{ method: function () {} }` in modern code.","Set methodsIgnorePattern when some names must remain plain function properties.","Run the autofix when onboarding legacy ES5 object modules."],"tags":["lint","eslint","oxlint","object-literal","method-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"}