Skip to content

linter: Oxlintrc incorrectly accepts JSON arrays due to serde_json behavior #18821

@camc314

Description

@camc314

Oxlintrc can be deserialized from a JSON array (e.g., []), which should be rejected. Configuration files must be JSON objects.

// This unexpectedly succeeds - should fail
let config: Oxlintrc = serde_json::from_value(json!([])).unwrap();

Root Cause

This is due to a known serde_json behavior where arrays can deserialize into structs by treating array elements as positional struct fields. Combined with #[serde(default)] at the struct level, an empty array deserializes successfully with all default values.

See: serde-rs/json#1059

The serde_json maintainer has marked this as "wishlist for 2.0" but it hasn't been fixed yet.

Affected Code

crates/oxc_linter/src/config/oxlintrc.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linterArea - LinterC-bugCategory - Bug

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions