{"record":{"id":"8a7498eec0f676b1","repo":"oxc-project/oxc","slug":"defineoptions-has-been-called-multiple-times","errorCode":null,"errorMessage":"`defineOptions` has been called multiple times.","messagePattern":"`defineOptions` has been called multiple times\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vue/valid_define_options.rs","lineNumber":21,"sourceCode":"    ast::{CallExpression, Expression, IdentifierReference, ObjectPropertyKind},\n};\nuse oxc_ast_visit::{VisitJs, walk_js};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode, ast_util::variable_declaration_kind, context::LintContext,\n    frameworks::FrameworkOptions, rule::Rule,\n};\n\nfn referencing_locally_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`defineOptions` is referencing locally declared variables.\")\n        .with_label(span)\n}\n\nfn multiple_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`defineOptions` has been called multiple times.\").with_label(span)\n}\n\nfn not_defined_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Options are not defined.\").with_label(span)\n}\n\nfn disallow_prop_diagnostic(span: Span, prop_name: &str, instead_macro: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"`defineOptions()` cannot be used to declare `{prop_name}`. Use `{instead_macro}()` instead.\"\n    ))\n    .with_label(span)\n}\n\nfn type_args_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`defineOptions()` cannot accept type arguments.\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vue/valid_define_options.rs#L3-L39","documentation":"Diagnostic from the oxlint rule `vue/valid-define-options`. The rule collects the span of every `defineOptions(...)` call in the program; when more than one call is found (`visitor.call_spans.len() > 1`), it reports this diagnostic on EVERY call site (both the first and subsequent calls get a label). The Vue compiler allows at most one `defineOptions` per component; a second call is a compile error in `@vitejs/plugin-vue` / vue-loader.","triggerScenarios":"Two or more `defineOptions(...)` calls in the same .vue program (VueSetup framework option enabled). Typical trigger: `defineOptions({ name: 'A' }); defineOptions({ name: 'B' })` inside one `<script setup>`, often produced by merging two components or pasting a snippet that already contains a `defineOptions` call.","commonSituations":"Merging two SFCs where each had its own `defineOptions({ name })`; copy-pasting a component template that includes `defineOptions({ inheritAttrs: false })`; codemods that insert `defineOptions({ name })` into files that already have one.","solutions":["Delete all but one `defineOptions` call and merge the option properties into the surviving object literal.","If the duplicates differ, reconcile them (e.g. combine `name` and `inheritAttrs` into a single call) instead of keeping both.","Search the file for `defineOptions(` to confirm only one call remains after the merge."],"exampleFix":"// before\n<script setup>\ndefineOptions({ name: 'A' })\ndefineOptions({ name: 'B', inheritAttrs: false })\n</script>\n\n// after\n<script setup>\ndefineOptions({ name: 'B', inheritAttrs: false })\n</script>","handlingStrategy":"validation","validationCode":"const setup = extractScriptSetup(src);\nconst count = (setup.match(/\\bdefineOptions\\s*\\(/g) ?? []).length;\nif (count > 1) throw new Error(`Expected one defineOptions call, found ${count}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Codemods that insert defineOptions({ name }) should first grep the file for an existing call and merge into it.","When merging SFCs, search for `defineOptions(` in both files and reconcile.","Keep vue/valid-define-options enabled in CI."],"tags":["vue","script-setup","compiler-macro","defineoptions","lint","duplicate-call"],"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"}