{"record":{"id":"de41d7afa29fc5ad","repo":"oxc-project/oxc","slug":"use-object-destructuring","errorCode":null,"errorMessage":"Use Object destructuring.","messagePattern":"Use Object destructuring\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/prefer_destructuring.rs","lineNumber":21,"sourceCode":"    ast::{\n        AssignmentTarget, BindingPattern, Expression, MemberExpression, VariableDeclarationKind,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse 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 {","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/prefer_destructuring.rs#L3-L39","documentation":"Diagnostic from the oxlint `prefer-destructuring` rule for object targets. It fires when code reads a property into a variable via member access (`const foo = object.foo;`) and the rule's object option is enabled, suggesting `const { foo } = object;` instead (prefer_destructuring.rs:21-25). The rule config (PreferDestructuringTargetConfig in the same file) gates this with `{ \"object\": true }` or \"always\".","triggerScenarios":"Enable `\"prefer-destructuring\": [\"error\", { \"object\": true }]` (or \"always\") and write `const version = config.version;` or `this.name = user.name;` where a matching-key destructure is possible.","commonSituations":"Configs from teams standardizing on destructuring for imports/config objects; React props extraction (`const title = props.title;`); assignments from deeply nested options; cases where the variable name differs from the key — those need renaming or a default (`const { title: t } = props`) and are only fixable when names match.","solutions":["Use object destructuring: `const foo = object.foo;` becomes `const { foo } = object;` (auto-fixable when names match).","If names must differ, destructure with a rename: `const { foo: bar } = object;`.","Turn the option off (`{ \"object\": false }`) if direct member access is your style.","Inline-disable for cases where destructuring hurts clarity (chained access like `const v = obj.a.b.c;`)."],"exampleFix":"// before\nconst foo = object.foo;\n\n// after\nconst { foo } = object;","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — many teams enable object only\n{ \"rules\": { \"prefer-destructuring\": [\"warn\", { \"object\": true, \"array\": false }] } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Destructure at the point of member-access reads (`const { foo } = obj;`).","Use rename syntax when variable and key names differ.","Auto-fix matching-name cases with the linter rather than by hand."],"tags":["oxlint","eslint","style","destructuring","es6"],"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-14T05:17:10.506Z"}