{"record":{"id":"7054973d9efe1498","repo":"oxc-project/oxc","slug":"use-array-destructuring","errorCode":null,"errorMessage":"Use Array destructuring.","messagePattern":"Use Array destructuring\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/prefer_destructuring.rs","lineNumber":27,"sourceCode":"use oxc_span::{GetSpan, Span};\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    ast_util::variable_declaration_kind,\n    context::LintContext,\n    rule::{Rule, TupleRuleConfig},\n};\n\nfn prefer_object_destructuring(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use Object destructuring.\")\n        .with_help(\"Use object destructuring rather than direct member access.\")\n        .with_label(span)\n}\n\nfn prefer_array_destructuring(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use Array destructuring.\")\n        .with_help(\"Use array destructuring rather than direct member access.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, JsonSchema, Deserialize, Serialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\nstruct PreferDestructuringTargetConfig {\n    array: bool,\n    object: bool,\n}\n\nimpl Default for PreferDestructuringTargetConfig {\n    fn default() -> Self {\n        Self { array: true, object: true }\n    }\n}\n\nimpl PreferDestructuringTargetConfig {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/prefer_destructuring.rs#L9-L45","documentation":"Diagnostic from the oxlint `prefer-destructuring` rule for array targets. It fires when code indexes into an array to pull values (`const foo = array[0];`) and the rule's array option is enabled, suggesting `const [foo] = array;` (prefer_destructuring.rs:27-31). Enabled via `{ \"array\": true }` or the \"always\" shorthand in .oxlintrc.json.","triggerScenarios":"Enable array destructuring reporting and write `const first = items[0];` or `this.x = point[0]; this.y = point[1];` (the swap-style case becomes `[this.x, this.y] = point;`).","commonSituations":"Tuple return values (e.g. `const m = match(...); const name = m[1];` for regex captures); coordinate/pair handling; teams that enable array destructuring for looks but dislike it for single-index reads (commonly disabled with `{ \"array\": false, \"object\": true }`).","solutions":["Destructure the index: `const foo = array[0];` becomes `const [foo] = array;`; multi-index reads become `const [x, y] = point;`.","Disable the array half of the rule: `[\"error\", { \"array\": false, \"object\": true }]`.","Use rest/spread when taking head and tail: `const [head, ...rest] = items;`.","Inline-disable for readability exceptions like `arr[arr.length - 1]`."],"exampleFix":"// before\nconst foo = array[0];\n\n// after\nconst [foo] = array;","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — opt out of array half if single-index reads annoy the team\n{ \"rules\": { \"prefer-destructuring\": [\"warn\", { \"object\": true, \"array\": false }] } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Destructure tuple returns immediately: `const [x, y] = point;`.","Disable the array option if positional reads like `items[0]` are your norm.","Use rest patterns for head/tail splits instead of chained indexes."],"tags":["oxlint","eslint","style","destructuring","es6","arrays"],"backgroundTag":"eslint-prefer-destructuring","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}