{"record":{"id":"2102928f08bbb235","repo":"oxc-project/oxc","slug":"defineprops-is-referencing-locally-declared-vari","errorCode":null,"errorMessage":"`defineProps` is referencing locally declared variables.","messagePattern":"`defineProps` is referencing locally declared variables\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vue/valid_define_props.rs","lineNumber":35,"sourceCode":"}\n\nfn called_multiple_times(span: Span, second_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`defineProps` has been called multiple times.\")\n        .with_help(\"combine all `defineProps` calls into a single `defineProps` call.\")\n        .with_labels([\n            span.label(\"`defineProps` is called here\"),\n            second_span.label(\"`defineProps` is called here too\"),\n        ])\n}\n\nfn events_not_defined(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Props are not defined.\")\n        .with_help(\"Define at least one prop in `defineProps`.\")\n        .with_label(span)\n}\n\nfn referencing_locally(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`defineProps` is referencing locally declared variables.\")\n        .with_help(\"inline the variable or import it from another module.\")\n        .with_label(span)\n}\n\nfn define_in_both(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Props are defined in both `defineProps` and `export default {}`.\")\n        .with_help(\"Remove `export default`.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct ValidDefineProps;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforce valid usage of the `defineProps` compiler macro in Vue.\n    ///","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vue/valid_define_props.rs#L17-L53","documentation":"Diagnostic from the oxlint rule `vue/valid-define-props`. When `check_define_macro_call_expression` detects that the argument to `defineProps` references identifiers declared locally in the same `<script setup>` block (as opposed to imports or a sibling `<script>` binding), it returns `DefineMacroProblem::ReferencingLocally`. The Vue compiler cannot statically resolve local variables into the props definition, so the component's props may break silently or be typed incorrectly.","triggerScenarios":"`const def = { msg: String }; defineProps(def)` inside `<script setup>` — the argument expression contains an IdentifierReference bound in the same block rather than imported or declared in a sibling `<script>`. The pass tests show allowed shapes: `const def` in plain `<script>` then `defineProps(def)` in `<script setup>`, `import { propsDef } from './defs'; defineProps(propsDef)`, and type-level references like `Array as PropType<typeof strList>` (type positions are not checked).","commonSituations":"Reusing a shared prop-shape object defined in the same file; grouping prop definitions into a `const` for readability; converting Options API `props: def` directly into `defineProps(def)` without moving `def`.","solutions":["Inline the object: `defineProps({ msg: String })`.","Move the definition into a plain `<script>` block (sibling to `<script setup>`) or another module and import it, as the help text suggests.","Use `// oxlint-disable vue/valid-define-props` on the line only if you have verified the compiler accepts your specific case."],"exampleFix":"// before\n<script setup>\nconst def = { msg: String }\ndefineProps(def)\n</script>\n\n// after\n<script setup>\ndefineProps({ msg: String })\n</script>","handlingStrategy":"validation","validationCode":"const arg = setup.match(/\\bdefineProps\\s*\\(\\s*([a-zA-Z_$][\\w$]*)\\s*\\)\\s*;?/);\nif (arg && new RegExp(`(?:const|let|var)\\\\s+${arg[1]}`).test(setup)) {\n  throw new Error(`defineProps references local variable '${arg[1]}' — inline it or import it`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Inline prop definitions or move them to a plain <script> block / separate module.","Keep type-level references (PropType<typeof x>) — those are fine; only runtime value references are checked."],"tags":["vue","script-setup","compiler-macro","defineprops","lint"],"backgroundTag":"vue-script-setup-macro-misuse","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"}