{"record":{"id":"25d3429125a7ca1f","repo":"oxc-project/oxc","slug":"avoid-using-withdefaults-with-destructuring","errorCode":null,"errorMessage":"Avoid using `withDefaults` with destructuring.","messagePattern":"Avoid using `withDefaults` with destructuring\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/vue/define_props_destructuring.rs","lineNumber":24,"sourceCode":"use 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\n#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct DefinePropsDestructuring {\n    /// Require or prohibit destructuring.","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vue/define_props_destructuring.rs#L6-L42","documentation":"Diagnostic from oxlint's vue/define-props-destructuring rule (style category, since oxlint 1.20.0). It fires when withDefaults() is combined with destructuring, e.g. `const { baz } = withDefaults(defineProps(...), { baz: 'x' })`. All three modes of the rule warn against this pattern; with Vue 3.5+ defaults belong directly in the destructuring pattern, and on older versions the combination is the least portable style.","triggerScenarios":"A file contains destructuring of a withDefaults(defineProps(...), {...}) call. The rule detects the parent withDefaults CallExpression span around a destructured defineProps and reports it under every destructure option.","commonSituations":"Copying typed-props boilerplate from Vue 3.0-3.4 era docs or blog posts into a codebase whose lint config uses this rule; CI then flags the legacy withDefaults idiom.","solutions":["Inline the default into the destructure: const { baz = 'default' } = defineProps<{ baz?: string }>() (Vue 3.5+)","Or keep withDefaults but assign it to a variable and access props via that variable (pre-3.5)","Remove withDefaults entirely when the default can be handled at usage sites"],"exampleFix":"// before\nconst { baz } = withDefaults(defineProps<{ baz?: string }>(), { baz: 'default' })\n// after\nconst { baz = 'default' } = defineProps<{ baz?: string }>()","handlingStrategy":"validation","validationCode":"# find withDefaults usages, then check which are destructured\ngrep -rn \"withDefaults\" --include='*.vue' src","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer destructure-time defaults (const { x = 'd' } = defineProps<...>()) over withDefaults on Vue 3.5+","Add a lint rule or review checklist banning new withDefaults wrappers"],"tags":["vue","oxlint","lint","script-setup","withdefaults","defineprops","destructuring"],"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"}