{"record":{"id":"94b58defdbcf064e","repo":"oxc-project/oxc","slug":"expected-longform-method-syntax-for-string-literal","errorCode":null,"errorMessage":"Expected longform method syntax for string literal keys.","messagePattern":"Expected longform method syntax for string literal keys\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/object_shorthand.rs","lineNumber":30,"sourceCode":"use 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\nfn expected_method_longform(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected longform method syntax.\").with_label(span)\n}\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/oxc-project/oxc/blob/a3d33dda7cb69da23db4fcaa2c0c05de61e760a1/crates/oxc_linter/src/rules/eslint/object_shorthand.rs#L12-L48","documentation":"Diagnostic from `object-shorthand` when the `avoidQuotes` option is enabled and a shorthand method uses a quoted string-literal key (e.g. `{ \"foo\"() {} }`). The option exists because quoted keys in shorthand position hurt readability and diff tooling, so the rule asks for longform method syntax (`\"foo\": function () {}`) instead. Fired from the apply-to-methods branch when the key is a string literal.","triggerScenarios":"Config `\"object-shorthand\": [\"error\", \"always\", { \"avoidQuotes\": true }]` and code like `const o = { \"some key\"() { return 1; } }` or `{ 'foo'() {} }`. Only method shorthands with quoted keys are reported; unquoted shorthand methods are fine.","commonSituations":"Teams adopting avoidQuotes to keep JSON-like property style; keys generated with spaces or reserved words where authors reached for quote-plus-shorthand syntax.","solutions":["Write the method in longform: `{ \"foo\": function () {} }`.","If the key is identifier-safe, drop the quotes and keep shorthand: `{ foo() {} }`.","Use a computed key only when the key is genuinely dynamic.","Let `oxlint --fix` convert the shorthand to longform automatically."],"exampleFix":"// before\nconst o = {\n  \"fetch data\"() { return 1; },\n};\n\n// after\nconst o = {\n  \"fetch data\": function () { return 1; },\n};","handlingStrategy":"validation","validationCode":"const hasQuotedShorthandMethod = /\\{\\s*['\"][^'\"]+['\"]\\s*\\(/.test(objectLiteralSource);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["With avoidQuotes on, write quoted-key methods in longform.","Drop quotes when the key is a valid identifier to keep method shorthand.","Mirror the ESLint option names (avoidQuotes) in your oxlint config."],"tags":["lint","eslint","oxlint","object-literal","shorthand","quoted-keys"],"backgroundTag":"object-shorthand-avoid-quotes","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"}