{"record":{"id":"18251aba6ba9dc9b","repo":"oxc-project/oxc","slug":"expected-longform-method-syntax","errorCode":null,"errorMessage":"Expected longform method syntax.","messagePattern":"Expected longform method syntax\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/object_shorthand.rs","lineNumber":46,"sourceCode":"\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\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\")]\n#[serde(default, deny_unknown_fields)]\npub struct ObjectShorthandOptions {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/oxc-project/oxc/blob/a3d33dda7cb69da23db4fcaa2c0c05de61e760a1/crates/oxc_linter/src/rules/eslint/object_shorthand.rs#L28-L64","documentation":"This diagnostic comes from the oxlint `object-shorthand` rule (crates/oxc_linter/src/rules/eslint/object_shorthand.rs). It fires when the rule is configured to require longform method syntax (shorthand type `never`, which sets apply_never=true), but the source contains an ES6 shorthand method such as `{ foo() {} }`. It is a style warning: the linter wants the explicit `foo: function() {}` form instead.","triggerScenarios":"Enable `\"object-shorthand\": [\"error\", \"never\"]` (or \"never\" as the shorthand type in .oxlintrc.json) and lint any object literal that uses method shorthand, e.g. `const obj = { run() {} }`. The `expected_method_longform` diagnostic (object_shorthand.rs:45-47) is emitted for that span.","commonSituations":"Teams porting an ESLint config that used \"never\"; codebases that predate ES6 and forbid shorthand for grep-ability; accidentally writing `[\"error\", \"never\"]` when \"always\" was intended; mixing this option with avoidQuotes and being surprised which message appears.","solutions":["Rewrite the flagged method to longform: `foo() {}` becomes `foo: function() {}`.","If shorthand is actually wanted, change the rule config to `[\"error\", \"always\"]` or remove the \"never\" option.","Disable the rule for the file with an inline `// oxlint-disable-next-line object-shorthand` comment (or the eslint-disable equivalent).","Turn the rule off globally in .oxlintrc.json if your style guide does not care."],"exampleFix":"// before\nconst obj = { foo() { return 1; } };\n\n// after\nconst obj = { foo: function () { return 1; } };","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — decide the policy once, before lint runs\n{ \"rules\": { \"object-shorthand\": [\"warn\", \"always\"] } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one shorthand policy (always/never/consistent) in .oxlintrc.json and encode it in a shared config.","Run `oxlint --fix` in a pre-commit hook (e.g. lint-staged) so violations never reach CI.","Normalize existing object literals with a codemod (jscodeshift/ast-grep) when adopting the rule."],"tags":["oxlint","eslint","style","object-literal","es6"],"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-14T05:17:10.506Z"}