Skip to content

Commit 90dfa2b

Browse files
huangtiandi1999camc314
authored andcommitted
check setup
1 parent 16798ae commit 90dfa2b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

crates/oxc_linter/src/context/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::{
1717
config::GlobalValue,
1818
disable_directives::DisableDirectives,
1919
fixer::{Fix, FixKind, Message, PossibleFixes, RuleFix, RuleFixer},
20+
frameworks::FrameworkOptions,
2021
};
2122

2223
mod host;
@@ -443,6 +444,12 @@ impl<'a> LintContext<'a> {
443444
self.parent.frameworks
444445
}
445446

447+
/// Returns the framework options for the current script block.
448+
/// For Vue files, this can be `FrameworkOptions::VueSetup` if we're in a `<script setup>` block.
449+
pub fn frameworks_options(&self) -> FrameworkOptions {
450+
self.parent.frameworks_options()
451+
}
452+
446453
pub fn other_file_hosts(&self) -> Vec<&ContextSubHost<'a>> {
447454
self.parent.other_file_hosts()
448455
}

crates/oxc_linter/src/rules/vue/no_required_prop_with_default.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use oxc_macros::declare_oxc_lint;
1111
use oxc_span::{GetSpan, Span};
1212
use rustc_hash::FxHashSet;
1313

14-
use crate::{AstNode, context::LintContext, rule::Rule};
14+
use crate::{AstNode, context::LintContext, frameworks::FrameworkOptions, rule::Rule};
1515

1616
fn no_required_prop_with_default_diagnostic(span: Span, prop_name: &str) -> OxcDiagnostic {
1717
let msg = format!("Prop \"{prop_name}\" should be optional.");
@@ -78,8 +78,9 @@ impl Rule for NoRequiredPropWithDefault {
7878
let Expression::Identifier(ident) = &call_expr.callee else {
7979
return;
8080
};
81+
let is_vue_setup = ctx.frameworks_options() == FrameworkOptions::VueSetup;
8182
match ident.name.as_str() {
82-
"defineProps" => {
83+
"defineProps" if is_vue_setup => {
8384
if let Some(arge) = call_expr.arguments.first() {
8485
let Some(Expression::ObjectExpression(obj)) = arge.as_expression()
8586
else {
@@ -114,7 +115,7 @@ impl Rule for NoRequiredPropWithDefault {
114115
};
115116
handle_object_expression(ctx, obj);
116117
}
117-
"withDefaults" if call_expr.arguments.len() == 2 => {
118+
"withDefaults" if call_expr.arguments.len() == 2 && is_vue_setup => {
118119
let [first_arg, second_arg] = call_expr.arguments.as_slice() else {
119120
return;
120121
};

0 commit comments

Comments
 (0)