oxc-project/oxc · warning · OxcDiagnostic
Expected longform method syntax.
Error message
Expected longform method syntax.
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/eslint/object_shorthand.rs:46
fn expected_literal_method_longform(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected longform method syntax for string literal keys.").with_label(span)
}
fn expected_property_shorthand(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected property shorthand.").with_label(span)
}
fn expected_property_longform(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected longform property syntax.").with_label(span)
}
fn expected_method_shorthand(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected method shorthand.").with_label(span)
}
fn expected_method_longform(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected longform method syntax.").with_label(span)
}
fn unexpected_mix(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected mix of shorthand and non-shorthand properties.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct ObjectShorthand(Box<ObjectShorthandConfig>);
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(default)]
pub struct ObjectShorthandTupleConfig(ShorthandType, ObjectShorthandOptions);
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default, deny_unknown_fields)]
pub struct ObjectShorthandOptions {View on GitHub (pinned to a3d33dda7c)
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.
Example fix
// before
const obj = { foo() { return 1; } };
// after
const obj = { foo: function () { return 1; } }; Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json — decide the policy once, before lint runs
{ "rules": { "object-shorthand": ["warn", "always"] } } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expected {setter_key} to be before {getter_key}.
- Unexpected function expression.
- Use Object destructuring.
- Use Array destructuring.
- Expected shorthand for all properties.
AI-assisted analysis of oxc-project/oxc@a3d33dda7c (2026-08-20).
Data as JSON: /api/errors/18251aba6ba9dc9b.
Report an issue: GitHub.