{"record":{"id":"2d0f1d1d2d32a259","repo":"oxc-project/oxc","slug":"prop-prop-name-should-be-optional","errorCode":null,"errorMessage":"Prop \"{prop_name}\" should be optional.","messagePattern":"Prop \"(.+?)\" should be optional\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/vue/no_required_prop_with_default.rs","lineNumber":27,"sourceCode":"    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::NodeId;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    fixer::{RuleFix, RuleFixer},\n    frameworks::FrameworkOptions,\n    rule::Rule,\n    utils::{find_property, for_each_define_props_type_signature},\n};\n\nfn no_required_prop_with_default_diagnostic(span: Span, prop_name: &str) -> OxcDiagnostic {\n    let msg = format!(\"Prop \\\"{prop_name}\\\" should be optional.\");\n    OxcDiagnostic::warn(msg)\n        .with_help(\"Remove the `required: true` option, or drop the `required` key entirely to make this prop optional.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoRequiredPropWithDefault;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforce props with default values to be optional.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// If a prop is declared with a default value, whether it is required or not,\n    /// we can always skip it in actual use. In that situation, the default value would be applied.\n    /// So, a required prop with a default value is essentially the same as an optional prop.\n    ///","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vue/no_required_prop_with_default.rs#L9-L45","documentation":"The vue/no-required-prop-with-default rule reports a prop declared with both `required: true` and a `default`. In Vue, a prop with a default is always resolved to a value, so it can never be missing; marking it required is contradictory. It also skews TypeScript/`defineProps` inference, which derives optionality from whether `default` exists. The rule has a fixer (RuleFix/RuleFixer are imported) and its help suggests removing the `required: true` option or dropping the `required` key entirely. It checks both Options-API prop objects (find_property) and `defineProps` type signatures via for_each_define_props_type_signature.","triggerScenarios":"Declaring `{ type: String, required: true, default: 'x' }` in a component's `props`, or a runtime prop object inside `defineProps({ ... })`, where both `required` and `default` keys are present.","commonSituations":"Adding a default later without removing `required`; teams enforcing 'all props explicit' by marking everything required; migrating from JS to TS prop definitions and keeping both modifiers.","solutions":["Remove `required: true` and keep the `default` (the rule's autofix does exactly this — apply the suggested fix).","If the prop genuinely must be provided by callers, remove the `default` instead and keep `required: true`.","Pick one strategy per prop, never both, and document the convention in your team's style guide.","Re-run oxlint to confirm the prop passes."],"exampleFix":"// before\nprops: {\n  variant: {\n    type: String,\n    required: true,   // contradicts the default\n    default: 'primary'\n  }\n}\n\n// after\nprops: {\n  variant: {\n    type: String,\n    default: 'primary'\n  }\n}","handlingStrategy":"validation","validationCode":"// pre-check a prop definition before shipping it\nfunction assertValidProp(prop) {\n  if (prop.required && 'default' in prop) {\n    throw new Error(`prop cannot be both required and have a default`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt one rule: a prop declares either `required: true` or `default`, never both.","Apply the rule's autofix during review instead of leaving contradictions in place.","Let TS optionality follow the presence of `default` in defineProps inference."],"tags":["vue","props","lint","options-api","script-setup"],"backgroundTag":"invalid-prop-definition","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"}