From 6551dfef5c0ccb030ea9a96e639ebd42c8d520c2 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 18 Dec 2024 02:37:12 +0000 Subject: [PATCH] refactor(semantic): pass `&str` instead of `Cow` (#7972) As suggested by clippy... --- crates/oxc_semantic/src/checker/typescript.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/oxc_semantic/src/checker/typescript.rs b/crates/oxc_semantic/src/checker/typescript.rs index 343d18c1ac7e1..ea4f2ed4502da 100644 --- a/crates/oxc_semantic/src/checker/typescript.rs +++ b/crates/oxc_semantic/src/checker/typescript.rs @@ -26,12 +26,11 @@ pub fn check_ts_type_parameter_declaration( } } /// '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?(17019) -#[allow(clippy::needless_pass_by_value)] fn jsdoc_type_in_annotation( modifier: char, is_start: bool, span: Span, - suggested_type: Cow, + suggested_type: &str, ) -> OxcDiagnostic { let (code, start_or_end) = if is_start { ("17020", "start") } else { ("17019", "end") }; @@ -58,13 +57,19 @@ pub fn check_ts_type_annotation(annotation: &TSTypeAnnotation<'_>, ctx: &Semanti span_with_illegal_modifier.shrink_right(1) }; + let suggestion = &ctx.source_text[valid_type_span]; let suggestion = if modifier == '?' { - Cow::Owned(format!("{} | null | undefined", &ctx.source_text[valid_type_span])) + Cow::Owned(format!("{suggestion} | null | undefined")) } else { - Cow::Borrowed(&ctx.source_text[valid_type_span]) + Cow::Borrowed(suggestion) }; - ctx.error(jsdoc_type_in_annotation(modifier, is_start, span_with_illegal_modifier, suggestion)); + ctx.error(jsdoc_type_in_annotation( + modifier, + is_start, + span_with_illegal_modifier, + &suggestion, + )); } /// Initializers are not allowed in ambient contexts. ts(1039)