{"record":{"id":"76ce6b7ee5217796","repo":"oxc-project/oxc","slug":"avoid-destructuring-from-defineprops","errorCode":null,"errorMessage":"Avoid destructuring from `defineProps`.","messagePattern":"Avoid destructuring from `defineProps`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/vue/define_props_destructuring.rs","lineNumber":20,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    frameworks::FrameworkOptions,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn prefer_destructuring_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer destructuring from `defineProps` directly.\").with_label(span)\n}\n\nfn avoid_destructuring_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Avoid destructuring from `defineProps`.\").with_label(span)\n}\n\nfn avoid_with_defaults_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Avoid using `withDefaults` with destructuring.\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"kebab-case\")]\nenum Destructure {\n    /// Requires destructuring when `defineProps` is assigned to a variable and warns against using `withDefaults` with destructuring\n    #[default]\n    OnlyWhenAssigned,\n    /// Requires destructuring when using `defineProps` and warns against using `withDefaults` with destructuring\n    Always,\n    /// Requires using a variable to store props and prohibits destructuring\n    Never,\n}\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vue/define_props_destructuring.rs#L2-L38","documentation":"Diagnostic from oxlint's vue/define-props-destructuring rule (style category, since oxlint 1.20.0). It fires when defineProps() results are destructured while the rule is set to Destructure::Never, which requires storing props in a variable. This mode protects codebases where destructured values would lose reactivity (pre-Vue 3.5 compilers or runtime-only builds).","triggerScenarios":"Config sets \"vue/define-props-destructuring\": [\"error\", { \"destructure\": \"never\" }] and a file contains `const { foo } = defineProps(['foo'])` or destructuring of a withDefaults(defineProps(...)) call.","commonSituations":"Projects on Vue < 3.5 (or using defineProps without the compiler transform) where destructured props stop updating; teams standardize on `props.foo` access and enforce it with this option.","solutions":["Store the result and access members: const props = defineProps(['foo']); props.foo","Upgrade to Vue 3.5+ where reactive props destructuring is supported, then switch the option to \"always\" or the default","Disable the rule for files that must destructure (e.g., withDefaults-free simple props)"],"exampleFix":"// before (option { \"destructure\": \"never\" })\nconst { foo } = defineProps(['foo'])\n// after\nconst props = defineProps(['foo'])\nconsole.log(props.foo)","handlingStrategy":"validation","validationCode":"# find destructured defineProps before switching to { \"destructure\": \"never\" }\ngrep -rnE \"const *\\{[^}]*\\} *= *(withDefaults\\()?\\s*defineProps\" --include='*.vue' src","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use \"never\" mode on Vue versions below 3.5 to protect reactivity of destructured props","Check your Vue version in package.json before choosing the destructure option"],"tags":["vue","oxlint","lint","script-setup","defineprops","destructuring","reactivity"],"backgroundTag":"vue-defineprops-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"}